harnery 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +84 -2
- package/bin/agent-coord +42 -0
- package/bin/agent-hook +44 -0
- package/bin/harn +40 -0
- package/dist/cli.d.ts +9 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +18 -0
- package/dist/commander.d.ts +128 -0
- package/dist/commander.d.ts.map +1 -0
- package/dist/commander.js +126 -0
- package/dist/commands/agents.d.ts +18 -0
- package/dist/commands/agents.d.ts.map +1 -0
- package/dist/commands/agents.js +3946 -0
- package/dist/commands/backup.d.ts +22 -0
- package/dist/commands/backup.d.ts.map +1 -0
- package/dist/commands/backup.js +262 -0
- package/dist/commands/browse-ai.d.ts +4 -0
- package/dist/commands/browse-ai.d.ts.map +1 -0
- package/dist/commands/browse-ai.js +156 -0
- package/dist/commands/browse.d.ts +4 -0
- package/dist/commands/browse.d.ts.map +1 -0
- package/dist/commands/browse.js +590 -0
- package/dist/commands/callers.d.ts +4 -0
- package/dist/commands/callers.d.ts.map +1 -0
- package/dist/commands/callers.js +276 -0
- package/dist/commands/completion.d.ts +17 -0
- package/dist/commands/completion.d.ts.map +1 -0
- package/dist/commands/completion.js +158 -0
- package/dist/commands/config-get.d.ts +4 -0
- package/dist/commands/config-get.d.ts.map +1 -0
- package/dist/commands/config-get.js +131 -0
- package/dist/commands/context.d.ts +11 -0
- package/dist/commands/context.d.ts.map +1 -0
- package/dist/commands/context.js +185 -0
- package/dist/commands/cookies.d.ts +4 -0
- package/dist/commands/cookies.d.ts.map +1 -0
- package/dist/commands/cookies.js +140 -0
- package/dist/commands/docs.d.ts +4 -0
- package/dist/commands/docs.d.ts.map +1 -0
- package/dist/commands/docs.js +137 -0
- package/dist/commands/doctor.d.ts +25 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +200 -0
- package/dist/commands/edit-batch.d.ts +18 -0
- package/dist/commands/edit-batch.d.ts.map +1 -0
- package/dist/commands/edit-batch.js +172 -0
- package/dist/commands/eml.d.ts +4 -0
- package/dist/commands/eml.d.ts.map +1 -0
- package/dist/commands/eml.js +428 -0
- package/dist/commands/env.d.ts +4 -0
- package/dist/commands/env.d.ts.map +1 -0
- package/dist/commands/env.js +201 -0
- package/dist/commands/fetch.d.ts +4 -0
- package/dist/commands/fetch.d.ts.map +1 -0
- package/dist/commands/fetch.js +99 -0
- package/dist/commands/file-history.d.ts +4 -0
- package/dist/commands/file-history.d.ts.map +1 -0
- package/dist/commands/file-history.js +152 -0
- package/dist/commands/grep.d.ts +4 -0
- package/dist/commands/grep.d.ts.map +1 -0
- package/dist/commands/grep.js +317 -0
- package/dist/commands/init.d.ts +82 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +288 -0
- package/dist/commands/outline.d.ts +4 -0
- package/dist/commands/outline.d.ts.map +1 -0
- package/dist/commands/outline.js +494 -0
- package/dist/commands/presence.d.ts +12 -0
- package/dist/commands/presence.d.ts.map +1 -0
- package/dist/commands/presence.js +123 -0
- package/dist/commands/read.d.ts +7 -0
- package/dist/commands/read.d.ts.map +1 -0
- package/dist/commands/read.js +46 -0
- package/dist/commands/scratch.d.ts +4 -0
- package/dist/commands/scratch.d.ts.map +1 -0
- package/dist/commands/scratch.js +426 -0
- package/dist/commands/session.d.ts +4 -0
- package/dist/commands/session.d.ts.map +1 -0
- package/dist/commands/session.js +162 -0
- package/dist/commands/sync.d.ts +24 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +275 -0
- package/dist/commands/toc.d.ts +5 -0
- package/dist/commands/toc.d.ts.map +1 -0
- package/dist/commands/toc.js +153 -0
- package/dist/commands/tokens.d.ts +4 -0
- package/dist/commands/tokens.d.ts.map +1 -0
- package/dist/commands/tokens.js +48 -0
- package/dist/commands/tunnel.d.ts +4 -0
- package/dist/commands/tunnel.d.ts.map +1 -0
- package/dist/commands/tunnel.js +513 -0
- package/dist/commands/uninstall.d.ts +22 -0
- package/dist/commands/uninstall.d.ts.map +1 -0
- package/dist/commands/uninstall.js +126 -0
- package/dist/commands/web.d.ts +4 -0
- package/dist/commands/web.d.ts.map +1 -0
- package/dist/commands/web.js +165 -0
- package/dist/core/agents/canonical-emit.d.ts +27 -0
- package/dist/core/agents/canonical-emit.d.ts.map +1 -0
- package/dist/core/agents/canonical-emit.js +72 -0
- package/dist/core/agents/cli-emit.d.ts +27 -0
- package/dist/core/agents/cli-emit.d.ts.map +1 -0
- package/dist/core/agents/cli-emit.js +57 -0
- package/dist/core/agents/cli.d.ts +10 -0
- package/dist/core/agents/cli.d.ts.map +1 -0
- package/dist/core/agents/cli.js +757 -0
- package/dist/core/agents/codex-replay.d.ts +29 -0
- package/dist/core/agents/codex-replay.d.ts.map +1 -0
- package/dist/core/agents/codex-replay.js +138 -0
- package/dist/core/agents/coord-client.d.ts +98 -0
- package/dist/core/agents/coord-client.d.ts.map +1 -0
- package/dist/core/agents/coord-client.js +212 -0
- package/dist/core/agents/events/consume.d.ts +59 -0
- package/dist/core/agents/events/consume.d.ts.map +1 -0
- package/dist/core/agents/events/consume.js +147 -0
- package/dist/core/agents/events/emit.d.ts +42 -0
- package/dist/core/agents/events/emit.d.ts.map +1 -0
- package/dist/core/agents/events/emit.js +70 -0
- package/dist/core/agents/events/ulid.d.ts +11 -0
- package/dist/core/agents/events/ulid.d.ts.map +1 -0
- package/dist/core/agents/events/ulid.js +47 -0
- package/dist/core/agents/index.d.ts +14 -0
- package/dist/core/agents/index.d.ts.map +1 -0
- package/dist/core/agents/index.js +13 -0
- package/dist/core/agents/paths.d.ts +6 -0
- package/dist/core/agents/paths.d.ts.map +1 -0
- package/dist/core/agents/paths.js +17 -0
- package/dist/core/agents/render/prompt-context.d.ts +43 -0
- package/dist/core/agents/render/prompt-context.d.ts.map +1 -0
- package/dist/core/agents/render/prompt-context.js +335 -0
- package/dist/core/agents/render/session-context.d.ts +39 -0
- package/dist/core/agents/render/session-context.d.ts.map +1 -0
- package/dist/core/agents/render/session-context.js +283 -0
- package/dist/core/agents/rules/claim-conflict.d.ts +35 -0
- package/dist/core/agents/rules/claim-conflict.d.ts.map +1 -0
- package/dist/core/agents/rules/claim-conflict.js +244 -0
- package/dist/core/agents/rules/commit-conflict.d.ts +59 -0
- package/dist/core/agents/rules/commit-conflict.d.ts.map +1 -0
- package/dist/core/agents/rules/commit-conflict.js +244 -0
- package/dist/core/agents/rules/stop-hook.d.ts +44 -0
- package/dist/core/agents/rules/stop-hook.d.ts.map +1 -0
- package/dist/core/agents/rules/stop-hook.js +161 -0
- package/dist/core/agents/session-events.d.ts +41 -0
- package/dist/core/agents/session-events.d.ts.map +1 -0
- package/dist/core/agents/session-events.js +205 -0
- package/dist/core/agents/state/activity-log.d.ts +18 -0
- package/dist/core/agents/state/activity-log.d.ts.map +1 -0
- package/dist/core/agents/state/activity-log.js +34 -0
- package/dist/core/agents/state/council.d.ts +39 -0
- package/dist/core/agents/state/council.d.ts.map +1 -0
- package/dist/core/agents/state/council.js +216 -0
- package/dist/core/agents/state/heartbeat-projector.d.ts +59 -0
- package/dist/core/agents/state/heartbeat-projector.d.ts.map +1 -0
- package/dist/core/agents/state/heartbeat-projector.js +436 -0
- package/dist/core/agents/state/heartbeat-writer.d.ts +64 -0
- package/dist/core/agents/state/heartbeat-writer.d.ts.map +1 -0
- package/dist/core/agents/state/heartbeat-writer.js +271 -0
- package/dist/core/agents/state/names.d.ts +35 -0
- package/dist/core/agents/state/names.d.ts.map +1 -0
- package/dist/core/agents/state/names.js +376 -0
- package/dist/core/agents/state/pidmap.d.ts +11 -0
- package/dist/core/agents/state/pidmap.d.ts.map +1 -0
- package/dist/core/agents/state/pidmap.js +32 -0
- package/dist/core/agents/state/scratch.d.ts +27 -0
- package/dist/core/agents/state/scratch.d.ts.map +1 -0
- package/dist/core/agents/state/scratch.js +90 -0
- package/dist/core/agents/state/shell-mutation.d.ts +17 -0
- package/dist/core/agents/state/shell-mutation.d.ts.map +1 -0
- package/dist/core/agents/state/shell-mutation.js +41 -0
- package/dist/core/agents/state/stale-sweep.d.ts +16 -0
- package/dist/core/agents/state/stale-sweep.d.ts.map +1 -0
- package/dist/core/agents/state/stale-sweep.js +166 -0
- package/dist/core/config.d.ts +29 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +108 -0
- package/dist/core/hooks/cli.d.ts +21 -0
- package/dist/core/hooks/cli.d.ts.map +1 -0
- package/dist/core/hooks/cli.js +1123 -0
- package/dist/core/hooks/effects/image-capture.d.ts +43 -0
- package/dist/core/hooks/effects/image-capture.d.ts.map +1 -0
- package/dist/core/hooks/effects/image-capture.js +288 -0
- package/dist/core/hooks/effects/index.d.ts +64 -0
- package/dist/core/hooks/effects/index.d.ts.map +1 -0
- package/dist/core/hooks/effects/index.js +197 -0
- package/dist/core/hooks/events/emit.d.ts +31 -0
- package/dist/core/hooks/events/emit.d.ts.map +1 -0
- package/dist/core/hooks/events/emit.js +89 -0
- package/dist/core/hooks/events/schema.d.ts +235 -0
- package/dist/core/hooks/events/schema.d.ts.map +1 -0
- package/dist/core/hooks/events/schema.js +12 -0
- package/dist/core/hooks/events/ulid.d.ts +10 -0
- package/dist/core/hooks/events/ulid.d.ts.map +1 -0
- package/dist/core/hooks/events/ulid.js +47 -0
- package/dist/core/hooks/harness/detect.d.ts +9 -0
- package/dist/core/hooks/harness/detect.d.ts.map +1 -0
- package/dist/core/hooks/harness/detect.js +29 -0
- package/dist/core/hooks/harness/events.d.ts +45 -0
- package/dist/core/hooks/harness/events.d.ts.map +1 -0
- package/dist/core/hooks/harness/events.js +71 -0
- package/dist/core/hooks/harness/output.d.ts +46 -0
- package/dist/core/hooks/harness/output.d.ts.map +1 -0
- package/dist/core/hooks/harness/output.js +87 -0
- package/dist/core/hooks/harness/parse.d.ts +67 -0
- package/dist/core/hooks/harness/parse.d.ts.map +1 -0
- package/dist/core/hooks/harness/parse.js +132 -0
- package/dist/core/hooks/index.d.ts +8 -0
- package/dist/core/hooks/index.d.ts.map +1 -0
- package/dist/core/hooks/index.js +7 -0
- package/dist/core/hooks/resolve/anchor.d.ts +37 -0
- package/dist/core/hooks/resolve/anchor.d.ts.map +1 -0
- package/dist/core/hooks/resolve/anchor.js +48 -0
- package/dist/core/hooks/resolve/coord-root.d.ts +6 -0
- package/dist/core/hooks/resolve/coord-root.d.ts.map +1 -0
- package/dist/core/hooks/resolve/coord-root.js +27 -0
- package/dist/core/hooks/resolve/intent.d.ts +33 -0
- package/dist/core/hooks/resolve/intent.d.ts.map +1 -0
- package/dist/core/hooks/resolve/intent.js +79 -0
- package/dist/core/hooks/resolve/owner.d.ts +42 -0
- package/dist/core/hooks/resolve/owner.d.ts.map +1 -0
- package/dist/core/hooks/resolve/owner.js +140 -0
- package/dist/core/hooks/resolve/transcript.d.ts +26 -0
- package/dist/core/hooks/resolve/transcript.d.ts.map +1 -0
- package/dist/core/hooks/resolve/transcript.js +73 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/lib/agent-browser/client.d.ts +99 -0
- package/dist/lib/agent-browser/client.d.ts.map +1 -0
- package/dist/lib/agent-browser/client.js +177 -0
- package/dist/lib/agent-browser/index.d.ts +2 -0
- package/dist/lib/agent-browser/index.d.ts.map +1 -0
- package/dist/lib/agent-browser/index.js +1 -0
- package/dist/lib/browser/client.d.ts +193 -0
- package/dist/lib/browser/client.d.ts.map +1 -0
- package/dist/lib/browser/client.js +325 -0
- package/dist/lib/browser/dev-overlay.d.ts +23 -0
- package/dist/lib/browser/dev-overlay.d.ts.map +1 -0
- package/dist/lib/browser/dev-overlay.js +153 -0
- package/dist/lib/browser/index.d.ts +5 -0
- package/dist/lib/browser/index.d.ts.map +1 -0
- package/dist/lib/browser/index.js +2 -0
- package/dist/lib/browser/layout.d.ts +79 -0
- package/dist/lib/browser/layout.d.ts.map +1 -0
- package/dist/lib/browser/layout.js +220 -0
- package/dist/lib/browser/visibility.d.ts +86 -0
- package/dist/lib/browser/visibility.d.ts.map +1 -0
- package/dist/lib/browser/visibility.js +333 -0
- package/dist/lib/browser/visual-diff.d.ts +38 -0
- package/dist/lib/browser/visual-diff.d.ts.map +1 -0
- package/dist/lib/browser/visual-diff.js +107 -0
- package/dist/lib/completion/bash.d.ts +25 -0
- package/dist/lib/completion/bash.d.ts.map +1 -0
- package/dist/lib/completion/bash.js +284 -0
- package/dist/lib/completion/fish.d.ts +16 -0
- package/dist/lib/completion/fish.d.ts.map +1 -0
- package/dist/lib/completion/fish.js +118 -0
- package/dist/lib/completion/index.d.ts +5 -0
- package/dist/lib/completion/index.d.ts.map +1 -0
- package/dist/lib/completion/index.js +4 -0
- package/dist/lib/completion/walk.d.ts +68 -0
- package/dist/lib/completion/walk.d.ts.map +1 -0
- package/dist/lib/completion/walk.js +102 -0
- package/dist/lib/completion/zsh.d.ts +13 -0
- package/dist/lib/completion/zsh.d.ts.map +1 -0
- package/dist/lib/completion/zsh.js +249 -0
- package/dist/lib/context/index.d.ts +107 -0
- package/dist/lib/context/index.d.ts.map +1 -0
- package/dist/lib/context/index.js +275 -0
- package/dist/lib/cookies/client.d.ts +131 -0
- package/dist/lib/cookies/client.d.ts.map +1 -0
- package/dist/lib/cookies/client.js +239 -0
- package/dist/lib/cookies/index.d.ts +2 -0
- package/dist/lib/cookies/index.d.ts.map +1 -0
- package/dist/lib/cookies/index.js +1 -0
- package/dist/lib/council/index.d.ts +266 -0
- package/dist/lib/council/index.d.ts.map +1 -0
- package/dist/lib/council/index.js +674 -0
- package/dist/lib/docs-index.d.ts +28 -0
- package/dist/lib/docs-index.d.ts.map +1 -0
- package/dist/lib/docs-index.js +169 -0
- package/dist/lib/docs-lint.d.ts +26 -0
- package/dist/lib/docs-lint.d.ts.map +1 -0
- package/dist/lib/docs-lint.js +378 -0
- package/dist/lib/docs-sweep.d.ts +34 -0
- package/dist/lib/docs-sweep.d.ts.map +1 -0
- package/dist/lib/docs-sweep.js +304 -0
- package/dist/lib/docs.d.ts +27 -0
- package/dist/lib/docs.d.ts.map +1 -0
- package/dist/lib/docs.js +142 -0
- package/dist/lib/env.d.ts +11 -0
- package/dist/lib/env.d.ts.map +1 -0
- package/dist/lib/env.js +12 -0
- package/dist/lib/exec.d.ts +32 -0
- package/dist/lib/exec.d.ts.map +1 -0
- package/dist/lib/exec.js +54 -0
- package/dist/lib/format.d.ts +29 -0
- package/dist/lib/format.d.ts.map +1 -0
- package/dist/lib/format.js +139 -0
- package/dist/lib/http/client.d.ts +56 -0
- package/dist/lib/http/client.d.ts.map +1 -0
- package/dist/lib/http/client.js +160 -0
- package/dist/lib/http/index.d.ts +2 -0
- package/dist/lib/http/index.d.ts.map +1 -0
- package/dist/lib/http/index.js +1 -0
- package/dist/lib/identities/index.d.ts +77 -0
- package/dist/lib/identities/index.d.ts.map +1 -0
- package/dist/lib/identities/index.js +190 -0
- package/dist/lib/machine.d.ts +19 -0
- package/dist/lib/machine.d.ts.map +1 -0
- package/dist/lib/machine.js +61 -0
- package/dist/lib/presence.d.ts +48 -0
- package/dist/lib/presence.d.ts.map +1 -0
- package/dist/lib/presence.js +123 -0
- package/dist/lib/readability/client.d.ts +32 -0
- package/dist/lib/readability/client.d.ts.map +1 -0
- package/dist/lib/readability/client.js +119 -0
- package/dist/lib/readability/index.d.ts +2 -0
- package/dist/lib/readability/index.d.ts.map +1 -0
- package/dist/lib/readability/index.js +1 -0
- package/dist/lib/scratch/index.d.ts +74 -0
- package/dist/lib/scratch/index.d.ts.map +1 -0
- package/dist/lib/scratch/index.js +393 -0
- package/dist/lib/tunnel/gate.d.ts +12 -0
- package/dist/lib/tunnel/gate.d.ts.map +1 -0
- package/dist/lib/tunnel/gate.js +101 -0
- package/dist/lib/tunnel/state.d.ts +34 -0
- package/dist/lib/tunnel/state.d.ts.map +1 -0
- package/dist/lib/tunnel/state.js +132 -0
- package/package.json +160 -8
- package/schemas/.gitkeep +0 -0
- package/schemas/config.schema.json +109 -0
- package/src/cli.ts +22 -0
- package/src/commander.ts +242 -0
- package/src/commands/.gitkeep +0 -0
- package/src/commands/agents.ts +4567 -0
- package/src/commands/backup.ts +305 -0
- package/src/commands/browse-ai.ts +198 -0
- package/src/commands/browse.ts +849 -0
- package/src/commands/callers.ts +363 -0
- package/src/commands/completion.ts +193 -0
- package/src/commands/config-get.ts +161 -0
- package/src/commands/context.ts +209 -0
- package/src/commands/cookies.ts +198 -0
- package/src/commands/docs.ts +174 -0
- package/src/commands/doctor.ts +231 -0
- package/src/commands/edit-batch.ts +233 -0
- package/src/commands/eml.ts +519 -0
- package/src/commands/env.ts +254 -0
- package/src/commands/fetch.ts +136 -0
- package/src/commands/file-history.ts +202 -0
- package/src/commands/grep.ts +371 -0
- package/src/commands/init.ts +335 -0
- package/src/commands/outline.ts +564 -0
- package/src/commands/presence.ts +152 -0
- package/src/commands/read.ts +64 -0
- package/src/commands/scratch.ts +445 -0
- package/src/commands/session.ts +187 -0
- package/src/commands/sync.ts +306 -0
- package/src/commands/toc.ts +218 -0
- package/src/commands/tokens.ts +79 -0
- package/src/commands/tunnel.ts +633 -0
- package/src/commands/uninstall.ts +144 -0
- package/src/commands/web.ts +193 -0
- package/src/core/agents/canonical-emit.ts +77 -0
- package/src/core/agents/cli-emit.ts +64 -0
- package/src/core/agents/cli.ts +838 -0
- package/src/core/agents/codex-replay.ts +163 -0
- package/src/core/agents/coord-client.ts +249 -0
- package/src/core/agents/events/consume.ts +196 -0
- package/src/core/agents/events/emit.ts +108 -0
- package/src/core/agents/events/ulid.ts +51 -0
- package/src/core/agents/index.ts +14 -0
- package/src/core/agents/paths.ts +16 -0
- package/src/core/agents/render/prompt-context.ts +401 -0
- package/src/core/agents/render/session-context.ts +341 -0
- package/src/core/agents/rules/claim-conflict.ts +282 -0
- package/src/core/agents/rules/commit-conflict.ts +303 -0
- package/src/core/agents/rules/stop-hook.ts +229 -0
- package/src/core/agents/session-events.ts +228 -0
- package/src/core/agents/state/activity-log.ts +33 -0
- package/src/core/agents/state/council.ts +265 -0
- package/src/core/agents/state/heartbeat-projector.ts +488 -0
- package/src/core/agents/state/heartbeat-writer.ts +333 -0
- package/src/core/agents/state/names.ts +399 -0
- package/src/core/agents/state/pidmap.ts +38 -0
- package/src/core/agents/state/scratch.ts +121 -0
- package/src/core/agents/state/shell-mutation.ts +44 -0
- package/src/core/agents/state/stale-sweep.ts +190 -0
- package/src/core/config.ts +111 -0
- package/src/core/hooks/cli.ts +1247 -0
- package/src/core/hooks/effects/image-capture.ts +330 -0
- package/src/core/hooks/effects/index.ts +210 -0
- package/src/core/hooks/events/emit.ts +120 -0
- package/src/core/hooks/events/schema.ts +430 -0
- package/src/core/hooks/events/ulid.ts +51 -0
- package/src/core/hooks/harness/detect.ts +30 -0
- package/src/core/hooks/harness/events.ts +102 -0
- package/src/core/hooks/harness/output.ts +100 -0
- package/src/core/hooks/harness/parse.ts +180 -0
- package/src/core/hooks/index.ts +16 -0
- package/src/core/hooks/resolve/anchor.ts +51 -0
- package/src/core/hooks/resolve/coord-root.ts +25 -0
- package/src/core/hooks/resolve/intent.ts +89 -0
- package/src/core/hooks/resolve/owner.ts +140 -0
- package/src/core/hooks/resolve/transcript.ts +72 -0
- package/src/hooks/.gitkeep +0 -0
- package/src/index.ts +15 -0
- package/src/lib/agent-browser/client.ts +239 -0
- package/src/lib/agent-browser/index.ts +1 -0
- package/src/lib/browser/client.ts +449 -0
- package/src/lib/browser/dev-overlay.ts +207 -0
- package/src/lib/browser/index.ts +24 -0
- package/src/lib/browser/layout.ts +288 -0
- package/src/lib/browser/visibility.ts +419 -0
- package/src/lib/browser/visual-diff.ts +150 -0
- package/src/lib/completion/bash.ts +291 -0
- package/src/lib/completion/fish.ts +134 -0
- package/src/lib/completion/index.ts +10 -0
- package/src/lib/completion/walk.ts +184 -0
- package/src/lib/completion/zsh.ts +262 -0
- package/src/lib/context/index.ts +386 -0
- package/src/lib/cookies/client.ts +301 -0
- package/src/lib/cookies/index.ts +13 -0
- package/src/lib/council/index.ts +803 -0
- package/src/lib/docs-index.ts +216 -0
- package/src/lib/docs-lint.ts +413 -0
- package/src/lib/docs-sweep.ts +348 -0
- package/src/lib/docs.ts +199 -0
- package/src/lib/env.ts +12 -0
- package/src/lib/exec.ts +74 -0
- package/src/lib/format.ts +147 -0
- package/src/lib/http/client.ts +211 -0
- package/src/lib/http/index.ts +1 -0
- package/src/lib/identities/index.ts +210 -0
- package/src/lib/machine.ts +61 -0
- package/src/lib/presence.ts +154 -0
- package/src/lib/readability/client.ts +156 -0
- package/src/lib/readability/index.ts +5 -0
- package/src/lib/readability/turndown-plugin-gfm.d.ts +10 -0
- package/src/lib/scratch/index.ts +470 -0
- package/src/lib/tunnel/gate.ts +113 -0
- package/src/lib/tunnel/state.ts +167 -0
- package/src/web/.gitkeep +0 -0
- package/index.js +0 -1
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hurricane-style name pool for the agent coordination layer. The name-pool
|
|
3
|
+
* assignment + resolution helpers.
|
|
4
|
+
*
|
|
5
|
+
* Layout invariant: 260 entries (10 per starting letter A..Z). Counter N
|
|
6
|
+
* picks COORD_NAMES[N % 260]; wraps to A at N=260.
|
|
7
|
+
*
|
|
8
|
+
* Durable persistence: `.harnery/.name-history` (JSONL, one row per assignment)
|
|
9
|
+
* + `.harnery/.name-counter` (current counter, atomic temp+rename).
|
|
10
|
+
*
|
|
11
|
+
* Recreation rule (mirrors v1):
|
|
12
|
+
* 1. Own instance_id in name-history → (original name, original kind)
|
|
13
|
+
* 2. session_id in name-history (owner != session) → (parent's name, "transient")
|
|
14
|
+
* 3. Else: new assignment, consume a counter slot.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
18
|
+
import { dirname, join } from "node:path";
|
|
19
|
+
|
|
20
|
+
/** All 260 names. */
|
|
21
|
+
export const COORD_NAMES = [
|
|
22
|
+
// Pass 1
|
|
23
|
+
"Anna",
|
|
24
|
+
"Bob",
|
|
25
|
+
"Carlos",
|
|
26
|
+
"Dalia",
|
|
27
|
+
"Erika",
|
|
28
|
+
"Fred",
|
|
29
|
+
"Gemma",
|
|
30
|
+
"Hank",
|
|
31
|
+
"Imelda",
|
|
32
|
+
"Jerry",
|
|
33
|
+
"Kirk",
|
|
34
|
+
"Lee",
|
|
35
|
+
"Milton",
|
|
36
|
+
"Nate",
|
|
37
|
+
"Oscar",
|
|
38
|
+
"Patty",
|
|
39
|
+
"Quentin",
|
|
40
|
+
"Rafael",
|
|
41
|
+
"Sara",
|
|
42
|
+
"Tony",
|
|
43
|
+
"Ulrik",
|
|
44
|
+
"Valerie",
|
|
45
|
+
"Whitney",
|
|
46
|
+
"Xander",
|
|
47
|
+
"Yara",
|
|
48
|
+
"Zara",
|
|
49
|
+
// Pass 2
|
|
50
|
+
"Adelaide",
|
|
51
|
+
"Bertha",
|
|
52
|
+
"Carmen",
|
|
53
|
+
"Dorian",
|
|
54
|
+
"Edna",
|
|
55
|
+
"Francine",
|
|
56
|
+
"Greta",
|
|
57
|
+
"Helene",
|
|
58
|
+
"Ines",
|
|
59
|
+
"Joyce",
|
|
60
|
+
"Karen",
|
|
61
|
+
"Lorenzo",
|
|
62
|
+
"Mindy",
|
|
63
|
+
"Nadine",
|
|
64
|
+
"Odette",
|
|
65
|
+
"Paulette",
|
|
66
|
+
"Quinn",
|
|
67
|
+
"Rebekah",
|
|
68
|
+
"Sean",
|
|
69
|
+
"Tammy",
|
|
70
|
+
"Ursula",
|
|
71
|
+
"Vinson",
|
|
72
|
+
"Wallace",
|
|
73
|
+
"Xanthe",
|
|
74
|
+
"Yusuf",
|
|
75
|
+
"Zoe",
|
|
76
|
+
// Pass 3
|
|
77
|
+
"Alex",
|
|
78
|
+
"Beatrice",
|
|
79
|
+
"Cyrus",
|
|
80
|
+
"Delia",
|
|
81
|
+
"Ernesto",
|
|
82
|
+
"Florence",
|
|
83
|
+
"Gordon",
|
|
84
|
+
"Hester",
|
|
85
|
+
"Isaias",
|
|
86
|
+
"Jenna",
|
|
87
|
+
"Klaus",
|
|
88
|
+
"Larry",
|
|
89
|
+
"Maxine",
|
|
90
|
+
"Nicholas",
|
|
91
|
+
"Otto",
|
|
92
|
+
"Peter",
|
|
93
|
+
"Quill",
|
|
94
|
+
"Renee",
|
|
95
|
+
"Stella",
|
|
96
|
+
"Theresa",
|
|
97
|
+
"Umberto",
|
|
98
|
+
"Virgil",
|
|
99
|
+
"Willow",
|
|
100
|
+
"Xavier",
|
|
101
|
+
"Yolanda",
|
|
102
|
+
"Zane",
|
|
103
|
+
// Pass 4
|
|
104
|
+
"Anita",
|
|
105
|
+
"Bruno",
|
|
106
|
+
"Cora",
|
|
107
|
+
"Damon",
|
|
108
|
+
"Edith",
|
|
109
|
+
"Felix",
|
|
110
|
+
"Gloria",
|
|
111
|
+
"Holly",
|
|
112
|
+
"Iris",
|
|
113
|
+
"Jasper",
|
|
114
|
+
"Kaia",
|
|
115
|
+
"Linda",
|
|
116
|
+
"Marco",
|
|
117
|
+
"Nora",
|
|
118
|
+
"Olive",
|
|
119
|
+
"Petra",
|
|
120
|
+
"Querida",
|
|
121
|
+
"Roman",
|
|
122
|
+
"Sebastian",
|
|
123
|
+
"Tobias",
|
|
124
|
+
"Una",
|
|
125
|
+
"Vera",
|
|
126
|
+
"Walter",
|
|
127
|
+
"Xena",
|
|
128
|
+
"Yusra",
|
|
129
|
+
"Zelda",
|
|
130
|
+
// Pass 5
|
|
131
|
+
"Aaron",
|
|
132
|
+
"Bonnie",
|
|
133
|
+
"Caleb",
|
|
134
|
+
"Daphne",
|
|
135
|
+
"Elias",
|
|
136
|
+
"Fiona",
|
|
137
|
+
"Galileo",
|
|
138
|
+
"Hugo",
|
|
139
|
+
"Ian",
|
|
140
|
+
"Jude",
|
|
141
|
+
"Knox",
|
|
142
|
+
"Leo",
|
|
143
|
+
"Maya",
|
|
144
|
+
"Nash",
|
|
145
|
+
"Owen",
|
|
146
|
+
"Paxton",
|
|
147
|
+
"Quetzal",
|
|
148
|
+
"Rosa",
|
|
149
|
+
"Sage",
|
|
150
|
+
"Talia",
|
|
151
|
+
"Uri",
|
|
152
|
+
"Vincent",
|
|
153
|
+
"Wesley",
|
|
154
|
+
"Ximena",
|
|
155
|
+
"Yvette",
|
|
156
|
+
"Zephyr",
|
|
157
|
+
// Pass 6
|
|
158
|
+
"Astrid",
|
|
159
|
+
"Beau",
|
|
160
|
+
"Celeste",
|
|
161
|
+
"Dexter",
|
|
162
|
+
"Ezra",
|
|
163
|
+
"Fitz",
|
|
164
|
+
"Genevieve",
|
|
165
|
+
"Hadley",
|
|
166
|
+
"Imogen",
|
|
167
|
+
"Joaquin",
|
|
168
|
+
"Kira",
|
|
169
|
+
"Lila",
|
|
170
|
+
"Mason",
|
|
171
|
+
"Nila",
|
|
172
|
+
"Olga",
|
|
173
|
+
"Pearl",
|
|
174
|
+
"Quincy",
|
|
175
|
+
"Royce",
|
|
176
|
+
"Sterling",
|
|
177
|
+
"Trent",
|
|
178
|
+
"Ulysses",
|
|
179
|
+
"Violet",
|
|
180
|
+
"Wynne",
|
|
181
|
+
"Xerxes",
|
|
182
|
+
"Yael",
|
|
183
|
+
"Zinnia",
|
|
184
|
+
// Pass 7
|
|
185
|
+
"Amelia",
|
|
186
|
+
"Bianca",
|
|
187
|
+
"Cody",
|
|
188
|
+
"Dahlia",
|
|
189
|
+
"Esme",
|
|
190
|
+
"Fern",
|
|
191
|
+
"Greer",
|
|
192
|
+
"Harriet",
|
|
193
|
+
"Ivan",
|
|
194
|
+
"Juno",
|
|
195
|
+
"Kendrick",
|
|
196
|
+
"Luther",
|
|
197
|
+
"Margot",
|
|
198
|
+
"Nigel",
|
|
199
|
+
"Orion",
|
|
200
|
+
"Phillip",
|
|
201
|
+
"Quenby",
|
|
202
|
+
"Reagan",
|
|
203
|
+
"Sienna",
|
|
204
|
+
"Tessa",
|
|
205
|
+
"Uma",
|
|
206
|
+
"Vesper",
|
|
207
|
+
"Watson",
|
|
208
|
+
"Xiomara",
|
|
209
|
+
"Yuri",
|
|
210
|
+
"Zoltan",
|
|
211
|
+
// Pass 8
|
|
212
|
+
"Andre",
|
|
213
|
+
"Boris",
|
|
214
|
+
"Cassidy",
|
|
215
|
+
"Davis",
|
|
216
|
+
"Evander",
|
|
217
|
+
"Forrest",
|
|
218
|
+
"Gibson",
|
|
219
|
+
"Henry",
|
|
220
|
+
"Irene",
|
|
221
|
+
"Justus",
|
|
222
|
+
"Kasper",
|
|
223
|
+
"Lainey",
|
|
224
|
+
"Miles",
|
|
225
|
+
"Naomi",
|
|
226
|
+
"Ophelia",
|
|
227
|
+
"Phoebe",
|
|
228
|
+
"Quark",
|
|
229
|
+
"Rylie",
|
|
230
|
+
"Saul",
|
|
231
|
+
"Truman",
|
|
232
|
+
"Ulrich",
|
|
233
|
+
"Voss",
|
|
234
|
+
"Winifred",
|
|
235
|
+
"Xuxa",
|
|
236
|
+
"Yvonne",
|
|
237
|
+
"Zia",
|
|
238
|
+
// Pass 9
|
|
239
|
+
"Aria",
|
|
240
|
+
"Brenda",
|
|
241
|
+
"Crispin",
|
|
242
|
+
"Dolores",
|
|
243
|
+
"Estelle",
|
|
244
|
+
"Felicity",
|
|
245
|
+
"Goldie",
|
|
246
|
+
"Hazel",
|
|
247
|
+
"Ira",
|
|
248
|
+
"Jovi",
|
|
249
|
+
"Kestrel",
|
|
250
|
+
"Lyric",
|
|
251
|
+
"Mavis",
|
|
252
|
+
"Nico",
|
|
253
|
+
"Otis",
|
|
254
|
+
"Percy",
|
|
255
|
+
"Querubin",
|
|
256
|
+
"Rhett",
|
|
257
|
+
"Scout",
|
|
258
|
+
"Tatum",
|
|
259
|
+
"Unity",
|
|
260
|
+
"Vivian",
|
|
261
|
+
"Wyatt",
|
|
262
|
+
"Xan",
|
|
263
|
+
"Yancy",
|
|
264
|
+
"Zev",
|
|
265
|
+
// Pass 10
|
|
266
|
+
"Atticus",
|
|
267
|
+
"Barnaby",
|
|
268
|
+
"Calliope",
|
|
269
|
+
"Drake",
|
|
270
|
+
"Eustace",
|
|
271
|
+
"Foster",
|
|
272
|
+
"Granger",
|
|
273
|
+
"Hollis",
|
|
274
|
+
"Indira",
|
|
275
|
+
"Jericho",
|
|
276
|
+
"Kaleb",
|
|
277
|
+
"Logan",
|
|
278
|
+
"Magnus",
|
|
279
|
+
"Noor",
|
|
280
|
+
"Oakley",
|
|
281
|
+
"Posy",
|
|
282
|
+
"Quito",
|
|
283
|
+
"Rosalind",
|
|
284
|
+
"Sloane",
|
|
285
|
+
"Theron",
|
|
286
|
+
"Upton",
|
|
287
|
+
"Vance",
|
|
288
|
+
"Wendell",
|
|
289
|
+
"Xola",
|
|
290
|
+
"Yann",
|
|
291
|
+
"Zora",
|
|
292
|
+
] as const;
|
|
293
|
+
|
|
294
|
+
if (COORD_NAMES.length !== 260) {
|
|
295
|
+
throw new Error(`COORD_NAMES table corrupt: expected 260 entries, got ${COORD_NAMES.length}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export type NameKind = "session" | "subagent" | "transient";
|
|
299
|
+
|
|
300
|
+
interface NameHistoryRow {
|
|
301
|
+
instance_id: string;
|
|
302
|
+
name: string;
|
|
303
|
+
kind: NameKind;
|
|
304
|
+
ts: string;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function atomicWrite(path: string, content: string): void {
|
|
308
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
309
|
+
const tmp = `${path}.tmp.${process.pid}`;
|
|
310
|
+
writeFileSync(tmp, content, "utf8");
|
|
311
|
+
renameSync(tmp, path);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function counterPath(coordRoot: string): string {
|
|
315
|
+
return join(coordRoot, ".harnery", ".name-counter");
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function historyPath(coordRoot: string): string {
|
|
319
|
+
return join(coordRoot, ".harnery", ".name-history");
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function readHistory(coordRoot: string): NameHistoryRow[] {
|
|
323
|
+
const p = historyPath(coordRoot);
|
|
324
|
+
if (!existsSync(p)) return [];
|
|
325
|
+
try {
|
|
326
|
+
return readFileSync(p, "utf8")
|
|
327
|
+
.split("\n")
|
|
328
|
+
.filter((line) => line.length > 0)
|
|
329
|
+
.map((line) => JSON.parse(line) as NameHistoryRow);
|
|
330
|
+
} catch {
|
|
331
|
+
return [];
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
function appendHistory(coordRoot: string, row: NameHistoryRow): void {
|
|
336
|
+
const p = historyPath(coordRoot);
|
|
337
|
+
mkdirSync(dirname(p), { recursive: true });
|
|
338
|
+
const line = `${JSON.stringify(row)}\n`;
|
|
339
|
+
// Append is naturally atomic for lines <PIPE_BUF (4096 on Linux).
|
|
340
|
+
writeFileSync(p, line, { encoding: "utf8", flag: "a" });
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Resolve (name, kind) for an existing owner without consuming a counter
|
|
345
|
+
* slot. Returns null if no history match found.
|
|
346
|
+
*
|
|
347
|
+
* 1. Own instance_id → original (name, kind)
|
|
348
|
+
* 2. session_id (owner != session) → (parent's name, "transient")
|
|
349
|
+
*/
|
|
350
|
+
export function resolveName(
|
|
351
|
+
coordRoot: string,
|
|
352
|
+
instanceId: string,
|
|
353
|
+
sessionId?: string,
|
|
354
|
+
): { name: string; kind: NameKind } | null {
|
|
355
|
+
const history = readHistory(coordRoot);
|
|
356
|
+
|
|
357
|
+
for (const row of history) {
|
|
358
|
+
if (row.instance_id === instanceId) {
|
|
359
|
+
return { name: row.name, kind: row.kind };
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (sessionId && sessionId !== instanceId) {
|
|
364
|
+
for (const row of history) {
|
|
365
|
+
if (row.instance_id === sessionId) {
|
|
366
|
+
return { name: row.name, kind: "transient" };
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Assign a name to <instanceId> with the given <kind>. Counter-consuming when
|
|
376
|
+
* the owner is new. Idempotent: returns existing name on resume.
|
|
377
|
+
*/
|
|
378
|
+
export function assignName(coordRoot: string, instanceId: string, kind: NameKind): string {
|
|
379
|
+
// Check 1: existing history row → original name.
|
|
380
|
+
const existing = resolveName(coordRoot, instanceId);
|
|
381
|
+
if (existing) return existing.name;
|
|
382
|
+
|
|
383
|
+
// New owner: consume a counter slot.
|
|
384
|
+
const cPath = counterPath(coordRoot);
|
|
385
|
+
let counter = 0;
|
|
386
|
+
if (existsSync(cPath)) {
|
|
387
|
+
const raw = readFileSync(cPath, "utf8").trim();
|
|
388
|
+
if (/^\d+$/.test(raw)) counter = Number.parseInt(raw, 10);
|
|
389
|
+
}
|
|
390
|
+
const name = COORD_NAMES[counter % 260]!;
|
|
391
|
+
atomicWrite(cPath, String(counter + 1));
|
|
392
|
+
appendHistory(coordRoot, {
|
|
393
|
+
instance_id: instanceId,
|
|
394
|
+
name,
|
|
395
|
+
kind,
|
|
396
|
+
ts: new Date().toISOString().replace(/\.\d{3}Z$/, "Z"),
|
|
397
|
+
});
|
|
398
|
+
return name;
|
|
399
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pid-map writer.
|
|
3
|
+
*
|
|
4
|
+
* Per-harness pid-map at `.harnery/pid-map/<pid>` containing
|
|
5
|
+
* `<instance_id>\t<platform>`. `harn agents whoami` walks ppid up 20 hops looking
|
|
6
|
+
* for a matching entry (preferring the harness, falling back to any platform).
|
|
7
|
+
*
|
|
8
|
+
* Atomic temp+rename. Idempotent: re-writing the same row is a no-op.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
12
|
+
import { dirname, join } from "node:path";
|
|
13
|
+
|
|
14
|
+
function atomicWrite(path: string, content: string): void {
|
|
15
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
16
|
+
const tmp = `${path}.tmp.${process.pid}`;
|
|
17
|
+
writeFileSync(tmp, content, "utf8");
|
|
18
|
+
renameSync(tmp, path);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function writePidmapRow(
|
|
22
|
+
coordRoot: string,
|
|
23
|
+
pid: number,
|
|
24
|
+
instanceId: string,
|
|
25
|
+
platform: string,
|
|
26
|
+
): void {
|
|
27
|
+
const path = join(coordRoot, ".harnery", "pid-map", String(pid));
|
|
28
|
+
const row = `${instanceId}\t${platform}`;
|
|
29
|
+
// Read-then-write idempotency: skip the rename churn when already current.
|
|
30
|
+
if (existsSync(path)) {
|
|
31
|
+
try {
|
|
32
|
+
if (readFileSync(path, "utf8") === row) return;
|
|
33
|
+
} catch {
|
|
34
|
+
/* fall through to write */
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
atomicWrite(path, row);
|
|
38
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scratchpad mutations: append-only timestamped journal at
|
|
3
|
+
* `.harnery/scratch/<instance_id>.md`.
|
|
4
|
+
*
|
|
5
|
+
* Used by the agents-coord web UI route handlers for both operator-nudge
|
|
6
|
+
* appends and inline edits.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
copyFileSync,
|
|
11
|
+
existsSync,
|
|
12
|
+
mkdirSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
renameSync,
|
|
15
|
+
writeFileSync,
|
|
16
|
+
} from "node:fs";
|
|
17
|
+
import { dirname, join } from "node:path";
|
|
18
|
+
|
|
19
|
+
const ALLOWED_CATEGORIES = new Set([
|
|
20
|
+
"note",
|
|
21
|
+
"plan",
|
|
22
|
+
"decision",
|
|
23
|
+
"blocker",
|
|
24
|
+
"question",
|
|
25
|
+
"done",
|
|
26
|
+
"handoff",
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
const APPEND_BODY_CAP = 4096;
|
|
30
|
+
|
|
31
|
+
function nowIsoSeconds(): string {
|
|
32
|
+
return new Date().toISOString().replace(/\.\d{3}Z$/, "Z");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function scratchPath(coordRoot: string, instanceId: string): string {
|
|
36
|
+
return join(coordRoot, ".harnery", "scratch", `${instanceId}.md`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function archivePath(coordRoot: string, instanceId: string, suffix: string): string {
|
|
40
|
+
return join(coordRoot, ".harnery", "scratch", "archived", `${instanceId}-${suffix}.md`);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function atomicWriteText(path: string, content: string): void {
|
|
44
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
45
|
+
const tmp = `${path}.tmp.${process.pid}`;
|
|
46
|
+
writeFileSync(tmp, content, "utf8");
|
|
47
|
+
renameSync(tmp, path);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Append a timestamped entry to the owner's scratchpad.
|
|
52
|
+
* Returns true on success, false if validation failed.
|
|
53
|
+
*/
|
|
54
|
+
export function appendScratch(
|
|
55
|
+
coordRoot: string,
|
|
56
|
+
instanceId: string,
|
|
57
|
+
category: string,
|
|
58
|
+
body: string,
|
|
59
|
+
): { ok: boolean; reason?: string; path?: string } {
|
|
60
|
+
if (!ALLOWED_CATEGORIES.has(category)) {
|
|
61
|
+
return { ok: false, reason: `invalid category "${category}"` };
|
|
62
|
+
}
|
|
63
|
+
if (!body || body.length === 0) {
|
|
64
|
+
return { ok: false, reason: "body required" };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const trimmedBody =
|
|
68
|
+
body.length > APPEND_BODY_CAP ? `${body.slice(0, APPEND_BODY_CAP - 3)}...` : body;
|
|
69
|
+
const target = scratchPath(coordRoot, instanceId);
|
|
70
|
+
const ts = nowIsoSeconds();
|
|
71
|
+
|
|
72
|
+
let prior = "";
|
|
73
|
+
if (existsSync(target)) {
|
|
74
|
+
prior = readFileSync(target, "utf8");
|
|
75
|
+
if (!prior.endsWith("\n")) prior += "\n";
|
|
76
|
+
}
|
|
77
|
+
const entry = `## [${ts}] ${category}\n${trimmedBody}\n`;
|
|
78
|
+
atomicWriteText(target, prior + entry);
|
|
79
|
+
return { ok: true, path: target };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Replace the scratchpad with new body, archiving prior contents and
|
|
84
|
+
* appending an "(edited via UI by Ryan)" audit-marker note.
|
|
85
|
+
*/
|
|
86
|
+
export function editScratchpad(
|
|
87
|
+
coordRoot: string,
|
|
88
|
+
instanceId: string,
|
|
89
|
+
newBody: string,
|
|
90
|
+
summary: string,
|
|
91
|
+
): { ok: boolean; reason?: string; archivePath?: string; path?: string } {
|
|
92
|
+
if (typeof newBody !== "string") {
|
|
93
|
+
return { ok: false, reason: "newBody required" };
|
|
94
|
+
}
|
|
95
|
+
const target = scratchPath(coordRoot, instanceId);
|
|
96
|
+
const ts = nowIsoSeconds();
|
|
97
|
+
const archiveSuffix = `pre-ui-${ts.replace(/:/g, "-")}`;
|
|
98
|
+
const archive = archivePath(coordRoot, instanceId, archiveSuffix);
|
|
99
|
+
|
|
100
|
+
mkdirSync(dirname(archive), { recursive: true });
|
|
101
|
+
|
|
102
|
+
let prior = "";
|
|
103
|
+
if (existsSync(target)) {
|
|
104
|
+
try {
|
|
105
|
+
copyFileSync(target, archive);
|
|
106
|
+
} catch {
|
|
107
|
+
/* archive optional; continue */
|
|
108
|
+
}
|
|
109
|
+
prior = readFileSync(target, "utf8");
|
|
110
|
+
if (!prior.endsWith("\n")) prior += "\n";
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const summaryText = summary && summary.length > 0 ? summary : "(no summary)";
|
|
114
|
+
const auditMarker =
|
|
115
|
+
`## [${ts}] note (edited via UI by Ryan)\n` +
|
|
116
|
+
`${summaryText}\n` +
|
|
117
|
+
`Pre-edit archived at .harnery/scratch/archived/${instanceId}-${archiveSuffix}.md\n\n`;
|
|
118
|
+
|
|
119
|
+
atomicWriteText(target, prior + auditMarker + newBody + (newBody.endsWith("\n") ? "" : "\n"));
|
|
120
|
+
return { ok: true, archivePath: archive, path: target };
|
|
121
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A heuristic parser that extracts file paths likely to be mutated by a
|
|
3
|
+
* shell command. Used by
|
|
4
|
+
* the cursor + codex harness adapters to emit SHELL_CLAIM_CANDIDATE log lines
|
|
5
|
+
* (warn-only, never blocks).
|
|
6
|
+
*
|
|
7
|
+
* Two cases:
|
|
8
|
+
* 1. Output redirections: `> path` and `>> path`
|
|
9
|
+
* 2. Common mutators: `sed -i…`, `cp`, `mv`, `touch`: capture the next
|
|
10
|
+
* non-space token after the command name (intentionally single-arg even
|
|
11
|
+
* though `cp src dest` has two args)
|
|
12
|
+
*
|
|
13
|
+
* Caller-supplied `coordRoot` is stripped from absolute paths so the warn
|
|
14
|
+
* log shows monorepo-relative form.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export function shellMutationPaths(cmd: string, coordRoot: string | null = null): string[] {
|
|
18
|
+
if (!cmd) return [];
|
|
19
|
+
const out: string[] = [];
|
|
20
|
+
|
|
21
|
+
// Output redirections: > path / >> path
|
|
22
|
+
const redirectRe = />>?[ \t]+([^ \t;|&"'`]+)/g;
|
|
23
|
+
let m: RegExpExecArray | null = redirectRe.exec(cmd);
|
|
24
|
+
while (m !== null) {
|
|
25
|
+
out.push(m[1]!);
|
|
26
|
+
m = redirectRe.exec(cmd);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Common mutators. Capture up to the first whitespace after the command
|
|
30
|
+
// name and take the final token. For 1-arg commands (touch, sed -i 'expr',
|
|
31
|
+
// cp WITHOUT a dest) that's the path; for 2-arg commands (`cp src dest`,
|
|
32
|
+
// `mv src dest`) it's the source, intentionally heuristic-only.
|
|
33
|
+
const cmdRe = /\b(?:sed -i\S*|cp|mv|touch)[ \t]+([^ \t;|&]+)/g;
|
|
34
|
+
m = cmdRe.exec(cmd);
|
|
35
|
+
while (m !== null) {
|
|
36
|
+
out.push(m[1]!);
|
|
37
|
+
m = cmdRe.exec(cmd);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return out
|
|
41
|
+
.map((p) => p.replace(/^\.\//, ""))
|
|
42
|
+
.map((p) => (coordRoot && p.startsWith(`${coordRoot}/`) ? p.slice(coordRoot.length + 1) : p))
|
|
43
|
+
.filter((p) => p.length > 0);
|
|
44
|
+
}
|