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,161 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stop-hook verdict: rule 1/3, 2/3, 3/3 enforcement evaluated
|
|
3
|
+
* from the canonical event stream alone (no transcript scan).
|
|
4
|
+
*
|
|
5
|
+
* Rule 1/3: `state.status_checked` event with matching turn boundary exists.
|
|
6
|
+
* Rule 2/3: latest `turn.stop` event has `status_box_present: true` (or the
|
|
7
|
+
* stop currently firing carries that field via the in-flight event
|
|
8
|
+
* agent-hook emits before the stop hook runs).
|
|
9
|
+
* Rule 3/3: `state.task_set` event with matching turn boundary exists.
|
|
10
|
+
*
|
|
11
|
+
* Pure-prose-turn exemption: when zero `tool.pre_use` events fire in
|
|
12
|
+
* the current turn, rules 1/3 and 3/3 do not apply. Rule 2/3 still applies
|
|
13
|
+
* as a user-visible mobile cue.
|
|
14
|
+
*/
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
import { resolveBinName } from "../../config.js";
|
|
18
|
+
function ackSignalFor(harness) {
|
|
19
|
+
return harness === "cursor" ? "status_checked" : "status_box_present";
|
|
20
|
+
}
|
|
21
|
+
const RECENT_EVENT_WINDOW_LINES = 5_000;
|
|
22
|
+
/**
|
|
23
|
+
* Evaluate the Stop-hook verdict. Returns the first failing rule (or allow
|
|
24
|
+
* when all three pass). Soft-fails open when the event stream isn't
|
|
25
|
+
* readable, fail-open posture on a verdict failure.
|
|
26
|
+
*/
|
|
27
|
+
export function evaluateStopHook(coordRoot, req) {
|
|
28
|
+
if (req.bypass) {
|
|
29
|
+
return {
|
|
30
|
+
allow: true,
|
|
31
|
+
exit_code: 0,
|
|
32
|
+
rule: "stop-hook.bypass",
|
|
33
|
+
reason: "HARNERY_AGENT_COORD_BYPASS_STOP=1",
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
let events;
|
|
37
|
+
try {
|
|
38
|
+
events = readRecentEvents(coordRoot, RECENT_EVENT_WINDOW_LINES);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return {
|
|
42
|
+
allow: true,
|
|
43
|
+
exit_code: 0,
|
|
44
|
+
rule: "stop-hook.fail_open",
|
|
45
|
+
reason: "events.ndjson not readable; failing open",
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const ownerEvents = events.filter((e) => e.instance_id === req.instance_id);
|
|
49
|
+
if (ownerEvents.length === 0) {
|
|
50
|
+
return {
|
|
51
|
+
allow: true,
|
|
52
|
+
exit_code: 0,
|
|
53
|
+
rule: "stop-hook.no_history",
|
|
54
|
+
reason: "no canonical events for this owner; defer to legacy or skip",
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Turn window: from the most recent user_prompt.submit (this owner) up to
|
|
58
|
+
// either the explicit now_ms or the last event we see. Fall back to a
|
|
59
|
+
// 5-minute window when no user_prompt.submit is in scope (fresh wiring,
|
|
60
|
+
// out-of-window prompt, etc.) so a stale stream doesn't silently pass.
|
|
61
|
+
const nowMs = req.now_ms ?? Date.now();
|
|
62
|
+
const lastUserPrompt = [...ownerEvents]
|
|
63
|
+
.reverse()
|
|
64
|
+
.find((e) => e.event_type === "user_prompt.submit");
|
|
65
|
+
const startMs = lastUserPrompt ? Date.parse(lastUserPrompt.ts) : nowMs - 5 * 60 * 1000;
|
|
66
|
+
const inTurn = ownerEvents.filter((e) => {
|
|
67
|
+
const t = Date.parse(e.ts);
|
|
68
|
+
return Number.isFinite(t) && t >= startMs && t <= nowMs;
|
|
69
|
+
});
|
|
70
|
+
const toolPreUseInTurn = inTurn.some((e) => e.event_type === "tool.pre_use");
|
|
71
|
+
const statusChecked = inTurn.some((e) => e.event_type === "state.status_checked");
|
|
72
|
+
const taskSet = inTurn.some((e) => e.event_type === "state.task_set");
|
|
73
|
+
// Rule 2/3: status_box_present on the most recent turn.stop for this owner.
|
|
74
|
+
// The turn.stop event fires from agent-hook stop, which is wired BEFORE
|
|
75
|
+
// the stop-hook verdict, so by the time we evaluate, the just-
|
|
76
|
+
// fired turn.stop is already in the stream.
|
|
77
|
+
const latestTurnStop = [...inTurn].reverse().find((e) => e.event_type === "turn.stop");
|
|
78
|
+
const boxPresent = latestTurnStop ? Boolean(latestTurnStop.data.status_box_present) : false;
|
|
79
|
+
// Harness-aware end-of-turn ack signal (see `ackSignalFor`). On Cursor the
|
|
80
|
+
// ack is `status_checked` (running `harn agents status` shows the box inline);
|
|
81
|
+
// on Claude Code / Codex it's the transcript-scanned `status_box_present`.
|
|
82
|
+
// The matching block helper carries the right "how to fix" message.
|
|
83
|
+
const ackSignal = ackSignalFor(req.harness);
|
|
84
|
+
const ackPresent = ackSignal === "status_checked" ? statusChecked : boxPresent;
|
|
85
|
+
const ackBlock = ackSignal === "status_checked" ? rule13Block : rule23Block;
|
|
86
|
+
// Pure-prose-turn exemption: only the ack signal applies. Parity
|
|
87
|
+
// across harnesses: CC requires the box; Cursor requires status_checked.
|
|
88
|
+
if (!toolPreUseInTurn) {
|
|
89
|
+
if (!ackPresent) {
|
|
90
|
+
return ackBlock();
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
allow: true,
|
|
94
|
+
exit_code: 0,
|
|
95
|
+
rule: "stop-hook.pure_prose_pass",
|
|
96
|
+
reason: "no tool calls this turn; rules 1/3 + 3/3 skipped",
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
if (!statusChecked)
|
|
100
|
+
return rule13Block();
|
|
101
|
+
// On Cursor `ackPresent === statusChecked` (already true here), so this is a
|
|
102
|
+
// no-op and rule 2/3 is not enforced; on CC/Codex it's the box-paste check.
|
|
103
|
+
if (!ackPresent)
|
|
104
|
+
return ackBlock();
|
|
105
|
+
if (!taskSet)
|
|
106
|
+
return rule33Block();
|
|
107
|
+
return {
|
|
108
|
+
allow: true,
|
|
109
|
+
exit_code: 0,
|
|
110
|
+
rule: "stop-hook.pass",
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function rule13Block() {
|
|
114
|
+
return {
|
|
115
|
+
allow: false,
|
|
116
|
+
exit_code: 2,
|
|
117
|
+
rule: "stop-hook.rule_1_3",
|
|
118
|
+
reason: `End-of-turn rule (1/3): no state.status_checked event found in this turn; run \`${resolveBinName()} agents status\` as your last tool call.`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function rule23Block() {
|
|
122
|
+
return {
|
|
123
|
+
allow: false,
|
|
124
|
+
exit_code: 2,
|
|
125
|
+
rule: "stop-hook.rule_2_3",
|
|
126
|
+
reason: `End-of-turn rule (2/3): turn.stop did not see the agent-status box in your reply text. Paste the \`${resolveBinName()} agents status\` output verbatim as a fenced code block (the \`┌─ agent-\` prefix is the detection signal).`,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function rule33Block() {
|
|
130
|
+
return {
|
|
131
|
+
allow: false,
|
|
132
|
+
exit_code: 2,
|
|
133
|
+
rule: "stop-hook.rule_3_3",
|
|
134
|
+
reason: `End-of-turn rule (3/3): no state.task_set event found in this turn; run \`${resolveBinName()} agents set-task "<short focus>"\` to declare what you're working on. Pass an empty string if the turn was purely conversational.`,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Read the last N JSON lines from events.ndjson. The Stop-hook verdict needs
|
|
139
|
+
* just the most recent turn so we tail-read aggressively.
|
|
140
|
+
*/
|
|
141
|
+
function readRecentEvents(coordRoot, maxLines) {
|
|
142
|
+
const path = join(coordRoot, ".harnery", "events.ndjson");
|
|
143
|
+
if (!existsSync(path))
|
|
144
|
+
return [];
|
|
145
|
+
const raw = readFileSync(path, "utf8");
|
|
146
|
+
const lines = raw.split("\n");
|
|
147
|
+
const start = Math.max(0, lines.length - maxLines);
|
|
148
|
+
const out = [];
|
|
149
|
+
for (let i = start; i < lines.length; i++) {
|
|
150
|
+
const line = lines[i];
|
|
151
|
+
if (!line?.trim())
|
|
152
|
+
continue;
|
|
153
|
+
try {
|
|
154
|
+
out.push(JSON.parse(line));
|
|
155
|
+
}
|
|
156
|
+
catch {
|
|
157
|
+
/* skip malformed */
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command/narration event emitter for the coordination layer.
|
|
3
|
+
*
|
|
4
|
+
* `writeSessionEvent` emits command + narration events straight to the
|
|
5
|
+
* **canonical** `.harnery/events.ndjson` (alongside the hook events), which the
|
|
6
|
+
* `/live` web viewer reads. The exported surface (`writeSessionEvent`,
|
|
7
|
+
* `newCmdId`, `clampField`, `readLastIntent`) is stable so the session-tee
|
|
8
|
+
* middleware callers need no edits.
|
|
9
|
+
*/
|
|
10
|
+
/** Event types accepted by `writeSessionEvent`. Only the command stream +
|
|
11
|
+
* narration are emitted canonically; the coord/state types are accepted for
|
|
12
|
+
* call-site compatibility but are no-ops (the agents CLI emits those itself). */
|
|
13
|
+
export type SessionEventType = "command_start" | "output" | "command_end" | "end_of_turn" | "hook_event" | "set_task" | "file_claim" | "file_release" | "peer_change" | "narration";
|
|
14
|
+
/**
|
|
15
|
+
* Resolved path of the ndjson sidecar file. Lives inside `.harnery/` so a
|
|
16
|
+
* containerized reader can pick it up through a single bind mount.
|
|
17
|
+
*/
|
|
18
|
+
export declare function sessionEventsPath(): string;
|
|
19
|
+
/** Random 8-char hex id for grouping output lines under a single command. */
|
|
20
|
+
export declare function newCmdId(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Read the model's most recent `<intent>...</intent>` declaration from the
|
|
23
|
+
* intent-stamp file written by the PreToolUse hook. Returns null when the
|
|
24
|
+
* file is missing, empty, or contains the explicit `(no intent)` sentinel.
|
|
25
|
+
* Callers fall back to whatever default they want in that case.
|
|
26
|
+
*
|
|
27
|
+
* Path: `.harnery/.last-intent.<instance_id>` next to the agent's heartbeat.
|
|
28
|
+
*/
|
|
29
|
+
export declare function readLastIntent(instanceId?: string): string | null;
|
|
30
|
+
/**
|
|
31
|
+
* Emit a session event. Command + narration events
|
|
32
|
+
* are written to the canonical `.harnery/events.ndjson`; the coord/state types
|
|
33
|
+
* are accepted for call-site compatibility but are no-ops here (the agents CLI
|
|
34
|
+
* emits those itself). Best-effort, never throws into the caller; a command
|
|
35
|
+
* must never break or slow on telemetry. The `agentName` arg is retained for
|
|
36
|
+
* the stable call signature (canonical events key on instance_id, not name).
|
|
37
|
+
*/
|
|
38
|
+
export declare function writeSessionEvent(type: SessionEventType, _agentName: string, fields?: Record<string, unknown>): void;
|
|
39
|
+
/** Trim long values to keep individual events small. */
|
|
40
|
+
export declare function clampField(v: string, max?: number): string;
|
|
41
|
+
//# sourceMappingURL=session-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-events.d.ts","sourceRoot":"","sources":["../../../src/core/agents/session-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AASH;;iFAEiF;AACjF,MAAM,MAAM,gBAAgB,GACxB,eAAe,GACf,QAAQ,GACR,aAAa,GACb,aAAa,GACb,YAAY,GACZ,UAAU,GACV,YAAY,GACZ,cAAc,GACd,aAAa,GACb,WAAW,CAAC;AAEhB;;;GAGG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAwB1C;AAED,6EAA6E;AAC7E,wBAAgB,QAAQ,IAAI,MAAM,CAEjC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CA8BjE;AAsGD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAC/B,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,IAAI,CAEN;AAED,wDAAwD;AACxD,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,SAAO,GAAG,MAAM,CAGxD"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Command/narration event emitter for the coordination layer.
|
|
3
|
+
*
|
|
4
|
+
* `writeSessionEvent` emits command + narration events straight to the
|
|
5
|
+
* **canonical** `.harnery/events.ndjson` (alongside the hook events), which the
|
|
6
|
+
* `/live` web viewer reads. The exported surface (`writeSessionEvent`,
|
|
7
|
+
* `newCmdId`, `clampField`, `readLastIntent`) is stable so the session-tee
|
|
8
|
+
* middleware callers need no edits.
|
|
9
|
+
*/
|
|
10
|
+
import { randomBytes } from "node:crypto";
|
|
11
|
+
import { existsSync, readFileSync, statSync } from "node:fs";
|
|
12
|
+
import { dirname, resolve } from "node:path";
|
|
13
|
+
// Kept dependency-light: vendored verbatim into a downstream consumer, so no coordEnv import.
|
|
14
|
+
import { normalizeHarness } from "./canonical-emit.js";
|
|
15
|
+
import { emit } from "./events/emit.js";
|
|
16
|
+
/**
|
|
17
|
+
* Resolved path of the ndjson sidecar file. Lives inside `.harnery/` so a
|
|
18
|
+
* containerized reader can pick it up through a single bind mount.
|
|
19
|
+
*/
|
|
20
|
+
export function sessionEventsPath() {
|
|
21
|
+
// Explicit override (tests + non-monorepo invocations).
|
|
22
|
+
const explicit = process.env.HARNERY_OUTPUT_SESSION_EVENTS;
|
|
23
|
+
if (explicit)
|
|
24
|
+
return explicit;
|
|
25
|
+
// Walk up looking for an EXISTING .harnery/ directory; only match dirs
|
|
26
|
+
// (submodule .git is a file/gitlink, and CLAUDE.md / AGENTS.md can
|
|
27
|
+
// proliferate per-subdirectory in many monorepos, so neither is a safe
|
|
28
|
+
// anchor). Don't reintroduce CLAUDE.md / .git as anchors, which creates
|
|
29
|
+
// stray .harnery/ dirs under submodule subtrees.
|
|
30
|
+
let dir = process.cwd();
|
|
31
|
+
for (let i = 0; i < 10; i++) {
|
|
32
|
+
const candidate = resolve(dir, ".harnery");
|
|
33
|
+
try {
|
|
34
|
+
if (existsSync(candidate) && statSync(candidate).isDirectory()) {
|
|
35
|
+
return resolve(candidate, "session-events.ndjson");
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
/* keep walking */
|
|
40
|
+
}
|
|
41
|
+
const parent = dirname(dir);
|
|
42
|
+
if (parent === dir)
|
|
43
|
+
break;
|
|
44
|
+
dir = parent;
|
|
45
|
+
}
|
|
46
|
+
return resolve(process.env.HOME || "/tmp", ".harnery", "session-events.ndjson");
|
|
47
|
+
}
|
|
48
|
+
/** Random 8-char hex id for grouping output lines under a single command. */
|
|
49
|
+
export function newCmdId() {
|
|
50
|
+
return randomBytes(4).toString("hex");
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Read the model's most recent `<intent>...</intent>` declaration from the
|
|
54
|
+
* intent-stamp file written by the PreToolUse hook. Returns null when the
|
|
55
|
+
* file is missing, empty, or contains the explicit `(no intent)` sentinel.
|
|
56
|
+
* Callers fall back to whatever default they want in that case.
|
|
57
|
+
*
|
|
58
|
+
* Path: `.harnery/.last-intent.<instance_id>` next to the agent's heartbeat.
|
|
59
|
+
*/
|
|
60
|
+
export function readLastIntent(instanceId) {
|
|
61
|
+
if (!instanceId)
|
|
62
|
+
return null;
|
|
63
|
+
// Walk up from cwd looking for .harnery/, same resolution as
|
|
64
|
+
// sessionEventsPath() (only match existing directories).
|
|
65
|
+
let dir = process.cwd();
|
|
66
|
+
let agentsDir = null;
|
|
67
|
+
for (let i = 0; i < 10; i++) {
|
|
68
|
+
const candidate = resolve(dir, ".harnery");
|
|
69
|
+
try {
|
|
70
|
+
if (existsSync(candidate) && statSync(candidate).isDirectory()) {
|
|
71
|
+
agentsDir = candidate;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
/* keep walking */
|
|
77
|
+
}
|
|
78
|
+
const parent = dirname(dir);
|
|
79
|
+
if (parent === dir)
|
|
80
|
+
break;
|
|
81
|
+
dir = parent;
|
|
82
|
+
}
|
|
83
|
+
if (!agentsDir)
|
|
84
|
+
return null;
|
|
85
|
+
const intentPath = resolve(agentsDir, `.last-intent.${instanceId}`);
|
|
86
|
+
if (!existsSync(intentPath))
|
|
87
|
+
return null;
|
|
88
|
+
try {
|
|
89
|
+
const raw = readFileSync(intentPath, "utf8").trim();
|
|
90
|
+
if (!raw || raw === "(no intent)")
|
|
91
|
+
return null;
|
|
92
|
+
return raw;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Dual-write: mirror command/narration session-events
|
|
100
|
+
* into the canonical `.harnery/events.ndjson` stream so the legacy
|
|
101
|
+
* session-events.ndjson writer + its web consumers can be retired.
|
|
102
|
+
* Only the command-stream + narration types migrate; the coord/state types
|
|
103
|
+
* (`set_task`, `file_claim`, `peer_change`, …) are already emitted canonically
|
|
104
|
+
* by the agents CLI, so re-emitting them here would double-count.
|
|
105
|
+
*/
|
|
106
|
+
const CANONICAL_TYPE = {
|
|
107
|
+
command_start: "command.start",
|
|
108
|
+
output: "command.output",
|
|
109
|
+
command_end: "command.end",
|
|
110
|
+
narration: "narration",
|
|
111
|
+
};
|
|
112
|
+
/** Cache heartbeat-derived envelope fields per instance_id so a burst of
|
|
113
|
+
* `output` lines (one event per stdout line) doesn't re-read + re-parse the
|
|
114
|
+
* heartbeat JSON each time. Short TTL: picks up platform/session changes
|
|
115
|
+
* within a few seconds without hammering the disk on a chatty command. */
|
|
116
|
+
const enrichCache = new Map();
|
|
117
|
+
const ENRICH_TTL_MS = 5000;
|
|
118
|
+
function enrichFromHeartbeat(coordRoot, instanceId) {
|
|
119
|
+
const now = Date.now();
|
|
120
|
+
const cached = enrichCache.get(instanceId);
|
|
121
|
+
if (cached && now - cached.at < ENRICH_TTL_MS)
|
|
122
|
+
return cached;
|
|
123
|
+
try {
|
|
124
|
+
const hbPath = resolve(coordRoot, ".harnery", "active", `${instanceId}.json`);
|
|
125
|
+
if (!existsSync(hbPath))
|
|
126
|
+
return null;
|
|
127
|
+
const hb = JSON.parse(readFileSync(hbPath, "utf8"));
|
|
128
|
+
const enrichment = {
|
|
129
|
+
session_id: hb.session_id || instanceId,
|
|
130
|
+
harness: normalizeHarness(hb.platform),
|
|
131
|
+
at: now,
|
|
132
|
+
};
|
|
133
|
+
enrichCache.set(instanceId, enrichment);
|
|
134
|
+
return enrichment;
|
|
135
|
+
}
|
|
136
|
+
catch {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
/** Project the flat legacy `fields` into the canonical event's `data` shape.
|
|
141
|
+
* Unknown types never reach here, guarded by CANONICAL_TYPE. */
|
|
142
|
+
function canonicalData(type, fields) {
|
|
143
|
+
switch (type) {
|
|
144
|
+
case "command_start":
|
|
145
|
+
return { cmd_id: fields.cmd_id, intent: fields.intent, cmd: fields.cmd };
|
|
146
|
+
case "output":
|
|
147
|
+
return { cmd_id: fields.cmd_id, stream: fields.stream, line: fields.line };
|
|
148
|
+
case "command_end":
|
|
149
|
+
return {
|
|
150
|
+
cmd_id: fields.cmd_id,
|
|
151
|
+
exit: fields.exit,
|
|
152
|
+
duration_ms: fields.duration_ms,
|
|
153
|
+
...(fields.signal ? { signal: fields.signal } : {}),
|
|
154
|
+
};
|
|
155
|
+
case "narration":
|
|
156
|
+
return { message: fields.message };
|
|
157
|
+
default:
|
|
158
|
+
return {};
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/** Emit a command/narration event to the canonical stream. Swallows every
|
|
162
|
+
* error and skips when identity can't be resolved: telemetry must never break
|
|
163
|
+
* (or slow down) a command. Non-command types return early. */
|
|
164
|
+
function emitCanonicalCommand(type, fields) {
|
|
165
|
+
const eventType = CANONICAL_TYPE[type];
|
|
166
|
+
if (!eventType)
|
|
167
|
+
return;
|
|
168
|
+
const instanceId = typeof fields.instance_id === "string" ? fields.instance_id : undefined;
|
|
169
|
+
if (!instanceId)
|
|
170
|
+
return;
|
|
171
|
+
try {
|
|
172
|
+
// coordRoot = the dir containing `.harnery/`; sessionEventsPath() anchors it.
|
|
173
|
+
const coordRoot = dirname(dirname(sessionEventsPath()));
|
|
174
|
+
const enrich = enrichFromHeartbeat(coordRoot, instanceId);
|
|
175
|
+
if (!enrich)
|
|
176
|
+
return;
|
|
177
|
+
emit(coordRoot, {
|
|
178
|
+
event_type: eventType,
|
|
179
|
+
instance_id: instanceId,
|
|
180
|
+
session_id: enrich.session_id,
|
|
181
|
+
harness: enrich.harness,
|
|
182
|
+
data: canonicalData(type, fields),
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
/* telemetry only, never break the command */
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Emit a session event. Command + narration events
|
|
191
|
+
* are written to the canonical `.harnery/events.ndjson`; the coord/state types
|
|
192
|
+
* are accepted for call-site compatibility but are no-ops here (the agents CLI
|
|
193
|
+
* emits those itself). Best-effort, never throws into the caller; a command
|
|
194
|
+
* must never break or slow on telemetry. The `agentName` arg is retained for
|
|
195
|
+
* the stable call signature (canonical events key on instance_id, not name).
|
|
196
|
+
*/
|
|
197
|
+
export function writeSessionEvent(type, _agentName, fields = {}) {
|
|
198
|
+
emitCanonicalCommand(type, fields);
|
|
199
|
+
}
|
|
200
|
+
/** Trim long values to keep individual events small. */
|
|
201
|
+
export function clampField(v, max = 1024) {
|
|
202
|
+
if (v.length <= max)
|
|
203
|
+
return v;
|
|
204
|
+
return `${v.slice(0, max - 1)}…`;
|
|
205
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display-name resolution for the coord layer.
|
|
3
|
+
*
|
|
4
|
+
* This module once housed `coordLog`, the writer for a human-readable
|
|
5
|
+
* activity log. That log has been retired; the canonical
|
|
6
|
+
* `.harnery/events.ndjson` stream is the single source of truth, and the
|
|
7
|
+
* per-event telemetry that had consumers (heals → health.*, councils →
|
|
8
|
+
* council.*, shell-mutation candidates → decision.warn) is emitted there
|
|
9
|
+
* directly. `coordLog` and its call sites are gone; only `resolveShortName`
|
|
10
|
+
* remains (still used for display-name resolution).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Resolve `agent-<name>` display string. Looks up the heartbeat's `name`
|
|
14
|
+
* field; falls back to `agent-<8-char-hex>` if name is empty (mirrors bash
|
|
15
|
+
* coord_owner_short). Returns `agent-unknown` when instanceId is null.
|
|
16
|
+
*/
|
|
17
|
+
export declare function resolveShortName(coordRoot: string, instanceId: string | null): string;
|
|
18
|
+
//# sourceMappingURL=activity-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activity-log.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/state/activity-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAYrF"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Display-name resolution for the coord layer.
|
|
3
|
+
*
|
|
4
|
+
* This module once housed `coordLog`, the writer for a human-readable
|
|
5
|
+
* activity log. That log has been retired; the canonical
|
|
6
|
+
* `.harnery/events.ndjson` stream is the single source of truth, and the
|
|
7
|
+
* per-event telemetry that had consumers (heals → health.*, councils →
|
|
8
|
+
* council.*, shell-mutation candidates → decision.warn) is emitted there
|
|
9
|
+
* directly. `coordLog` and its call sites are gone; only `resolveShortName`
|
|
10
|
+
* remains (still used for display-name resolution).
|
|
11
|
+
*/
|
|
12
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
/**
|
|
15
|
+
* Resolve `agent-<name>` display string. Looks up the heartbeat's `name`
|
|
16
|
+
* field; falls back to `agent-<8-char-hex>` if name is empty (mirrors bash
|
|
17
|
+
* coord_owner_short). Returns `agent-unknown` when instanceId is null.
|
|
18
|
+
*/
|
|
19
|
+
export function resolveShortName(coordRoot, instanceId) {
|
|
20
|
+
if (!instanceId)
|
|
21
|
+
return "agent-unknown";
|
|
22
|
+
const path = join(coordRoot, ".harnery", "active", `${instanceId}.json`);
|
|
23
|
+
if (existsSync(path)) {
|
|
24
|
+
try {
|
|
25
|
+
const hb = JSON.parse(readFileSync(path, "utf8"));
|
|
26
|
+
if (hb.name && hb.name.length > 0)
|
|
27
|
+
return `agent-${hb.name}`;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
/* fall through to short-id */
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return `agent-${instanceId.slice(0, 8)}`;
|
|
34
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Council manifest mutations: lifecycle helpers for the council-* actions.
|
|
3
|
+
*
|
|
4
|
+
* A council is a multi-round debate among agents recorded at
|
|
5
|
+
* `.harnery/councils/<id>.json` (manifest) plus `.harnery/councils/<id>/round-N/<member>.md`
|
|
6
|
+
* (contributions). Archive moves both into `.harnery/councils/archive/`.
|
|
7
|
+
*
|
|
8
|
+
* This module owns: lifecycle (advance, close, archive, unarchive, delete)
|
|
9
|
+
* and steward reassignment. Council CREATION + contribution writes stay
|
|
10
|
+
* separate (operator-side, harness-agnostic).
|
|
11
|
+
*/
|
|
12
|
+
export declare function advanceCouncil(coordRoot: string, councilId: string, opts?: {
|
|
13
|
+
force?: boolean;
|
|
14
|
+
}): {
|
|
15
|
+
ok: boolean;
|
|
16
|
+
reason?: string;
|
|
17
|
+
pendingMember?: string;
|
|
18
|
+
};
|
|
19
|
+
export declare function closeCouncil(coordRoot: string, councilId: string): {
|
|
20
|
+
ok: boolean;
|
|
21
|
+
reason?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare function archiveCouncil(coordRoot: string, councilId: string): {
|
|
24
|
+
ok: boolean;
|
|
25
|
+
reason?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function unarchiveCouncil(coordRoot: string, councilId: string): {
|
|
28
|
+
ok: boolean;
|
|
29
|
+
reason?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare function deleteCouncil(coordRoot: string, councilId: string): {
|
|
32
|
+
ok: boolean;
|
|
33
|
+
reason?: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function setCouncilSteward(coordRoot: string, councilId: string, newSteward: string, newStewardId: string): {
|
|
36
|
+
ok: boolean;
|
|
37
|
+
reason?: string;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=council.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"council.d.ts","sourceRoot":"","sources":["../../../../src/core/agents/state/council.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAwDH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,IAAI,GAAE;IAAE,KAAK,CAAC,EAAE,OAAO,CAAA;CAAO,GAC7B;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,CAuC1D;AAED,wBAAgB,YAAY,CAC1B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAalC;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAoClC;AAED,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAqClC;AAED,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAChB;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAmBlC;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GACnB;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAuBlC"}
|