Repository navigation
feat(extras): prepend and append modes for single-file extras - #451
Conversation
Tools without an @import directive (codex, gemini, cursor) could only take a shared instruction file as a symlink or copy, which replaces the target's own file. Teams that want one shared AGENTS.md plus the user's own notes in the same file had no way to express that. prepend and append write the source into the target file as a managed block fenced by skillshare:extra markers that carry the source path and a content hash. Sync inserts the block once and then rewrites it in place, status reports modified when the block body no longer matches its hash, Collect copies the edited body back to the source, Reapply rewrites the block from the source, and restore removes only the block. Lines outside the block, and markers inside code fences, are never touched. Several managed blocks (and an import line) may share one target file; the connection validator only rejects a file when a replacing mode (symlink, copy, merge) is involved. Refs #436
…dashboard The AGENTS.md tab and the instructions API only knew import, symlink and copy, so a tool without @import could hold one shared file and had to give up its own instruction file to do it. The mode picker now lists prepend and append first among the modes that keep the tool's own file, with import; symlink and copy stay blocked once a target holds another shared file in a managed part. A target whose file already holds a block defaults the next shared file to prepend; the first connection keeps the link default the existing tests and the memory guidance rely on. The row hint says the target also uses the other files instead of claiming one replaces the other, and the modified-state note, Collect and Reapply name the block rather than the whole file, since only the block is read back or rewritten. The connect and restore previews describe what a block does to the target file. Refs #436
The prepend and append modes are a feature, so Release Please would propose 0.26.0 for this batch. The maintainer wants it to ship as 0.25.1, so ask for that version. Release-As: 0.25.1
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cd812f3c8f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case "prepend", "append": | ||
| return syncExtraBlock(f, dryRun) |
There was a problem hiding this comment.
Strip managed blocks before recording replacement restore points
When a target first uses prepend or append over an existing file and is later switched to symlink or copy, syncExtraFileReplace records the current target as the restore point but strips only managed import lines. Consequently the backup includes this extra's content block, and detaching the replacement mode restores that stale block, so the tool continues applying instructions the user removed. Remove the matching content block before recording the replacement restore point, as is already done for import mode.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 899b52a. recordExtraRestorePoint now takes the ExtraFile and strips this extra's content block from the restore point as well as its import line, so a prepend/append target switched to symlink or copy restores to the file without the block. Covered by TestSyncExtraFile_SwitchingBlockToLinkKeepsBlockOutOfRestorePoint.
| updated, changed := f.removeContentBlock(string(data)) | ||
| if !changed { | ||
| return false, nil |
There was a problem hiding this comment.
Back up edited blocks before detaching them
If a user edits a managed block by hand and then removes that target or extra, restoreExtraBlock deletes the block immediately without checking its stored hash or calling backupExtraDrift. Those edits are therefore irretrievably discarded, unlike edited copy/symlink targets and contrary to the restore flow's promise that outside edits are backed up first. Detect a hash mismatch and save the target to drift history before removing the block.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 899b52a. restoreExtraBlock now finds the block first and, when its body no longer matches the stored hash, saves the target to drift history (DriftReasonRestore) before removing the block. Covered by TestRestoreExtraTarget_EditedBlockIsKeptAsDrift.
| if open == nil && indent < 4 && !strings.HasPrefix(raw, "\t") { | ||
| if c, n := fenceRun(line); n >= 3 { |
There was a problem hiding this comment.
Track fenced regions inside managed blocks
When the shared source contains a fenced example with a line resembling either managed marker, the parser stops tracking fences as soon as open is non-nil. The marker inside the code fence is then treated as structural syntax, so the freshly written target immediately reports drift or becomes "damaged" and subsequent sync, collect, and restore operations fail. Fence delimiters need to be tracked while scanning the managed body as well as outside it.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 899b52a. parseContentBlocks tracks fence delimiters inside an open block too, so a marker quoted in a fenced example of the source stays text. Covered by TestSyncExtraFile_BlockWithFencedMarkerExampleStaysSynced (sync twice, status synced, the quoted end marker stays inside the one block).
| case found.body == body && contentBlockHash(found.body) == found.hash: | ||
| return result, nil |
There was a problem hiding this comment.
Move an existing block when changing prepend or append
When a user changes an already-synced target from prepend to append or vice versa, the body and hash still match, so this early return leaves the block in its old position even though the saved mode and UI report the new one. The existing block must be repositioned when its current placement does not match f.Mode, including when its body is otherwise unchanged.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 899b52a. applyExtraBlock checks blockInPlace (only blank lines before a prepend block / after an append block); a block in the other mode's place is removed and inserted afresh, after the hand-edit check as before. Covered by TestSyncExtraFile_ChangingPrependToAppendMovesTheBlock.
…d tab A target row showed only the path of the file the tool reads, so seeing what a prepend or append block actually did to that file meant leaving the tab for the target page. The path now opens a read-only dialog with the same preview and source views, and a link to the target page for editing. Riders keep a plain path: they have no file of their own. Refs #436
Four gaps in the managed-block modes, found by Codex review of #451: - Switching a block target to symlink or copy recorded the restore point from the file as it stood, block included, so restoring the target later brought back instructions the user had removed. The restore point now strips this extra's block, as it already stripped its import line. - Detaching a target whose block had been edited by hand dropped the edit outright. The edited file is now kept as a drift backup first, as an edited copy or link is. - Fences were only tracked outside a block, so a source that quoted a marker in a fenced example produced a target that read as damaged on the next sync. Fences are tracked inside the block body too. - Changing a synced target between prepend and append left the block where the old mode had put it, since body and hash still matched. A block in the other mode's place is moved. Refs #436
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Allowing imports and content blocks to share a target exposes an order-dependent restore bug when the target did not exist originally. If an import and a prepend/append block coexist and the import is detached first, restoreExtraImport sees no remaining import lines and clears the path-level created attach record even though the content block remains; detaching that block later therefore writes an empty file instead of deleting the file that skillshare created. Managed restore bookkeeping must retain the attach record while either imports or content blocks remain.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| switch f.Mode { | ||
| case "import": | ||
| return syncExtraImport(f, dryRun) | ||
| case "prepend", "append": | ||
| return syncExtraBlock(f, dryRun) |
There was a problem hiding this comment.
Remove the old representation during mode switches
When an existing target is changed through the mode picker, setSharedTargetMode stores the new mode before calling SyncExtraFile, so this dispatch has no knowledge of the previous representation and the destination-mode handlers preserve it as user content. For example, copy → prepend retains the whole copied source and adds another copy in a block, import → prepend retains the @ line, and prepend → import retains the content block; the target then reads duplicate instructions, and detaching removes only the new representation, leaving stale instructions behind. Strip or reconstruct the previous managed/copy representation when changing modes.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in c88b7ff. Entering prepend/append now treats a leftover copy the way syncExtraImport does (rebuilt from the attach-time base, other extras' import lines kept, an edited copy saved as a mode-switch drift backup) and drops this extra's own @ line; entering import drops this extra's block, saving a hand-edited one as a drift backup first. prepend/append → symlink/copy was already covered by the restore-point fix in 899b52a. Covered by TestSyncExtraFile_SwitchingCopyToPrependRebuildsFromBase, TestSyncExtraFile_SwitchingImportToAppendDropsTheImportLine and TestSyncExtraFile_SwitchingPrependToImportDropsTheBlockAndKeepsAnEdit.
The source view of a target's file showed the block markers as plain comments, so which lines skillshare manages, and which block had been edited by hand, took reading the markers. Each managed block is now tinted, a block the target reports as modified in the warning tone, and the dialog says what the block is or offers Collect and Reapply for the edited one, as the row does. Refs #436
…es a block mode The mode picker stores the new mode before syncing, so the block and import handlers saw the previous mode's output as the user's content: copy → prepend kept the whole copied source beside the new block, import → prepend kept the @ line, and prepend → import kept the block. The tool then read the instructions twice, and detaching removed only the new representation. Entering a block mode now rebuilds a leftover copy from the attach-time base (backing up an edited copy as a mode-switch drift, as import does) and drops this extra's @ line; entering import mode drops this extra's block, keeping a hand-edited one as a drift backup. Refs #436
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c88b7ff341
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| exists := ourLink || err == nil | ||
| // This extra's content block is left over from prepend or append mode; the | ||
| // import line takes its place. A hand-edited block is kept as a drift backup. | ||
| if block, findErr := f.findContentBlock(strings.Split(string(data), "\n")); findErr == nil && block != nil { |
There was a problem hiding this comment.
Reject damaged blocks before switching to import
When a prepend/append block has structural damage, such as a deleted end marker, findContentBlock returns an error but this condition silently ignores it and proceeds to add the import line. The mode change is then saved as successful while the old block remains, so the target reads duplicate or stale instructions and later restore removes only the import. The fresh case not covered by the valid-block mode-switch fix is this parser-error path; return findErr instead of continuing.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 876e165. syncExtraImport now returns the findContentBlock error, so a damaged block stops the switch to import instead of being kept beside the new @ line. Covered by TestSyncExtraFile_DamagedBlockRefusesImportAndDetach.
| found, err := f.findContentBlock(strings.Split(string(data), "\n")) | ||
| if err != nil || found == nil { | ||
| return false, nil |
There was a problem hiding this comment.
Propagate damaged-block errors during detach
If a user damages a marker, for example by deleting the closing marker, this branch converts the parser error into (false, nil). Callers such as instructions.Assign therefore remove the target from configuration even though its managed content remains in the file, leaving stale instructions with no configured connection that can restore them. The fresh case beyond the fixed hash-mismatch handling is structural marker damage taking the err != nil branch; it must abort the detach rather than report success.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 876e165. restoreExtraBlock returns the parse error rather than (false, nil), so Assign keeps the connection configured until the block is repaired. Covered by TestSyncExtraFile_DamagedBlockRefusesImportAndDetach (detach errors, file untouched).
| } else if j == -1 { | ||
| mode := "symlink" | ||
| if t.Import { | ||
| mode = "import" | ||
| } | ||
| tc := config.ExtraTargetConfig{Path: filepath.Dir(t.File), As: filepath.Base(t.File), Mode: mode} | ||
| tc := config.ExtraTargetConfig{Path: filepath.Dir(t.File), As: filepath.Base(t.File), Mode: defaultAssignMode(t, next, r)} | ||
| next[i].Targets = append(next[i].Targets, tc) |
There was a problem hiding this comment.
Apply the modes validated by PlanAssign
When a non-import target's current prepend/append assignment appears after two newly requested extras in configuration order, PlanAssign permits the batch and plans both additions as managed blocks because it can still see the old holder. Assign then removes that holder before applying the request and recomputes each mode from the mutated slice, so both new assignments default to symlink; the second replaces the first and the server persists two replacement owners for one path, making later validation fail. Apply the planned target configurations, or compute defaults from the desired final set, instead of recomputing them after removals.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 876e165. PlanAssign now removes the files that are leaving before it checks whether a non-import target can take several and before it picks defaults, and Assign applies the target config the plan validated instead of recomputing it after its removals. Removing the only block holder while adding two files is now refused up front. Covered by TestAssign_RemovingTheBlockHolderRefusesTwoNewFiles.
| if err := os.WriteFile(f.Target, []byte(updated), info.Mode().Perm()); err != nil { | ||
| return false, fmt.Errorf("failed to write target: %w", err) | ||
| } | ||
| return true, nil |
There was a problem hiding this comment.
Clear attach state after removing the final managed block
If prepend/append created a previously absent target and the user later adds ordinary content outside the block, detaching the block takes this write path and leaves the attachCreated record behind. A later copy or symlink attachment consequently treats the target as part of the old attachment, and its eventual restore deletes the user's file instead of preserving the content added after the first detach. After writing the remainder, clear the attach record when no other managed block or import remains.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 876e165. After writing the remainder, restoreExtraBlock clears the attach record when no managed block or import line is left, so the file is the user's from then on. Covered by TestRestoreExtraTarget_LastBlockLeavingHandsTheFileToTheUser (a later symlink attach and restore puts the user's file back).
| if fenceLen > 0 || indent >= 4 || strings.HasPrefix(raw, "\t") { | ||
| continue |
There was a problem hiding this comment.
Recognize the generated end marker after an unclosed fence
When the shared source contains an opening Markdown fence without a closing fence, the generated managed end marker is skipped here because fenceLen remains nonzero. The first sync writes the target successfully, but every subsequent status/sync/restore sees the freshly generated block as damaged; detach can then leave the block behind. The parser needs to recognize its structural end marker independently of an unclosed fence in the source body.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 876e165. Inside an open block, the end marker now closes it when the fence it sits in never closes later in the file, so an unclosed fence in the source cannot swallow the structural marker. Covered by TestSyncExtraFile_SourceWithUnclosedFenceStaysSynced (sync twice, status synced, detach removes the block).
…e leaving files Five gaps found by the third Codex review of #451: - Switching a target with a damaged block (a deleted end marker) to import ignored the parse error and added the @ line, so the tool read the stale block as well. The switch now fails until the block is repaired. - Detaching such a target reported success without touching the file, so Assign dropped the connection and left the block with nothing configured to remove it. Detach now returns the error. - PlanAssign decided whether a non-import target could take several files, and Assign chose each new file's mode, from the extras before the files being detached were gone. Removing the only block holder while adding two files therefore passed the plan, then gave both new files a link, the second replacing the first. The plan now detaches first and Assign applies the modes the plan validated. - When the last block left a file it had created but the user had since added lines to, the created record stayed, so a later link attach and restore deleted the user's file. The attach record is cleared once no managed block or import line remains. - A source with a fence that never closes swallowed the block's own end marker on the next parse, so a freshly written target read as damaged. An open block's end marker now ends it when the fence never closes. Refs #436
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 876e165f25
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| file := filepath.Clean(filepath.Join(dir, as)) | ||
| if old, ok := owners[file]; ok && old.name != extra.Name && (old.mode != "import" || target.Mode != "import") { | ||
| if old, ok := owners[file]; ok && old.name != extra.Name && (!ManagedExtraMode(old.mode) || !ManagedExtraMode(target.Mode)) { |
There was a problem hiding this comment.
Apply source-alias validation to block modes
When a prepend or append target is a symlink resolving to another single-file extra's source, validation passes because the ExtraSourceAt guard below still runs only for import. applyExtraBlock then follows that symlink with os.WriteFile, injecting the managed block directly into the other extra's source and propagating the corruption to its targets. Apply the existing source-alias rejection to all managed modes that edit a target in place.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 15dc6f4. ValidateExtraConnections now applies the ExtraSourceAt check to every ManagedExtraMode (import, prepend, append), so a block target that links to another extra's source is a conflict before anything is written. Covered by TestValidateExtraConnections_BlockTargetLinkedToAnotherSourceConflicts.
| if stripped, changed := f.removeContentBlock(string(data)); changed { | ||
| data = []byte(stripped) |
There was a problem hiding this comment.
Reject damaged blocks before recording replacement state
When a block was added to an existing file, its marker is later damaged, and the mode changes to symlink or copy, removeContentBlock converts the parser error into changed=false, so this code records the damaged managed content as the user's restore point and allows the replacement. Detaching later resurrects that stale block. The fresh evidence beyond the earlier damaged import/detach paths is that replacement modes still reach this error-swallowing restore-point path; propagate the parse error before replacing the file.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 15dc6f4. recordExtraRestorePoint now runs findContentBlock and returns its error, so switching a target with a damaged block to symlink or copy is refused instead of saving the damaged block as the restore point. Covered by TestSyncExtraFile_DamagedBlockRefusesSwitchToLink.
| if fenceLen > 0 && open != nil && line == contentBlockEnd && !fenceCloses(lines[i+1:], fenceChar, fenceLen) { | ||
| fenceChar, fenceLen = 0, 0 | ||
| } | ||
| if fenceLen > 0 || indent >= 4 || strings.HasPrefix(raw, "\t") { | ||
| continue |
There was a problem hiding this comment.
Prevent append from duplicating blocks after an open fence
When the existing target content contains an unclosed Markdown fence and the mode is append, the generated begin marker is placed inside the parser's still-open fence. The first sync succeeds, but every subsequent sync ignores the existing block, takes the found == nil path, and appends another copy. Reject this target state before the initial write or make generated outer markers recognizable independently of fences opened before the block.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 15dc6f4. Appending to a file that ends inside an open fence is refused with an error asking to close it. The parser also now ends a block at an end marker inside a fence when the body so far matches the block's hash, so a source with an unclosed fence followed by the user's own fenced code stays synced. Covered by TestSyncExtraFile_AppendAfterOpenFenceIsRefused and TestSyncExtraFile_UnclosedFenceBodyBeforeUserCodeStaysSynced.
| if found != nil && (overwriteEdited || contentBlockHash(found.body) == found.hash) && !f.blockInPlace(found, lines) { | ||
| content, _ = f.removeContentBlock(content) | ||
| lines = strings.Split(content, "\n") | ||
| found = nil | ||
| } |
There was a problem hiding this comment.
Keep same-side managed blocks in place
When two shared files both use prepend (the default assigned to an additional shared file), only the first block has nothing but blank lines before it. Syncing the other therefore treats it as misplaced and moves it ahead of its sibling; syncing either file individually changes their precedence, and full sync repeatedly rewrites them. Placement should allow other managed blocks on the same side and use ordinary target content—not sibling blocks—to distinguish prepend from append.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 15dc6f4. blockInPlace ignores other managed blocks on the same side and only counts ordinary target content, so sibling prepend blocks keep their order across repeated syncs. Covered by TestSyncExtraFile_SiblingPrependBlocksKeepTheirOrder.
…d sibling reordering Four gaps found by the fourth Codex review of #451: - The check that refuses a target linked to another extra's source ran for import only, so a prepend or append target linked that way had its block written straight into that source. It now runs for every mode that edits the target in place. - Switching a target with a damaged block to symlink or copy recorded the damaged block as the user's restore point, so detaching later brought it back. Recording the restore point now fails on a damaged block. - Appending to a file that ends inside an open code fence put the begin marker inside that fence, so the next sync missed the block and appended another. Such an append is refused. Separately, a block body with an unclosed fence now ends at the end marker whose body matches the block's hash, even when the user's own code follows. - A second prepend block counted its sibling above it as misplacing it, so each sync moved one ahead of the other. Placement now ignores other managed blocks on the same side. Refs #436
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 15dc6f47e3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if !attached { | ||
| if err := recordExtraRestorePoint(f.Target, f.importLine()); err != nil { | ||
| if err := recordExtraRestorePoint(f); err != nil { |
There was a problem hiding this comment.
Preserve user content when replacing a created block file
When prepend/append originally created the target, attached is already true because of the attachCreated record. If the user subsequently adds ordinary content outside the managed block and switches directly to symlink or copy, this branch skips recordExtraRestorePoint; the complete file is only saved as drift and attachCreated remains. Detaching the replacement later therefore restores “no file” and removes the user's content from the target, unlike detaching the block directly. Before replacing this case, convert the attach record to a restore point containing the block-stripped remainder.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ede7f29. Before recording state for a replacement mode, syncExtraFileReplace checks a target with the created record: when removing this extra's block leaves non-blank lines, it records those lines as the restore point (replacing the created record) instead of keeping "no file". Covered by TestSyncExtraFile_CreatedBlockFileWithUserLinesSurvivesLinkRestore.
| func renderContentBlock(src, body, eol string) string { | ||
| lines := append([]string{contentBlockBegin(src, body)}, strings.Split(body, "\n")...) | ||
| lines = append(lines, contentBlockEnd) | ||
| return strings.Join(lines, eol) + eol |
There was a problem hiding this comment.
Reject or escape structural marker lines in block bodies
If the shared source contains an unfenced line exactly equal to <!-- /skillshare:extra -->, this renderer copies it verbatim into the managed body and then emits another structural end marker. The parser treats the source line as the end and the generated marker as unmatched, so a target produced successfully by the first sync is immediately damaged and later sync, collect, and detach operations fail. Escape or otherwise encode reserved marker lines, or reject the source before writing the target.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in ede7f29. applyExtraBlock now parses the updated file back before writing and refuses when this source's block does not read back with exactly the source body, so a marker-like line in the source (or any other parser ambiguity) is reported instead of producing a damaged target. Covered by TestSyncExtraFile_SourceWithMarkerLineIsRefused.
…eated files Two gaps found by the fifth Codex review of #451: - A source line that reads as a block marker, such as an unfenced end marker, was copied into the body, so the freshly written target parsed as damaged and every later sync, collect and detach failed. The block is now parsed back before writing, and a source whose block would not read back as itself is refused. - When a block had created the target and the user then added lines outside it, switching to symlink or copy kept the "created" record, so restoring the link later removed the file and the user's lines with it. Those lines are now recorded as the restore point. Refs #436
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ede7f29aea
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| case "prepend", "append": | ||
| return syncExtraBlock(f, dryRun) |
There was a problem hiding this comment.
Remove blocks from user symlinks before replacement
When a prepend or append target is a user-owned symlink, this new path writes the block through the link into its destination. A later switch to copy or symlink enters the utils.IsSymlinkOrJunction branch of syncExtraFileReplace, which strips only imports before unlinking, so the backing file retains the block; detaching the replacement restores the user's link and exposes those stale instructions again. Fresh evidence beyond the earlier mode-switch finding is that the current symlink branch still calls only removeImport, not removeContentBlock.
Useful? React with 👍 / 👎.
| if found == nil { | ||
| return false, nil |
There was a problem hiding this comment.
Clear attach state when the managed block is already gone
If a block created a previously absent target, the user manually removes that block and leaves their own content, and then detaches the extra, this early return leaves the attachCreated record behind. A later copy or symlink attachment therefore reuses the stale record, and its eventual restore deletes the user's file instead of preserving it; clear the attach record here when no sibling managed block or import remains.
Useful? React with 👍 / 👎.
| if body, err := f.blockBody(); err == nil && body == found.body { | ||
| return "synced" |
There was a problem hiding this comment.
Report misplaced managed blocks as drift
When ordinary content is inserted before a prepend block or after an append block—or the configured mode changes without an immediate sync—the body and hash still match, so this returns synced even though applyExtraBlock would reposition the block. The dashboard consequently omits the target from needsSync and offers no sync prompt; include blockInPlace(found, lines) in the status decision.
Useful? React with 👍 / 👎.
| export const connectExtras = (target: SharedInstructionsTarget, name: string) => | ||
| (target.import ? [...usesOf(target).filter((n) => n !== name), name] : [name]); | ||
| (target.import || holdsManaged(target) ? [...usesOf(target).filter((n) => n !== name), name] : [name]); |
There was a problem hiding this comment.
Use managed-aware assignment for row toggles
Although this helper now preserves existing assignments when a target already holds managed blocks, the individual row toggle still takes its older !tg.import && tg.assigned.length > 0 branch and submits only [name]. Thus clicking a new shared file on a non-import target with a prepend/append assignment detaches the existing block and replaces it with the new file, while Connect All correctly adds another block; route the row toggle through the same managed-aware logic.
Useful? React with 👍 / 👎.
The pages added with the block modes covered what they write, not what the review fixes made them do. The sharing guide still said sync overwrites a modified target, which is wrong for a block: sync stops until the edit is collected or the block is rewritten. The guide, the extras reference and the built-in skill now cover the block's Collect and Rewrite choices, block statuses, the target file dialog, what a mode change removes, how restore treats a block, and the cases a block target is refused. Common errors gains an Extras section for the four new messages. The --mode help of extras init, --add-target and the mode command listed only import among the single-file modes; it now lists prepend and append too. Refs #436
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3875c16e26
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if ManagedExtraMode(target.Mode) { | ||
| if name := ExtraSourceAt(extras, file, sourceDir); name != "" && name != extra.Name { | ||
| return &ExtraTargetConflict{Name: name, Target: file} |
There was a problem hiding this comment.
Reject block targets that alias their own source
For a prepend or append target that resolves to this extra's own source file, ExtraSourceAt returns extra.Name, so this exemption lets validation succeed. syncExtraBlock then reads and writes the same path, inserting the managed block directly into the canonical source; the next sync treats that already-wrapped source as the new body and can nest or damage its markers. Reject self-aliases for the in-place block modes as well as aliases to another extra.
Useful? React with 👍 / 👎.
| if endsInOpenFence(content) { | ||
| return nil, fmt.Errorf("%s ends inside an open code fence; close it before appending %s, or the block would read as code", f.Target, f.Source) |
There was a problem hiding this comment.
Ignore completed managed blocks when checking append fences
When the target already contains a valid managed block whose source ends with an unclosed fence, adding a second source in append mode is incorrectly refused here. parseContentBlocks deliberately recognizes the first block's generated end marker and resets its fence state, but endsInOpenFence scans that marker as ordinary text and therefore reports the entire target as still fenced. The fresh case beyond the previously fixed unmanaged open-fence target is an existing valid managed block, which the repository explicitly supports even with an unclosed fence body and alongside other managed blocks.
Useful? React with 👍 / 👎.
…nstruction-block # Conflicts: # ui/src/components/instructions/ProjectSharedFiles.tsx # ui/src/components/instructions/SharedInstructions.tsx
Type
proposals/only — see CONTRIBUTING.md)prepend/appendmodes for single-file extras (instructions: managed prepend/append block for targets without @import support #436)Linked Issue
Closes #436
What changes
Tools without an
@importdirective (codex, gemini, cursor, …) could only take a shared instruction file as a symlink or copy, which replaces the tool's own file.prependandappendwrite the source into the target file as a managed block instead:modifiedwhen the block body no longer matches its hash. Collect copies the edited body back to the source; Reapply rewrites the block from the source (the edited block is kept as a drift backup). Restore removes only the block.@importline) may share one target file. The connection validator only rejects a shared file when a replacing mode (symlink,copy,merge) is involved.extras init --mode prepend|append,extras <name> --mode …, wizard, completions, JSON schemas.prepend; the first connection keeps the link default. The row hint says the target also uses the other files, and the modified-state note, Collect and Reapply name the block rather than the whole file.extrascommand reference, target configuration, sharing-instructions how-to.The last commit carries
Release-As: 0.25.1so this ships as a patch rather than 0.26.0.Checks run (devcontainer)
make check: fmt, vet and all packages pass except the known worktree-only failures (internal/git,internal/hooks,TestResolveWebRef,TestRemoteRefs_*,TestGitHooksAPIContract), which need the main checkout's.gitlayout and pass there. The sourcefs raw-write ratchet gained allowances for the new block writes (target/extrasreasons).go test ./internal/sync ./internal/config ./internal/instructions ./internal/server ./internal/sourcefsand./tests/integration -run TestExtrasFilepass.tsc --noEmitclean,eslintclean on the touched folder, vitest 969/971. The two failures (MCPServerListPi exposure,MemoryNotesrefresh) fail identically on the main checkout and are unrelated.python3 scripts/ai-context.py checkok.modifiedwith Collect / Reapply; screenshot of the AGENTS.md tab reviewed.Not run: website build, E2E runbooks, translated website docs (English only updated).
Checklist
make check) — for code changes (see the worktree-only failures named above)