Commit Graph
6 Commits
Author SHA1 Message Date
Willie ede7f29aea fix(extras): read written blocks back and keep user lines in block-created 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
2026-10-07 00:43:13 +08:00
Willie 15dc6f47e3 fix(extras): guard block targets against source links, open fences and 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
2026-10-07 00:37:40 +08:00
Willie 876e165f25 fix(extras): refuse damaged blocks and plan block defaults without the 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
2026-10-07 00:30:34 +08:00
Willie c88b7ff341 fix(extras): drop the old representation when a target enters or leaves 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
2026-10-07 00:21:01 +08:00
Willie 899b52a78e fix(extras): keep block edits and placement straight across mode changes
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
2026-10-07 00:13:50 +08:00
Willie 05ff8c675a feat(extras): prepend and append modes for single-file extras
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
2026-10-07 00:04:00 +08:00