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,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `harn sync`: keep a curated subset of `.harnery/` live across machines
|
|
3
|
+
* via rclone (typically a Google Drive remote, but any rclone remote works).
|
|
4
|
+
*
|
|
5
|
+
* Scope: a deliberately small set of file types: durable identities,
|
|
6
|
+
* archived scratchpads, council manifests. The high-churn machine-local
|
|
7
|
+
* stuff (events.ndjson, .pid-map/, active/, .last-intent.*) stays put.
|
|
8
|
+
*
|
|
9
|
+
* Subcommands:
|
|
10
|
+
* init: interactive: `rclone config` walks through Google OAuth, then
|
|
11
|
+
* we record the chosen remote name in ~/.config/harnery/sync.json
|
|
12
|
+
* status: diff local vs remote (rclone check --one-way)
|
|
13
|
+
* push: local to remote (rclone copy)
|
|
14
|
+
* pull: remote to local (rclone copy)
|
|
15
|
+
* list: show what's in the remote
|
|
16
|
+
*
|
|
17
|
+
* Power users override via env (HARNERY_SYNC_REMOTE, HARNERY_SYNC_PREFIX) or by
|
|
18
|
+
* editing the config file. Like `harn backup`, this surfaces rclone rather
|
|
19
|
+
* than abstracting it.
|
|
20
|
+
*/
|
|
21
|
+
import { spawnSync } from "node:child_process";
|
|
22
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
23
|
+
import os from "node:os";
|
|
24
|
+
import path from "node:path";
|
|
25
|
+
// What we sync. Anything matching one of these (relative to .harnery/) is
|
|
26
|
+
// considered part of the sync set. Everything else stays local-only.
|
|
27
|
+
const SYNC_PATHS = ["identities/", "scratch/archived/", "councils/"];
|
|
28
|
+
function configPath() {
|
|
29
|
+
return path.join(os.homedir(), ".config", "harnery", "sync.json");
|
|
30
|
+
}
|
|
31
|
+
function loadConfig() {
|
|
32
|
+
const envRemote = process.env.HARNERY_SYNC_REMOTE;
|
|
33
|
+
const envPrefix = process.env.HARNERY_SYNC_PREFIX ?? "harnery";
|
|
34
|
+
if (envRemote)
|
|
35
|
+
return { remote: envRemote, prefix: envPrefix };
|
|
36
|
+
const p = configPath();
|
|
37
|
+
if (!existsSync(p))
|
|
38
|
+
return null;
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(readFileSync(p, "utf-8"));
|
|
41
|
+
if (typeof parsed.remote === "string" && typeof parsed.prefix === "string") {
|
|
42
|
+
return parsed;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
/* fall through */
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
function saveConfig(cfg) {
|
|
51
|
+
const p = configPath();
|
|
52
|
+
mkdirSync(path.dirname(p), { recursive: true });
|
|
53
|
+
writeFileSync(p, `${JSON.stringify(cfg, null, 2)}\n`, "utf-8");
|
|
54
|
+
}
|
|
55
|
+
function findHarneryDir() {
|
|
56
|
+
let dir = process.cwd();
|
|
57
|
+
for (let i = 0; i < 8; i++) {
|
|
58
|
+
if (existsSync(path.join(dir, ".harnery"))) {
|
|
59
|
+
return path.join(dir, ".harnery");
|
|
60
|
+
}
|
|
61
|
+
const parent = path.dirname(dir);
|
|
62
|
+
if (parent === dir)
|
|
63
|
+
break;
|
|
64
|
+
dir = parent;
|
|
65
|
+
}
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
function checkRclone(emit) {
|
|
69
|
+
const r = spawnSync("rclone", ["version"], { encoding: "utf-8" });
|
|
70
|
+
if (r.status !== 0) {
|
|
71
|
+
emit.error({
|
|
72
|
+
code: "rclone_missing",
|
|
73
|
+
message: "rclone is not on PATH",
|
|
74
|
+
hint: "Install via `curl https://rclone.org/install.sh | sudo bash` or " +
|
|
75
|
+
"https://rclone.org/downloads/",
|
|
76
|
+
});
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
}
|
|
81
|
+
function listRemotes() {
|
|
82
|
+
const r = spawnSync("rclone", ["listremotes"], { encoding: "utf-8" });
|
|
83
|
+
if (r.status !== 0)
|
|
84
|
+
return [];
|
|
85
|
+
return r.stdout
|
|
86
|
+
.split("\n")
|
|
87
|
+
.map((s) => s.trim().replace(/:$/, ""))
|
|
88
|
+
.filter(Boolean);
|
|
89
|
+
}
|
|
90
|
+
function ensureConfig(emit) {
|
|
91
|
+
const cfg = loadConfig();
|
|
92
|
+
if (cfg)
|
|
93
|
+
return cfg;
|
|
94
|
+
emit.error({
|
|
95
|
+
code: "not_initialized",
|
|
96
|
+
message: "no harn sync config",
|
|
97
|
+
hint: "Run `harn sync init` to pick an rclone remote and record it.",
|
|
98
|
+
});
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
function buildRcloneArgs(cfg, harneryDir, direction) {
|
|
102
|
+
const local = harneryDir;
|
|
103
|
+
const remote = `${cfg.remote}:${cfg.prefix}`;
|
|
104
|
+
return direction === "push" ? { local, remote } : { local, remote };
|
|
105
|
+
}
|
|
106
|
+
function syncIncludeFlags() {
|
|
107
|
+
const out = [];
|
|
108
|
+
for (const p of SYNC_PATHS) {
|
|
109
|
+
out.push("--include", `/${p}**`);
|
|
110
|
+
}
|
|
111
|
+
return out;
|
|
112
|
+
}
|
|
113
|
+
export function registerSyncCommand(program, emit) {
|
|
114
|
+
const sync = program
|
|
115
|
+
.command("sync")
|
|
116
|
+
.description("Cross-machine sync of curated .harnery/ subset (identities, archived " +
|
|
117
|
+
"scratchpads, council manifests) via rclone. Google Drive is the " +
|
|
118
|
+
"expected remote; any rclone backend works.");
|
|
119
|
+
sync
|
|
120
|
+
.command("init")
|
|
121
|
+
.description("Pick the rclone remote to sync against. Run `rclone config` first " +
|
|
122
|
+
"if you haven't set up a remote yet (harnery doesn't wrap the OAuth " +
|
|
123
|
+
"flow; rclone's own config wizard handles that).")
|
|
124
|
+
.option("--remote <name>", "Use this rclone remote (skips the picker)")
|
|
125
|
+
.option("--prefix <path>", "Subpath under the remote root (default: harnery)", "harnery")
|
|
126
|
+
.action((opts) => {
|
|
127
|
+
if (!checkRclone(emit)) {
|
|
128
|
+
emit.setExitCode(1);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
const remotes = listRemotes();
|
|
132
|
+
if (remotes.length === 0) {
|
|
133
|
+
emit.error({
|
|
134
|
+
code: "no_remotes",
|
|
135
|
+
message: "rclone has no remotes configured",
|
|
136
|
+
hint: "Run `rclone config` to add one (Google Drive: choose `drive`).",
|
|
137
|
+
});
|
|
138
|
+
emit.setExitCode(1);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
let remote = opts.remote;
|
|
142
|
+
if (!remote) {
|
|
143
|
+
if (remotes.length === 1) {
|
|
144
|
+
remote = remotes[0];
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
emit.error({
|
|
148
|
+
code: "remote_required",
|
|
149
|
+
message: `multiple rclone remotes; pass --remote <name>; available: ${remotes.join(", ")}`,
|
|
150
|
+
});
|
|
151
|
+
emit.setExitCode(1);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (!remotes.includes(remote)) {
|
|
156
|
+
emit.error({
|
|
157
|
+
code: "unknown_remote",
|
|
158
|
+
message: `remote "${remote}" not in rclone config (have: ${remotes.join(", ")})`,
|
|
159
|
+
});
|
|
160
|
+
emit.setExitCode(1);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
saveConfig({ remote, prefix: opts.prefix });
|
|
164
|
+
emit.text(`recorded: remote=${remote} prefix=${opts.prefix}`);
|
|
165
|
+
emit.text(`config: ${configPath()}`);
|
|
166
|
+
});
|
|
167
|
+
sync
|
|
168
|
+
.command("status")
|
|
169
|
+
.description("Diff local .harnery/ subset vs the remote (rclone check --one-way).")
|
|
170
|
+
.option("--dry-run", "Same as no-op for status; kept for symmetry with push/pull")
|
|
171
|
+
.option("--verbose", "Pass -v to rclone")
|
|
172
|
+
.action((opts) => {
|
|
173
|
+
if (!checkRclone(emit)) {
|
|
174
|
+
emit.setExitCode(1);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const cfg = ensureConfig(emit);
|
|
178
|
+
if (!cfg) {
|
|
179
|
+
emit.setExitCode(1);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const hDir = findHarneryDir();
|
|
183
|
+
if (!hDir) {
|
|
184
|
+
emit.error({ code: "no_harnery", message: "no .harnery/ found above cwd" });
|
|
185
|
+
emit.setExitCode(1);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
const { local, remote } = buildRcloneArgs(cfg, hDir, "push");
|
|
189
|
+
const args = ["check", local, remote, "--one-way", ...syncIncludeFlags()];
|
|
190
|
+
if (opts.verbose)
|
|
191
|
+
args.push("-v");
|
|
192
|
+
const r = spawnSync("rclone", args, { stdio: "inherit" });
|
|
193
|
+
emit.setExitCode(r.status ?? 1);
|
|
194
|
+
});
|
|
195
|
+
sync
|
|
196
|
+
.command("push")
|
|
197
|
+
.description("Push local .harnery/ subset to the remote (rclone copy).")
|
|
198
|
+
.option("--dry-run", "Pass --dry-run to rclone")
|
|
199
|
+
.option("--verbose", "Pass -v to rclone")
|
|
200
|
+
.action((opts) => {
|
|
201
|
+
if (!checkRclone(emit)) {
|
|
202
|
+
emit.setExitCode(1);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
const cfg = ensureConfig(emit);
|
|
206
|
+
if (!cfg) {
|
|
207
|
+
emit.setExitCode(1);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
const hDir = findHarneryDir();
|
|
211
|
+
if (!hDir) {
|
|
212
|
+
emit.error({ code: "no_harnery", message: "no .harnery/ found above cwd" });
|
|
213
|
+
emit.setExitCode(1);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const { local, remote } = buildRcloneArgs(cfg, hDir, "push");
|
|
217
|
+
const args = ["copy", local, remote, ...syncIncludeFlags()];
|
|
218
|
+
if (opts.dryRun)
|
|
219
|
+
args.push("--dry-run");
|
|
220
|
+
if (opts.verbose)
|
|
221
|
+
args.push("-v");
|
|
222
|
+
const r = spawnSync("rclone", args, { stdio: "inherit" });
|
|
223
|
+
emit.setExitCode(r.status ?? 1);
|
|
224
|
+
});
|
|
225
|
+
sync
|
|
226
|
+
.command("pull")
|
|
227
|
+
.description("Pull the remote subset down into local .harnery/ (rclone copy).")
|
|
228
|
+
.option("--dry-run", "Pass --dry-run to rclone")
|
|
229
|
+
.option("--verbose", "Pass -v to rclone")
|
|
230
|
+
.action((opts) => {
|
|
231
|
+
if (!checkRclone(emit)) {
|
|
232
|
+
emit.setExitCode(1);
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
const cfg = ensureConfig(emit);
|
|
236
|
+
if (!cfg) {
|
|
237
|
+
emit.setExitCode(1);
|
|
238
|
+
return;
|
|
239
|
+
}
|
|
240
|
+
const hDir = findHarneryDir();
|
|
241
|
+
if (!hDir) {
|
|
242
|
+
emit.error({ code: "no_harnery", message: "no .harnery/ found above cwd" });
|
|
243
|
+
emit.setExitCode(1);
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
const { local, remote } = buildRcloneArgs(cfg, hDir, "pull");
|
|
247
|
+
const args = ["copy", remote, local, ...syncIncludeFlags()];
|
|
248
|
+
if (opts.dryRun)
|
|
249
|
+
args.push("--dry-run");
|
|
250
|
+
if (opts.verbose)
|
|
251
|
+
args.push("-v");
|
|
252
|
+
const r = spawnSync("rclone", args, { stdio: "inherit" });
|
|
253
|
+
emit.setExitCode(r.status ?? 1);
|
|
254
|
+
});
|
|
255
|
+
sync
|
|
256
|
+
.command("list")
|
|
257
|
+
.description("List what's currently in the remote (rclone lsf).")
|
|
258
|
+
.option("--depth <n>", "Max recursion depth", "4")
|
|
259
|
+
.action((opts) => {
|
|
260
|
+
if (!checkRclone(emit)) {
|
|
261
|
+
emit.setExitCode(1);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const cfg = ensureConfig(emit);
|
|
265
|
+
if (!cfg) {
|
|
266
|
+
emit.setExitCode(1);
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const remote = `${cfg.remote}:${cfg.prefix}`;
|
|
270
|
+
const r = spawnSync("rclone", ["lsf", remote, "-R", "--max-depth", opts.depth], {
|
|
271
|
+
stdio: "inherit",
|
|
272
|
+
});
|
|
273
|
+
emit.setExitCode(r.status ?? 1);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { EmitContext } from "../commander.js";
|
|
3
|
+
export declare function registerTocCommand(program: Command, emit: EmitContext): void;
|
|
4
|
+
export declare function registerSectionCommand(program: Command, emit: EmitContext): void;
|
|
5
|
+
//# sourceMappingURL=toc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toc.d.ts","sourceRoot":"","sources":["../../src/commands/toc.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AA4CnD,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAqB5E;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CA0BhF"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { resolveBinName } from "../core/config.js";
|
|
4
|
+
export function registerTocCommand(program, emit) {
|
|
5
|
+
program
|
|
6
|
+
.command("toc <file>")
|
|
7
|
+
.description("Print the markdown header outline (level + text + line number).")
|
|
8
|
+
.option("--json", "Structured JSON envelope")
|
|
9
|
+
.option("-d, --depth <n>", "Maximum header depth (1-6)")
|
|
10
|
+
.option("--with-sizes", "Include line count per section")
|
|
11
|
+
.action(async (file, opts) => {
|
|
12
|
+
try {
|
|
13
|
+
const result = await runToc(file, opts);
|
|
14
|
+
if (opts.json) {
|
|
15
|
+
emit.config({ format: "json" });
|
|
16
|
+
emit.data(result);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
emit.text(`${renderToc(result)}\n`);
|
|
20
|
+
}
|
|
21
|
+
catch (err) {
|
|
22
|
+
emit.error({ code: "toc_failed", message: err.message });
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function registerSectionCommand(program, emit) {
|
|
28
|
+
program
|
|
29
|
+
.command("section <file> <header...>")
|
|
30
|
+
.description("Extract one section from a markdown file by header substring (case-insensitive by default). " +
|
|
31
|
+
"Joins multi-word args into one query string.")
|
|
32
|
+
.option("--json", "Structured JSON envelope: {file, matched_header, line_start, line_end, content}")
|
|
33
|
+
.option("--case-sensitive", "Case-sensitive header match")
|
|
34
|
+
.action(async (file, header, opts) => {
|
|
35
|
+
try {
|
|
36
|
+
const result = await runSection(file, header.join(" "), opts);
|
|
37
|
+
if (opts.json) {
|
|
38
|
+
emit.config({ format: "json" });
|
|
39
|
+
emit.data(result);
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
emit.text(`${result.content}\n`);
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
emit.error({ code: "section_failed", message: err.message });
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
async function runToc(file, opts) {
|
|
51
|
+
const absPath = resolve(file);
|
|
52
|
+
if (!existsSync(absPath))
|
|
53
|
+
throw new Error(`no such file: ${file}`);
|
|
54
|
+
const content = readFileSync(absPath, "utf8");
|
|
55
|
+
const lines = content.split("\n");
|
|
56
|
+
const maxDepth = opts.depth ? Number.parseInt(opts.depth, 10) : 6;
|
|
57
|
+
if (!Number.isFinite(maxDepth) || maxDepth < 1 || maxDepth > 6) {
|
|
58
|
+
throw new Error(`--depth must be 1-6 (got ${opts.depth})`);
|
|
59
|
+
}
|
|
60
|
+
const headers = [];
|
|
61
|
+
let inFence = false;
|
|
62
|
+
let fenceMarker = "";
|
|
63
|
+
for (let i = 0; i < lines.length; i++) {
|
|
64
|
+
const line = lines[i];
|
|
65
|
+
const fenceMatch = line.match(/^(\s*)(`{3,}|~{3,})/);
|
|
66
|
+
if (fenceMatch) {
|
|
67
|
+
const marker = fenceMatch[2];
|
|
68
|
+
if (!inFence) {
|
|
69
|
+
inFence = true;
|
|
70
|
+
fenceMarker = marker[0];
|
|
71
|
+
}
|
|
72
|
+
else if (marker[0] === fenceMarker) {
|
|
73
|
+
inFence = false;
|
|
74
|
+
}
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (inFence)
|
|
78
|
+
continue;
|
|
79
|
+
const headerMatch = line.match(/^(#{1,6})\s+(.+?)\s*#*\s*$/);
|
|
80
|
+
if (headerMatch) {
|
|
81
|
+
const level = headerMatch[1].length;
|
|
82
|
+
if (level > maxDepth)
|
|
83
|
+
continue;
|
|
84
|
+
headers.push({
|
|
85
|
+
level,
|
|
86
|
+
text: headerMatch[2],
|
|
87
|
+
line: i + 1,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (opts.withSizes) {
|
|
92
|
+
for (let i = 0; i < headers.length; i++) {
|
|
93
|
+
const nextLine = i + 1 < headers.length ? headers[i + 1].line : lines.length + 1;
|
|
94
|
+
headers[i].size_lines = nextLine - headers[i].line;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
file,
|
|
99
|
+
total_lines: lines.length,
|
|
100
|
+
headers,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function renderToc(r) {
|
|
104
|
+
const lines = [];
|
|
105
|
+
lines.push(`toc · ${r.file} (${r.headers.length} header${r.headers.length === 1 ? "" : "s"}, ${r.total_lines} lines)`);
|
|
106
|
+
if (r.headers.length === 0) {
|
|
107
|
+
lines.push("(no markdown headers found)");
|
|
108
|
+
return lines.join("\n");
|
|
109
|
+
}
|
|
110
|
+
lines.push("");
|
|
111
|
+
for (const h of r.headers) {
|
|
112
|
+
const indent = " ".repeat(h.level - 1);
|
|
113
|
+
const lineMark = `L${h.line}`.padEnd(6);
|
|
114
|
+
const size = h.size_lines !== undefined ? ` (${h.size_lines}L)` : "";
|
|
115
|
+
lines.push(` ${lineMark}${indent}${"#".repeat(h.level)} ${h.text}${size}`);
|
|
116
|
+
}
|
|
117
|
+
return lines.join("\n");
|
|
118
|
+
}
|
|
119
|
+
async function runSection(file, query, opts) {
|
|
120
|
+
if (!query.trim())
|
|
121
|
+
throw new Error("header query required");
|
|
122
|
+
const tocResult = await runToc(file, {});
|
|
123
|
+
const absPath = resolve(file);
|
|
124
|
+
const lines = readFileSync(absPath, "utf8").split("\n");
|
|
125
|
+
const matches = tocResult.headers.filter((h) => opts.caseSensitive
|
|
126
|
+
? h.text.includes(query)
|
|
127
|
+
: h.text.toLowerCase().includes(query.toLowerCase()));
|
|
128
|
+
if (matches.length === 0) {
|
|
129
|
+
throw new Error(`no header matching "${query}". Run \`${resolveBinName()} toc ${file}\` to list available headers.`);
|
|
130
|
+
}
|
|
131
|
+
if (matches.length > 1) {
|
|
132
|
+
const list = matches.map((h) => ` L${h.line} ${"#".repeat(h.level)} ${h.text}`).join("\n");
|
|
133
|
+
throw new Error(`multiple headers match "${query}":\n${list}\n\nRefine the query or use exact text.`);
|
|
134
|
+
}
|
|
135
|
+
const matched = matches[0];
|
|
136
|
+
const idx = tocResult.headers.findIndex((h) => h.line === matched.line);
|
|
137
|
+
let endLine = lines.length;
|
|
138
|
+
for (let i = idx + 1; i < tocResult.headers.length; i++) {
|
|
139
|
+
if (tocResult.headers[i].level <= matched.level) {
|
|
140
|
+
endLine = tocResult.headers[i].line - 1;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const content = lines.slice(matched.line - 1, endLine).join("\n");
|
|
145
|
+
return {
|
|
146
|
+
file,
|
|
147
|
+
matched_header: matched.text,
|
|
148
|
+
matched_level: matched.level,
|
|
149
|
+
line_start: matched.line,
|
|
150
|
+
line_end: endLine,
|
|
151
|
+
content,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokens.d.ts","sourceRoot":"","sources":["../../src/commands/tokens.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAwBnD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,GAAG,IAAI,CAyC/E"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { countTokens } from "gpt-tokenizer/model/gpt-4o";
|
|
3
|
+
export function registerTokensCommand(program, emit) {
|
|
4
|
+
program
|
|
5
|
+
.command("tokens")
|
|
6
|
+
.description("Count tokens in text/markdown files (offline, uses o200k_base as Claude proxy)")
|
|
7
|
+
.argument("<files...>", "One or more file paths (globs are shell-expanded)")
|
|
8
|
+
.option("--limit <n>", "Flag files exceeding N tokens; exit non-zero if any exceed", (v) => Number.parseInt(v, 10))
|
|
9
|
+
.option("--format <type>", "Output format: table, json, plain", "table")
|
|
10
|
+
.action((files, opts) => {
|
|
11
|
+
if (opts.format === "json")
|
|
12
|
+
emit.config({ format: "json" });
|
|
13
|
+
const results = files.map(countFile);
|
|
14
|
+
const over = opts.limit !== undefined
|
|
15
|
+
? results.filter((r) => !r.error && r.tokens > opts.limit)
|
|
16
|
+
: [];
|
|
17
|
+
const enriched = results.map((r) => ({
|
|
18
|
+
path: r.path,
|
|
19
|
+
chars: r.chars,
|
|
20
|
+
tokens: r.tokens,
|
|
21
|
+
error: r.error,
|
|
22
|
+
over_limit: opts.limit !== undefined && !r.error ? r.tokens > opts.limit : null,
|
|
23
|
+
pct_of_limit: opts.limit !== undefined && !r.error
|
|
24
|
+
? Math.round((r.tokens / opts.limit) * 100)
|
|
25
|
+
: null,
|
|
26
|
+
}));
|
|
27
|
+
emit.data({
|
|
28
|
+
ok: true,
|
|
29
|
+
tokenizer: "o200k_base",
|
|
30
|
+
limit: opts.limit ?? null,
|
|
31
|
+
count: enriched.length,
|
|
32
|
+
over_count: over.length,
|
|
33
|
+
results: enriched,
|
|
34
|
+
});
|
|
35
|
+
if (over.length > 0)
|
|
36
|
+
emit.setExitCode(1);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function countFile(path) {
|
|
40
|
+
try {
|
|
41
|
+
const content = readFileSync(path, "utf8");
|
|
42
|
+
return { path, chars: content.length, tokens: countTokens(content), error: null };
|
|
43
|
+
}
|
|
44
|
+
catch (err) {
|
|
45
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
46
|
+
return { path, chars: 0, tokens: 0, error: msg };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Command } from "commander";
|
|
2
|
+
import type { EmitContext, HarneryProgramContext } from "../commander.js";
|
|
3
|
+
export declare function registerTunnelCommand(program: Command, emitParam: EmitContext, contextParam?: HarneryProgramContext): void;
|
|
4
|
+
//# sourceMappingURL=tunnel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tunnel.d.ts","sourceRoot":"","sources":["../../src/commands/tunnel.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AA4jB1E,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,WAAW,EACtB,YAAY,CAAC,EAAE,qBAAqB,GACnC,IAAI,CAuDN"}
|