harnery 0.0.1 → 0.2.1
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 +509 -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 +39 -0
- package/dist/lib/readability/client.d.ts.map +1 -0
- package/dist/lib/readability/client.js +121 -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 +583 -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 +169 -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,301 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname } from "node:path";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Shared cookie-store library.
|
|
6
|
+
*
|
|
7
|
+
* Design:
|
|
8
|
+
* - CDP-native cookie format (matches Playwright/agent-browser output).
|
|
9
|
+
* - Caller chooses the store path on construction; the harn defaults are
|
|
10
|
+
* `~/.cache/harnery/cookies.json`. Consumers can point at any path.
|
|
11
|
+
* - Pure synchronous I/O; the store is small (<1MB typical) so async
|
|
12
|
+
* buys nothing and complicates the merge-on-write path.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** CDP-native cookie. `expires === -1` means session cookie / no expiry. */
|
|
16
|
+
export interface Cookie {
|
|
17
|
+
name: string;
|
|
18
|
+
value: string;
|
|
19
|
+
domain: string;
|
|
20
|
+
path: string;
|
|
21
|
+
expires: number;
|
|
22
|
+
size?: number;
|
|
23
|
+
httpOnly: boolean;
|
|
24
|
+
secure: boolean;
|
|
25
|
+
session?: boolean;
|
|
26
|
+
sameSite?: string;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface OriginEntry {
|
|
30
|
+
origin: string;
|
|
31
|
+
localStorage: { name: string; value: string }[];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface CookieStore {
|
|
35
|
+
cookies: Cookie[];
|
|
36
|
+
origins: OriginEntry[];
|
|
37
|
+
exportedAt?: string;
|
|
38
|
+
exportedFrom?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface CookieJarOptions {
|
|
42
|
+
/** Absolute path to the JSON store. Caller must provide. */
|
|
43
|
+
path: string;
|
|
44
|
+
/** `exportedFrom` tag stamped on every save. Defaults to `"bp-cookies"`. */
|
|
45
|
+
source?: string;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface InfoResult {
|
|
49
|
+
path: string;
|
|
50
|
+
exists: boolean;
|
|
51
|
+
bytes: number;
|
|
52
|
+
active: number;
|
|
53
|
+
expired: number;
|
|
54
|
+
total: number;
|
|
55
|
+
domains: string[];
|
|
56
|
+
origins: number;
|
|
57
|
+
exportedAt?: string;
|
|
58
|
+
exportedFrom?: string;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export class CookieJar {
|
|
62
|
+
readonly path: string;
|
|
63
|
+
private readonly source: string;
|
|
64
|
+
|
|
65
|
+
constructor(opts: CookieJarOptions) {
|
|
66
|
+
this.path = opts.path;
|
|
67
|
+
this.source = opts.source ?? "bp-cookies";
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
exists(): boolean {
|
|
71
|
+
return existsSync(this.path);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
load(): CookieStore {
|
|
75
|
+
if (!existsSync(this.path)) {
|
|
76
|
+
return { cookies: [], origins: [] };
|
|
77
|
+
}
|
|
78
|
+
const raw = readFileSync(this.path, "utf-8");
|
|
79
|
+
const parsed = JSON.parse(raw);
|
|
80
|
+
return {
|
|
81
|
+
cookies: parsed.cookies ?? [],
|
|
82
|
+
origins: parsed.origins ?? [],
|
|
83
|
+
exportedAt: parsed.exportedAt,
|
|
84
|
+
exportedFrom: parsed.exportedFrom,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Persist a store, stamping `exportedAt` (now) and `exportedFrom`
|
|
90
|
+
* (constructor-provided source). Creates the parent directory if needed.
|
|
91
|
+
*/
|
|
92
|
+
save(store: CookieStore): void {
|
|
93
|
+
const stamped: CookieStore = {
|
|
94
|
+
...store,
|
|
95
|
+
exportedAt: new Date().toISOString(),
|
|
96
|
+
exportedFrom: this.source,
|
|
97
|
+
};
|
|
98
|
+
mkdirSync(dirname(this.path), { recursive: true });
|
|
99
|
+
writeFileSync(this.path, `${JSON.stringify(stamped, null, 2)}\n`);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Read + filter helper. Drops expired cookies. Optional domain filter
|
|
104
|
+
* uses the same `domainMatches` logic Playwright/CDP do (leading dot
|
|
105
|
+
* means subdomain match).
|
|
106
|
+
*/
|
|
107
|
+
list(filter: { domain?: string } = {}): Cookie[] {
|
|
108
|
+
const store = this.load();
|
|
109
|
+
let cookies = store.cookies.filter((c) => !isExpired(c));
|
|
110
|
+
if (filter.domain) {
|
|
111
|
+
cookies = cookies.filter((c) => domainMatches(c.domain, filter.domain!));
|
|
112
|
+
}
|
|
113
|
+
return cookies;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Set a single cookie, merging into the store on `(name, domain, path)`.
|
|
118
|
+
* Returns the saved store.
|
|
119
|
+
*/
|
|
120
|
+
set(cookie: Cookie): CookieStore {
|
|
121
|
+
const store = this.load();
|
|
122
|
+
const merged = mergeCookies(store, [cookie]);
|
|
123
|
+
this.save(merged);
|
|
124
|
+
return merged;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Clear cookies. Pass `{ all: true }` to wipe everything (including
|
|
129
|
+
* origins/localStorage), or `{ domain: "..." }` to drop matching cookies
|
|
130
|
+
* + origins. Returns counts before/after.
|
|
131
|
+
*/
|
|
132
|
+
clear(opts: { domain?: string; all?: boolean }): { before: number; after: number } {
|
|
133
|
+
if (!opts.domain && !opts.all) {
|
|
134
|
+
throw new Error("Specify { domain } or { all: true }");
|
|
135
|
+
}
|
|
136
|
+
const store = this.load();
|
|
137
|
+
const before = store.cookies.length;
|
|
138
|
+
if (opts.all) {
|
|
139
|
+
store.cookies = [];
|
|
140
|
+
store.origins = [];
|
|
141
|
+
} else if (opts.domain) {
|
|
142
|
+
const dom = opts.domain;
|
|
143
|
+
store.cookies = store.cookies.filter((c) => !domainMatches(c.domain, dom));
|
|
144
|
+
store.origins = store.origins.filter((o) => {
|
|
145
|
+
try {
|
|
146
|
+
return !domainMatches(dom, new URL(o.origin).hostname);
|
|
147
|
+
} catch {
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
this.save(store);
|
|
153
|
+
return { before, after: store.cookies.length };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Build a `Cookie:` header value for a URL. Only cookies that match
|
|
158
|
+
* domain + path + secure rules are included. Returns `""` when nothing
|
|
159
|
+
* matches.
|
|
160
|
+
*/
|
|
161
|
+
header(url: string): string {
|
|
162
|
+
const store = this.load();
|
|
163
|
+
const cookies = matchingCookies(store, url);
|
|
164
|
+
return cookies.map((c) => `${c.name}=${c.value}`).join("; ");
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Import cookies from a JSON file. Accepts three shapes:
|
|
169
|
+
* - `{ cookies: [...] }` (CDP/agent-browser native)
|
|
170
|
+
* - `{ data: { cookies: [...] } }` (agent-browser wrapper envelope)
|
|
171
|
+
* - `[...]` (raw array)
|
|
172
|
+
*
|
|
173
|
+
* `replace: true` overwrites the store; default merges on `(name, domain, path)`.
|
|
174
|
+
* Returns the count imported.
|
|
175
|
+
*/
|
|
176
|
+
import(filePath: string, opts: { replace?: boolean } = {}): { count: number } {
|
|
177
|
+
if (!existsSync(filePath)) {
|
|
178
|
+
throw new Error(`File not found: ${filePath}`);
|
|
179
|
+
}
|
|
180
|
+
const raw = readFileSync(filePath, "utf-8");
|
|
181
|
+
const incoming = JSON.parse(raw);
|
|
182
|
+
const cookies: Cookie[] = incoming.cookies ?? incoming.data?.cookies ?? incoming;
|
|
183
|
+
if (!Array.isArray(cookies)) {
|
|
184
|
+
throw new Error(`Expected a cookies array in ${filePath}`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
if (opts.replace) {
|
|
188
|
+
const store: CookieStore = { cookies, origins: incoming.origins ?? [] };
|
|
189
|
+
this.save(store);
|
|
190
|
+
} else {
|
|
191
|
+
const store = this.load();
|
|
192
|
+
const merged = mergeCookies(store, cookies);
|
|
193
|
+
if (incoming.origins) {
|
|
194
|
+
const seen = new Set(store.origins.map((o) => o.origin));
|
|
195
|
+
for (const o of incoming.origins) {
|
|
196
|
+
if (!seen.has(o.origin)) merged.origins.push(o);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
this.save(merged);
|
|
200
|
+
}
|
|
201
|
+
return { count: cookies.length };
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Write the entire store to a file (for sharing with another tool). */
|
|
205
|
+
export(filePath: string): { count: number } {
|
|
206
|
+
const store = this.load();
|
|
207
|
+
const stamped: CookieStore = {
|
|
208
|
+
...store,
|
|
209
|
+
exportedAt: new Date().toISOString(),
|
|
210
|
+
exportedFrom: `${this.source}-export`,
|
|
211
|
+
};
|
|
212
|
+
mkdirSync(dirname(filePath), { recursive: true });
|
|
213
|
+
writeFileSync(filePath, `${JSON.stringify(stamped, null, 2)}\n`);
|
|
214
|
+
return { count: stamped.cookies.length };
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Stats for the `info` command. Stable shape so callers can JSON it. */
|
|
218
|
+
info(): InfoResult {
|
|
219
|
+
if (!existsSync(this.path)) {
|
|
220
|
+
return {
|
|
221
|
+
path: this.path,
|
|
222
|
+
exists: false,
|
|
223
|
+
bytes: 0,
|
|
224
|
+
active: 0,
|
|
225
|
+
expired: 0,
|
|
226
|
+
total: 0,
|
|
227
|
+
domains: [],
|
|
228
|
+
origins: 0,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const store = this.load();
|
|
232
|
+
const expired = store.cookies.filter(isExpired).length;
|
|
233
|
+
const active = store.cookies.length - expired;
|
|
234
|
+
const domainSet = new Set(
|
|
235
|
+
store.cookies.map((c) => (c.domain.startsWith(".") ? c.domain.slice(1) : c.domain)),
|
|
236
|
+
);
|
|
237
|
+
return {
|
|
238
|
+
path: this.path,
|
|
239
|
+
exists: true,
|
|
240
|
+
bytes: statSync(this.path).size,
|
|
241
|
+
active,
|
|
242
|
+
expired,
|
|
243
|
+
total: store.cookies.length,
|
|
244
|
+
domains: [...domainSet].sort(),
|
|
245
|
+
origins: store.origins.length,
|
|
246
|
+
exportedAt: store.exportedAt,
|
|
247
|
+
exportedFrom: store.exportedFrom,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
// ---------------------------------------------------------------------------
|
|
253
|
+
// Standalone helpers (also exported so callers without a CookieJar can use them)
|
|
254
|
+
// ---------------------------------------------------------------------------
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* Merge cookies into a store. Newer entries with the same
|
|
258
|
+
* `(name, domain, path)` triple replace older ones. Pure; caller must save.
|
|
259
|
+
*/
|
|
260
|
+
export function mergeCookies(store: CookieStore, incoming: Cookie[]): CookieStore {
|
|
261
|
+
const key = (c: Cookie) => `${c.name}|${c.domain}|${c.path}`;
|
|
262
|
+
const map = new Map<string, Cookie>();
|
|
263
|
+
for (const c of store.cookies) map.set(key(c), c);
|
|
264
|
+
for (const c of incoming) map.set(key(c), c);
|
|
265
|
+
return { ...store, cookies: Array.from(map.values()) };
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** RFC 6265 domain match. Leading dot in cookie domain means subdomain match. */
|
|
269
|
+
export function domainMatches(cookieDomain: string, hostname: string): boolean {
|
|
270
|
+
const cd = cookieDomain.startsWith(".") ? cookieDomain.slice(1) : cookieDomain;
|
|
271
|
+
if (hostname === cd) return true;
|
|
272
|
+
if (hostname.endsWith(`.${cd}`)) return true;
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** RFC 6265 path match. */
|
|
277
|
+
export function pathMatches(cookiePath: string, urlPath: string): boolean {
|
|
278
|
+
if (urlPath === cookiePath) return true;
|
|
279
|
+
if (urlPath.startsWith(cookiePath) && cookiePath.endsWith("/")) return true;
|
|
280
|
+
if (urlPath.startsWith(`${cookiePath}/`)) return true;
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** `expires <= 0` is a session cookie / no expiry; otherwise compare to now. */
|
|
285
|
+
export function isExpired(cookie: Cookie): boolean {
|
|
286
|
+
if (cookie.expires <= 0) return false;
|
|
287
|
+
return cookie.expires < Date.now() / 1000;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Cookies that should be sent with a request to `url`. */
|
|
291
|
+
export function matchingCookies(store: CookieStore, url: string): Cookie[] {
|
|
292
|
+
const parsed = new URL(url);
|
|
293
|
+
const isSecure = parsed.protocol === "https:";
|
|
294
|
+
return store.cookies.filter((c) => {
|
|
295
|
+
if (isExpired(c)) return false;
|
|
296
|
+
if (!domainMatches(c.domain, parsed.hostname)) return false;
|
|
297
|
+
if (!pathMatches(c.path, parsed.pathname)) return false;
|
|
298
|
+
if (c.secure && !isSecure) return false;
|
|
299
|
+
return true;
|
|
300
|
+
});
|
|
301
|
+
}
|