@cybedefend/vibedefend 1.8.2 → 1.9.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/README.md +185 -17
- package/dist/auth/auth-store.js +16 -0
- package/dist/auth/auth-store.js.map +1 -1
- package/dist/clients/antigravity.js +30 -6
- package/dist/clients/antigravity.js.map +1 -1
- package/dist/clients/claude-code.js +209 -17
- package/dist/clients/claude-code.js.map +1 -1
- package/dist/clients/codex.js +171 -11
- package/dist/clients/codex.js.map +1 -1
- package/dist/clients/cursor.js +149 -9
- package/dist/clients/cursor.js.map +1 -1
- package/dist/clients/dependency-check-wiring.js +24 -0
- package/dist/clients/dependency-check-wiring.js.map +1 -0
- package/dist/clients/opencode-plugin.js +905 -0
- package/dist/clients/opencode-plugin.js.map +1 -0
- package/dist/clients/opencode.js +653 -0
- package/dist/clients/opencode.js.map +1 -0
- package/dist/clients/registry.js +2 -0
- package/dist/clients/registry.js.map +1 -1
- package/dist/clients/vscode.js +106 -12
- package/dist/clients/vscode.js.map +1 -1
- package/dist/clients/windsurf.js +9 -1
- package/dist/clients/windsurf.js.map +1 -1
- package/dist/commands/mcp/index.js +11 -0
- package/dist/commands/mcp/index.js.map +1 -1
- package/dist/config.js +4 -1
- package/dist/config.js.map +1 -1
- package/dist/diagnostics.js +22 -3
- package/dist/diagnostics.js.map +1 -1
- package/dist/doctor.js +26 -1
- package/dist/doctor.js.map +1 -1
- package/dist/guards-evaluator/command-analysis.js +347 -86
- package/dist/guards-evaluator/command-analysis.js.map +1 -1
- package/dist/guards-evaluator/command-view.js +116 -16
- package/dist/guards-evaluator/command-view.js.map +1 -1
- package/dist/guards-evaluator/evaluate.js +185 -41
- package/dist/guards-evaluator/evaluate.js.map +1 -1
- package/dist/guards-evaluator/file-reads.js +202 -0
- package/dist/guards-evaluator/file-reads.js.map +1 -0
- package/dist/guards-evaluator/index.js +1 -1
- package/dist/guards-evaluator/index.js.map +1 -1
- package/dist/guards-evaluator/inline-danger.js +299 -0
- package/dist/guards-evaluator/inline-danger.js.map +1 -0
- package/dist/guards-evaluator/normalize.js +1186 -55
- package/dist/guards-evaluator/normalize.js.map +1 -1
- package/dist/guards-evaluator/regex.js +91 -4
- package/dist/guards-evaluator/regex.js.map +1 -1
- package/dist/guards-evaluator/shell-files.js +587 -0
- package/dist/guards-evaluator/shell-files.js.map +1 -0
- package/dist/guards-evaluator/triage.js +32 -2
- package/dist/guards-evaluator/triage.js.map +1 -1
- package/dist/hook-runner.js +25601 -5423
- package/dist/hooks/install.js +8 -3
- package/dist/hooks/install.js.map +1 -1
- package/dist/hooks/runtime/antigravity-session.js +109 -50
- package/dist/hooks/runtime/antigravity-session.js.map +1 -1
- package/dist/hooks/runtime/apply-patch.js +92 -0
- package/dist/hooks/runtime/apply-patch.js.map +1 -0
- package/dist/hooks/runtime/caller-gate.js +27 -0
- package/dist/hooks/runtime/caller-gate.js.map +1 -0
- package/dist/hooks/runtime/code-mode.js +259 -0
- package/dist/hooks/runtime/code-mode.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/api.js +179 -0
- package/dist/hooks/runtime/dependency-check/api.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/capabilities.js +99 -0
- package/dist/hooks/runtime/dependency-check/capabilities.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/checked-packages.js +48 -0
- package/dist/hooks/runtime/dependency-check/checked-packages.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/commands/cwd.js +154 -0
- package/dist/hooks/runtime/dependency-check/commands/cwd.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/commands/env.js +99 -0
- package/dist/hooks/runtime/dependency-check/commands/env.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/commands/flags.js +164 -0
- package/dist/hooks/runtime/dependency-check/commands/flags.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/commands/managers.js +418 -0
- package/dist/hooks/runtime/dependency-check/commands/managers.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/commands/peel.js +111 -0
- package/dist/hooks/runtime/dependency-check/commands/peel.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/commands/shell.js +217 -0
- package/dist/hooks/runtime/dependency-check/commands/shell.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/commands/types.js +4 -0
- package/dist/hooks/runtime/dependency-check/commands/types.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/commands.js +34 -0
- package/dist/hooks/runtime/dependency-check/commands.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/deadlines.js +69 -0
- package/dist/hooks/runtime/dependency-check/deadlines.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/dispatch.js +344 -0
- package/dist/hooks/runtime/dependency-check/dispatch.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/entering.js +63 -0
- package/dist/hooks/runtime/dependency-check/entering.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/exec-cache.js +36 -0
- package/dist/hooks/runtime/dependency-check/exec-cache.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/git-blob.js +116 -0
- package/dist/hooks/runtime/dependency-check/git-blob.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/hook.js +418 -0
- package/dist/hooks/runtime/dependency-check/hook.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/local-store.js +74 -0
- package/dist/hooks/runtime/dependency-check/local-store.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfile-walk.js +89 -0
- package/dist/hooks/runtime/dependency-check/lockfile-walk.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/bun.js +153 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/bun.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/by-name.js +46 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/by-name.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/cargo.js +91 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/cargo.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/composer.js +98 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/composer.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/gemfile.js +88 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/gemfile.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/go-mod.js +154 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/go-mod.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/gradle-lockfile.js +27 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/gradle-lockfile.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/graph.js +131 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/graph.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/npm.js +107 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/npm.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/nuget-packages-lock.js +60 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/nuget-packages-lock.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/pins.js +105 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/pins.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/pip-report.js +34 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/pip-report.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/pnpm.js +109 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/pnpm.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/poetry.js +105 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/poetry.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/uv.js +181 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/uv.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/yaml.js +319 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/yaml.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/yarn-berry.js +71 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/yarn-berry.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/yarn1.js +144 -0
- package/dist/hooks/runtime/dependency-check/lockfiles/yarn1.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests/apply.js +110 -0
- package/dist/hooks/runtime/dependency-check/manifests/apply.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests/diff.js +127 -0
- package/dist/hooks/runtime/dependency-check/manifests/diff.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests/edit.js +259 -0
- package/dist/hooks/runtime/dependency-check/manifests/edit.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests/json.js +109 -0
- package/dist/hooks/runtime/dependency-check/manifests/json.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests/kind.js +40 -0
- package/dist/hooks/runtime/dependency-check/manifests/kind.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests/patch.js +179 -0
- package/dist/hooks/runtime/dependency-check/manifests/patch.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests/text.js +665 -0
- package/dist/hooks/runtime/dependency-check/manifests/text.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests/toml.js +350 -0
- package/dist/hooks/runtime/dependency-check/manifests/toml.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/manifests.js +14 -0
- package/dist/hooks/runtime/dependency-check/manifests.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/messages.js +270 -0
- package/dist/hooks/runtime/dependency-check/messages.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/net-baseline.js +157 -0
- package/dist/hooks/runtime/dependency-check/net-baseline.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/net-state.js +70 -0
- package/dist/hooks/runtime/dependency-check/net-state.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/pending-forces.js +54 -0
- package/dist/hooks/runtime/dependency-check/pending-forces.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/post-tool-use.js +108 -0
- package/dist/hooks/runtime/dependency-check/post-tool-use.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/ranges.js +369 -0
- package/dist/hooks/runtime/dependency-check/ranges.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/requirement-files.js +144 -0
- package/dist/hooks/runtime/dependency-check/requirement-files.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/bun.js +38 -0
- package/dist/hooks/runtime/dependency-check/resolvers/bun.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/bundler.js +218 -0
- package/dist/hooks/runtime/dependency-check/resolvers/bundler.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/cargo.js +303 -0
- package/dist/hooks/runtime/dependency-check/resolvers/cargo.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/composer.js +250 -0
- package/dist/hooks/runtime/dependency-check/resolvers/composer.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/config-files.js +27 -0
- package/dist/hooks/runtime/dependency-check/resolvers/config-files.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/direct-only-registry.js +409 -0
- package/dist/hooks/runtime/dependency-check/resolvers/direct-only-registry.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/direct-only.js +290 -0
- package/dist/hooks/runtime/dependency-check/resolvers/direct-only.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/gem.js +89 -0
- package/dist/hooks/runtime/dependency-check/resolvers/gem.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/go.js +313 -0
- package/dist/hooks/runtime/dependency-check/resolvers/go.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/npm.js +81 -0
- package/dist/hooks/runtime/dependency-check/resolvers/npm.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/pip.js +229 -0
- package/dist/hooks/runtime/dependency-check/resolvers/pip.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/pipx.js +8 -0
- package/dist/hooks/runtime/dependency-check/resolvers/pipx.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/pnpm.js +68 -0
- package/dist/hooks/runtime/dependency-check/resolvers/pnpm.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/poetry.js +70 -0
- package/dist/hooks/runtime/dependency-check/resolvers/poetry.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/project.js +208 -0
- package/dist/hooks/runtime/dependency-check/resolvers/project.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/python-index.js +270 -0
- package/dist/hooks/runtime/dependency-check/resolvers/python-index.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/python.js +229 -0
- package/dist/hooks/runtime/dependency-check/resolvers/python.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/registry.js +221 -0
- package/dist/hooks/runtime/dependency-check/resolvers/registry.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/shared.js +440 -0
- package/dist/hooks/runtime/dependency-check/resolvers/shared.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/tree.js +131 -0
- package/dist/hooks/runtime/dependency-check/resolvers/tree.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/uv.js +433 -0
- package/dist/hooks/runtime/dependency-check/resolvers/uv.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/xml-lite.js +132 -0
- package/dist/hooks/runtime/dependency-check/resolvers/xml-lite.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/resolvers/yarn-berry.js +106 -0
- package/dist/hooks/runtime/dependency-check/resolvers/yarn-berry.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/sandbox.js +328 -0
- package/dist/hooks/runtime/dependency-check/sandbox.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/specs.js +171 -0
- package/dist/hooks/runtime/dependency-check/specs.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/static-view.js +90 -0
- package/dist/hooks/runtime/dependency-check/static-view.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/stop-net.js +278 -0
- package/dist/hooks/runtime/dependency-check/stop-net.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/stop-wiring.js +94 -0
- package/dist/hooks/runtime/dependency-check/stop-wiring.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/tool-call.js +130 -0
- package/dist/hooks/runtime/dependency-check/tool-call.js.map +1 -0
- package/dist/hooks/runtime/dependency-check/types.js +96 -0
- package/dist/hooks/runtime/dependency-check/types.js.map +1 -0
- package/dist/hooks/runtime/emit.js +240 -52
- package/dist/hooks/runtime/emit.js.map +1 -1
- package/dist/hooks/runtime/exit-deadlock-guard.js +24 -8
- package/dist/hooks/runtime/exit-deadlock-guard.js.map +1 -1
- package/dist/hooks/runtime/fetch-rules.js +78 -29
- package/dist/hooks/runtime/fetch-rules.js.map +1 -1
- package/dist/hooks/runtime/grep-include.js +228 -0
- package/dist/hooks/runtime/grep-include.js.map +1 -0
- package/dist/hooks/runtime/pre-compact.js +1 -1
- package/dist/hooks/runtime/pre-compact.js.map +1 -1
- package/dist/hooks/runtime/pre-invocation.js +3 -3
- package/dist/hooks/runtime/pre-invocation.js.map +1 -1
- package/dist/hooks/runtime/repo-registry.js +72 -0
- package/dist/hooks/runtime/repo-registry.js.map +1 -0
- package/dist/hooks/runtime/repo-scope.js +75 -0
- package/dist/hooks/runtime/repo-scope.js.map +1 -0
- package/dist/hooks/runtime/resolve.js +11 -2
- package/dist/hooks/runtime/resolve.js.map +1 -1
- package/dist/hooks/runtime/runner-args.js +17 -2
- package/dist/hooks/runtime/runner-args.js.map +1 -1
- package/dist/hooks/runtime/script-resolve.js +21 -5
- package/dist/hooks/runtime/script-resolve.js.map +1 -1
- package/dist/hooks/runtime/session-activation.js +71 -18
- package/dist/hooks/runtime/session-activation.js.map +1 -1
- package/dist/hooks/runtime/session-review.js +184 -88
- package/dist/hooks/runtime/session-review.js.map +1 -1
- package/dist/hooks/runtime/session-start.js +68 -13
- package/dist/hooks/runtime/session-start.js.map +1 -1
- package/dist/hooks/runtime/session-writes.js +11 -5
- package/dist/hooks/runtime/session-writes.js.map +1 -1
- package/dist/hooks/runtime/shell-writes.js +7 -88
- package/dist/hooks/runtime/shell-writes.js.map +1 -1
- package/dist/hooks/runtime/sniff.js +227 -2
- package/dist/hooks/runtime/sniff.js.map +1 -1
- package/dist/hooks/runtime/target-resolve.js +32 -17
- package/dist/hooks/runtime/target-resolve.js.map +1 -1
- package/dist/hooks/runtime/unmapped-tools.js +77 -1
- package/dist/hooks/runtime/unmapped-tools.js.map +1 -1
- package/dist/hooks/runtime/user-prompt-submit.js +1 -1
- package/dist/hooks/runtime/user-prompt-submit.js.map +1 -1
- package/dist/hooks/runtime/work-dir.js +3 -0
- package/dist/hooks/runtime/work-dir.js.map +1 -1
- package/dist/hooks/shim.js +27 -20
- package/dist/hooks/shim.js.map +1 -1
- package/dist/index.js +46 -10
- package/dist/index.js.map +1 -1
- package/dist/install-scope.js +12 -0
- package/dist/install-scope.js.map +1 -0
- package/dist/install.js +188 -78
- package/dist/install.js.map +1 -1
- package/dist/link.js +55 -5
- package/dist/link.js.map +1 -1
- package/dist/mcp/config/hook.js +25 -0
- package/dist/mcp/config/hook.js.map +1 -1
- package/dist/org.js +3 -1
- package/dist/org.js.map +1 -1
- package/dist/prompts.js +97 -13
- package/dist/prompts.js.map +1 -1
- package/dist/refresh-hooks.js +67 -15
- package/dist/refresh-hooks.js.map +1 -1
- package/dist/repo/exclude-block.js +112 -0
- package/dist/repo/exclude-block.js.map +1 -0
- package/dist/repo/footer.js +93 -0
- package/dist/repo/footer.js.map +1 -0
- package/dist/repo/git-repo.js +77 -0
- package/dist/repo/git-repo.js.map +1 -0
- package/dist/repo/guarded-write.js +45 -0
- package/dist/repo/guarded-write.js.map +1 -0
- package/dist/repo/install-repo.js +508 -0
- package/dist/repo/install-repo.js.map +1 -0
- package/dist/repo/machine-wiring.js +122 -0
- package/dist/repo/machine-wiring.js.map +1 -0
- package/dist/repo/mcp-json.js +57 -0
- package/dist/repo/mcp-json.js.map +1 -0
- package/dist/repo/registry.js +53 -0
- package/dist/repo/registry.js.map +1 -0
- package/dist/repo/repo-mode-guard.js +83 -0
- package/dist/repo/repo-mode-guard.js.map +1 -0
- package/dist/repo/repo-setups.js +123 -0
- package/dist/repo/repo-setups.js.map +1 -0
- package/dist/repo/repo-status.js +283 -0
- package/dist/repo/repo-status.js.map +1 -0
- package/dist/repo/uninstall-repo.js +56 -0
- package/dist/repo/uninstall-repo.js.map +1 -0
- package/dist/repo/unsupported.js +14 -0
- package/dist/repo/unsupported.js.map +1 -0
- package/dist/scan-diff.js +526 -0
- package/dist/scan-diff.js.map +1 -0
- package/dist/shim.js +9 -7
- package/dist/status.js +53 -11
- package/dist/status.js.map +1 -1
- package/dist/uninstall.js +51 -3
- package/dist/uninstall.js.map +1 -1
- package/dist/update-check-gate.js +17 -0
- package/dist/update-check-gate.js.map +1 -0
- package/dist/update.js +6 -1
- package/dist/update.js.map +1 -1
- package/dist/zip.js +95 -0
- package/dist/zip.js.map +1 -0
- package/package.json +6 -3
package/dist/hooks/install.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* scripts) with a simpler "copy + write config" pair:
|
|
6
6
|
*
|
|
7
7
|
* 1. Copy the bundled `dist/hook-runner.js` (built by esbuild) to
|
|
8
|
-
* `~/.cybedefend/hook-runner.js`. ONE script for all
|
|
8
|
+
* `~/.cybedefend/hook-runner.js`. ONE script for all 7 agents.
|
|
9
9
|
* 2. Write `~/.cybedefend/runtime-config.json` with the user's region
|
|
10
10
|
* + hook tunables — the runner reads it on every invocation.
|
|
11
11
|
*
|
|
@@ -180,9 +180,11 @@ export function installHookRuntime(opts, deps = {}) {
|
|
|
180
180
|
nonBlockingMode: opts.hooks.nonBlockingMode,
|
|
181
181
|
autoUpdate: useShim ? opts.hooks.autoUpdate : false,
|
|
182
182
|
enableDiffScan: opts.hooks.enableDiffScan,
|
|
183
|
+
enablePackageCheck: opts.hooks.enablePackageCheck,
|
|
183
184
|
activation: opts.hooks.activation,
|
|
184
185
|
},
|
|
185
186
|
installedVersion: opts.installedVersion,
|
|
187
|
+
installScope: opts.installScope ?? 'machine',
|
|
186
188
|
...(useShim ? { runnerSource } : {}),
|
|
187
189
|
...keptOrganization(configDest, opts.region),
|
|
188
190
|
};
|
|
@@ -241,9 +243,12 @@ export function quoteCommandPath(p) {
|
|
|
241
243
|
* a specific subcommand of the runner. Pure — adapters call this without
|
|
242
244
|
* touching the filesystem.
|
|
243
245
|
*/
|
|
244
|
-
export function hookCommand(subcommand, runnerPath = HOOK_RUNNER_PATH) {
|
|
246
|
+
export function hookCommand(subcommand, runnerPath = HOOK_RUNNER_PATH, client) {
|
|
245
247
|
// Forward-slash first (Windows-shell safe), then quote if it has a space.
|
|
246
|
-
|
|
248
|
+
const base = `node ${quoteCommandPath(toPosixPath(runnerPath))} ${subcommand}`;
|
|
249
|
+
// Repo mode names the agent the command was written for, so the runner can
|
|
250
|
+
// drop a call another agent fired through the same settings file.
|
|
251
|
+
return client ? `${base} --client ${client}` : base;
|
|
247
252
|
}
|
|
248
253
|
/**
|
|
249
254
|
* Marker used by every adapter's `dropOurs` to identify legacy AND new
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/hooks/install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAIzC,OAAO,EACL,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,GAEb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,I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,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChE,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACvD,OAAO,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AAC5C,CAAC"}
|
|
@@ -1,30 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Per-
|
|
2
|
+
* Per-session on-disk state for the JSON-contract clients: Antigravity
|
|
3
|
+
* (BACK-241) and OpenCode (BACK-255).
|
|
4
|
+
*
|
|
5
|
+
* The module keeps its Antigravity-era file name; both clients are served
|
|
6
|
+
* by the same functions, each under its own directory
|
|
7
|
+
* (`sessionStateDir(client)`: `~/.cybedefend/antigravity` or
|
|
8
|
+
* `~/.cybedefend/opencode`), so one client's sessions never see, nor get
|
|
9
|
+
* pruned with, the other's.
|
|
3
10
|
*
|
|
4
11
|
* Antigravity's hook envelope carries a `conversationId` that is stable for
|
|
5
|
-
* the life of one chat (SessionStart through the matching Stop),
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* path component
|
|
12
|
+
* the life of one chat (SessionStart through the matching Stop), OpenCode's
|
|
13
|
+
* plugin envelope a `sessionID` that is stable for one session, and in both
|
|
14
|
+
* the CLI is re-invoked once per hook call, as a short-lived process with
|
|
15
|
+
* no memory of the calls before it. Three small per-session ledgers bridge
|
|
16
|
+
* that gap, under `<state dir>/<key>/`, keyed by a hash of that id so no
|
|
17
|
+
* caller-supplied string ever becomes a path component
|
|
18
|
+
* (`sessionStateKey`):
|
|
11
19
|
*
|
|
12
20
|
* - `context/*.md` — rule bodies a PreToolUse run stashed because it had
|
|
13
21
|
* nothing to deliver to the model (an Antigravity `allow` answer is
|
|
14
|
-
* never shown to it).
|
|
15
|
-
*
|
|
22
|
+
* never shown to it). Antigravity only: OpenCode's answer carries its
|
|
23
|
+
* context itself. The PreInvocation hook drains and delivers them at the
|
|
24
|
+
* next call that CAN speak to the model.
|
|
16
25
|
* - `edits.jsonl` — one `{"f": "<path>"}` line per file a PreToolUse
|
|
17
|
-
* run saw edited, read back by the end-of-session review
|
|
18
|
-
* - `reviewed` — a marker a review run leaves so a
|
|
19
|
-
*
|
|
26
|
+
* run saw edited, read back by the end-of-session review.
|
|
27
|
+
* - `reviewed` — a marker a review run leaves so a session is never
|
|
28
|
+
* reviewed twice.
|
|
20
29
|
*
|
|
21
30
|
* Antigravity runs tool calls in parallel, so several hook processes can be
|
|
22
|
-
* writing one
|
|
31
|
+
* writing one session's state at the same time:
|
|
23
32
|
* - `stashContext` writes to a hidden `.tmp` scratch name in `context/`
|
|
24
33
|
* (`O_CREAT|O_EXCL`, so two concurrent stashes can't collide) and only
|
|
25
34
|
* `renameSync`s it to its final `${Date.now()}-${8 hex}.md` name once
|
|
26
35
|
* it is fully written — `renameSync` is atomic on the same filesystem,
|
|
27
36
|
* so a reader never observes a half-written body under a final name.
|
|
37
|
+
* Within one process the timestamp is strictly increasing, so stashes
|
|
38
|
+
* made in the same millisecond still drain in the order they were made.
|
|
28
39
|
* - `recordEdit` only ever appends, one line per call: concurrent appends
|
|
29
40
|
* interleave at the line boundary, never inside a line.
|
|
30
41
|
* - `readEdits` tolerates a line a concurrent writer has not finished
|
|
@@ -33,12 +44,12 @@
|
|
|
33
44
|
*
|
|
34
45
|
* Every write refreshes the key directory's own mtime (`ensureLiveKeyDir`):
|
|
35
46
|
* a directory's mtime otherwise only moves when a direct child is added or
|
|
36
|
-
* removed, so a
|
|
47
|
+
* removed, so a session that is active every day but never adds a new
|
|
37
48
|
* TOP-LEVEL entry under its key directory (every `recordEdit` call after
|
|
38
49
|
* the first only appends to an already-existing `edits.jsonl`) would
|
|
39
50
|
* otherwise look as old as its very first write to `pruneStale`.
|
|
40
51
|
*
|
|
41
|
-
* A path under a
|
|
52
|
+
* A path under a session's key directory may be a symlink an attacker
|
|
42
53
|
* planted before the hook ran (into the key directory's position itself,
|
|
43
54
|
* or into its `context/` subdirectory) to redirect a write or a delete
|
|
44
55
|
* outside the state directory. Every entry point — the three writers, the
|
|
@@ -46,23 +57,28 @@
|
|
|
46
57
|
* follows a link) before it writes, reads or judges staleness through it,
|
|
47
58
|
* and refuses (does nothing) when the path is not a real directory. The
|
|
48
59
|
* same applies one level down, at `edits.jsonl` and `reviewed` themselves:
|
|
49
|
-
* their names are fixed and the key is a predictable hash of
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* `
|
|
55
|
-
*
|
|
60
|
+
* their names are fixed and the key is a predictable hash of the session
|
|
61
|
+
* id, so an attacker needs no race, just a symlink planted ahead of time in
|
|
62
|
+
* an otherwise-real key directory. `recordEdit` and `markReviewed` open
|
|
63
|
+
* with `O_NOFOLLOW` (an `lstatSync` check where that flag is unavailable —
|
|
64
|
+
* Windows); `readEdits` and `isReviewed` use `lstatSync`, never
|
|
65
|
+
* `existsSync`/`statSync`, and treat a symlink there the same as a session
|
|
66
|
+
* with no state yet. None of that depends on the client: the functions take
|
|
67
|
+
* the directory to work in and check it the same way, whichever it is.
|
|
68
|
+
*
|
|
69
|
+
* Every function takes that directory explicitly (no default): a default
|
|
70
|
+
* would silently be one client's, and an OpenCode caller that forgot to
|
|
71
|
+
* name its own would write into Antigravity's.
|
|
56
72
|
*
|
|
57
73
|
* No function in this module throws: every filesystem error is swallowed
|
|
58
74
|
* and the caller gets back the same empty value it would get from a
|
|
59
|
-
*
|
|
75
|
+
* session that has no state yet.
|
|
60
76
|
*/
|
|
61
77
|
import { appendFileSync, closeSync, constants, lstatSync, mkdirSync, openSync, readdirSync, readFileSync, renameSync, rmSync, unlinkSync, utimesSync, writeFileSync, writeSync, } from 'node:fs';
|
|
62
78
|
import { createHash, randomBytes } from 'node:crypto';
|
|
63
79
|
import { homedir } from 'node:os';
|
|
64
80
|
import { join } from 'node:path';
|
|
65
|
-
/** Stashed rule bodies kept per
|
|
81
|
+
/** Stashed rule bodies kept per session; the oldest are dropped past this. */
|
|
66
82
|
export const MAX_STASHED_CONTEXTS = 20;
|
|
67
83
|
/** Default staleness window for `pruneStale`, read from a key directory's mtime. */
|
|
68
84
|
export const DEFAULT_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
@@ -72,20 +88,49 @@ export const DEFAULT_MAX_AGE_MS = 7 * 24 * 60 * 60 * 1000;
|
|
|
72
88
|
const STASH_NAME_RE = /^\d+-[0-9a-f]{8}\.md$/;
|
|
73
89
|
const DIR_MODE = 0o700;
|
|
74
90
|
const FILE_MODE = 0o600;
|
|
91
|
+
/** The envelope field that identifies a session, per client. */
|
|
92
|
+
const SESSION_ID_FIELD = {
|
|
93
|
+
antigravity: 'conversationId',
|
|
94
|
+
opencode: 'sessionID',
|
|
95
|
+
};
|
|
96
|
+
/** A usable session id: a string of 1 to 256 characters. */
|
|
97
|
+
function stateId(value) {
|
|
98
|
+
return typeof value === 'string' && value.length > 0 && value.length <= 256
|
|
99
|
+
? value
|
|
100
|
+
: null;
|
|
101
|
+
}
|
|
75
102
|
/**
|
|
76
|
-
* A stable key for
|
|
77
|
-
*
|
|
78
|
-
*
|
|
103
|
+
* A stable key for the session an envelope belongs to: the first 32 hex
|
|
104
|
+
* characters of the sha256 of its id (`conversationId` for Antigravity,
|
|
105
|
+
* `sessionID` for OpenCode), so the id itself (arbitrary, agent-supplied)
|
|
106
|
+
* never becomes a path component. Null for a missing, empty, non-string or
|
|
107
|
+
* longer-than-256 id, and for an envelope of the other client (it has no
|
|
108
|
+
* such field).
|
|
109
|
+
*
|
|
110
|
+
* On OpenCode the key is the ROOT session's: the plugin stamps it on every
|
|
111
|
+
* envelope as `rootSessionID`, and a subagent's (`task`) tool calls carry
|
|
112
|
+
* the child's own `sessionID`. The review runs for the root session only
|
|
113
|
+
* and reads the root's ledger, so a session that delegates its edits is
|
|
114
|
+
* reviewed on them. A `rootSessionID` that is not a usable id falls back to
|
|
115
|
+
* the `sessionID`.
|
|
79
116
|
*/
|
|
80
|
-
export function
|
|
81
|
-
const id = raw.
|
|
82
|
-
|
|
117
|
+
export function sessionStateKey(raw, client) {
|
|
118
|
+
const id = (client === 'opencode' ? stateId(raw.rootSessionID) : null) ??
|
|
119
|
+
stateId(raw[SESSION_ID_FIELD[client]]);
|
|
120
|
+
if (id === null)
|
|
83
121
|
return null;
|
|
84
122
|
return createHash('sha256').update(id).digest('hex').slice(0, 32);
|
|
85
123
|
}
|
|
86
|
-
/**
|
|
87
|
-
export function
|
|
88
|
-
return
|
|
124
|
+
/** The key of an Antigravity conversation: `sessionStateKey(raw, 'antigravity')`. */
|
|
125
|
+
export function conversationKey(raw) {
|
|
126
|
+
return sessionStateKey(raw, 'antigravity');
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* `~/.cybedefend/<client>` (`antigravity` or `opencode`), re-read on every
|
|
130
|
+
* call (home can move in tests).
|
|
131
|
+
*/
|
|
132
|
+
export function sessionStateDir(client) {
|
|
133
|
+
return join(homedir(), '.cybedefend', client);
|
|
89
134
|
}
|
|
90
135
|
function keyDir(key, dir) {
|
|
91
136
|
return join(dir, key);
|
|
@@ -182,7 +227,7 @@ function ensureRealDir(path) {
|
|
|
182
227
|
/**
|
|
183
228
|
* Ensure a real key directory exists for `key` under `dir`, and bump its
|
|
184
229
|
* own mtime to `now` on every call — not only when it is first created —
|
|
185
|
-
* so a
|
|
230
|
+
* so a session written to every day never looks idle to `pruneStale`.
|
|
186
231
|
* Refuses — creates and touches nothing — when something other than a real
|
|
187
232
|
* directory already sits at that path (see the module doc).
|
|
188
233
|
*/
|
|
@@ -199,12 +244,25 @@ function ensureLiveKeyDir(key, dir, now) {
|
|
|
199
244
|
}
|
|
200
245
|
return kd;
|
|
201
246
|
}
|
|
247
|
+
/** The timestamp of this process's last stash name. */
|
|
248
|
+
let lastStashStamp = 0;
|
|
249
|
+
/**
|
|
250
|
+
* The timestamp a new stash name starts with: `now`, or one more than the
|
|
251
|
+
* previous stash of this process when that one is not older. Two stashes in
|
|
252
|
+
* the same millisecond would otherwise share a prefix and be drained in the
|
|
253
|
+
* order of their random suffix. The name keeps its `<digits>-<8 hex>.md`
|
|
254
|
+
* shape, which another release of the CLI may be reading.
|
|
255
|
+
*/
|
|
256
|
+
function nextStashStamp(now) {
|
|
257
|
+
lastStashStamp = Math.max(now, lastStashStamp + 1);
|
|
258
|
+
return lastStashStamp;
|
|
259
|
+
}
|
|
202
260
|
/**
|
|
203
|
-
* Stash a rule body for a
|
|
261
|
+
* Stash a rule body for a session that cannot see it right now
|
|
204
262
|
* (Antigravity's PreToolUse `allow` never reaches the model). Keeps the 20
|
|
205
263
|
* newest stashes; older ones are dropped silently.
|
|
206
264
|
*/
|
|
207
|
-
export function stashContext(key, body, dir
|
|
265
|
+
export function stashContext(key, body, dir) {
|
|
208
266
|
let tmpPath;
|
|
209
267
|
try {
|
|
210
268
|
const now = Date.now();
|
|
@@ -214,11 +272,12 @@ export function stashContext(key, body, dir = antigravityStateDir()) {
|
|
|
214
272
|
const contextDir = join(kd, 'context');
|
|
215
273
|
if (!ensureRealDir(contextDir))
|
|
216
274
|
return;
|
|
275
|
+
const stamp = nextStashStamp(now);
|
|
217
276
|
const suffix = randomBytes(4).toString('hex');
|
|
218
|
-
tmpPath = join(contextDir, `.${
|
|
277
|
+
tmpPath = join(contextDir, `.${stamp}-${suffix}.tmp`);
|
|
219
278
|
// O_EXCL: two concurrent stashes never collide on the same scratch name.
|
|
220
279
|
writeFileSync(tmpPath, body, { mode: FILE_MODE, flag: 'wx' });
|
|
221
|
-
const finalPath = join(contextDir, `${
|
|
280
|
+
const finalPath = join(contextDir, `${stamp}-${suffix}.md`);
|
|
222
281
|
renameSync(tmpPath, finalPath); // atomic on the same filesystem
|
|
223
282
|
tmpPath = undefined; // renamed away — nothing left to clean up on error
|
|
224
283
|
const kept = readdirSync(contextDir).filter(isFinalStashName).sort();
|
|
@@ -246,13 +305,13 @@ export function stashContext(key, body, dir = antigravityStateDir()) {
|
|
|
246
305
|
}
|
|
247
306
|
}
|
|
248
307
|
/**
|
|
249
|
-
* Every stashed body for a
|
|
308
|
+
* Every stashed body for a session, oldest first, each file deleted as
|
|
250
309
|
* it is read. A body stashed more than once (two PreToolUse runs stashing
|
|
251
310
|
* the same unseen rule) is returned only once. A `.tmp` scratch file still
|
|
252
311
|
* mid-write (or left behind by a crashed stash) is neither read nor
|
|
253
312
|
* deleted — only a final `*.md` name is ever touched.
|
|
254
313
|
*/
|
|
255
|
-
export function drainContext(key, dir
|
|
314
|
+
export function drainContext(key, dir) {
|
|
256
315
|
try {
|
|
257
316
|
const kd = keyDir(key, dir);
|
|
258
317
|
if (isUnsafePath(kd))
|
|
@@ -288,8 +347,8 @@ export function drainContext(key, dir = antigravityStateDir()) {
|
|
|
288
347
|
return [];
|
|
289
348
|
}
|
|
290
349
|
}
|
|
291
|
-
/** Record that a
|
|
292
|
-
export function recordEdit(key, file, dir
|
|
350
|
+
/** Record that a session's PreToolUse run saw `file` edited. */
|
|
351
|
+
export function recordEdit(key, file, dir) {
|
|
293
352
|
try {
|
|
294
353
|
const now = Date.now();
|
|
295
354
|
const kd = ensureLiveKeyDir(key, dir, now);
|
|
@@ -301,8 +360,8 @@ export function recordEdit(key, file, dir = antigravityStateDir()) {
|
|
|
301
360
|
// Best-effort.
|
|
302
361
|
}
|
|
303
362
|
}
|
|
304
|
-
/** The edits recorded for a
|
|
305
|
-
export function readEdits(key, dir
|
|
363
|
+
/** The edits recorded for a session: how many, and which distinct files, in order. */
|
|
364
|
+
export function readEdits(key, dir) {
|
|
306
365
|
try {
|
|
307
366
|
const kd = keyDir(key, dir);
|
|
308
367
|
if (isUnsafePath(kd))
|
|
@@ -341,8 +400,8 @@ export function readEdits(key, dir = antigravityStateDir()) {
|
|
|
341
400
|
return { count: 0, files: [] };
|
|
342
401
|
}
|
|
343
402
|
}
|
|
344
|
-
/** Mark a
|
|
345
|
-
export function markReviewed(key, dir
|
|
403
|
+
/** Mark a session as reviewed (the end-of-session review ran). */
|
|
404
|
+
export function markReviewed(key, dir) {
|
|
346
405
|
try {
|
|
347
406
|
const now = Date.now();
|
|
348
407
|
const kd = ensureLiveKeyDir(key, dir, now);
|
|
@@ -354,8 +413,8 @@ export function markReviewed(key, dir = antigravityStateDir()) {
|
|
|
354
413
|
// Best-effort.
|
|
355
414
|
}
|
|
356
415
|
}
|
|
357
|
-
/** Whether `markReviewed` already ran for this
|
|
358
|
-
export function isReviewed(key, dir
|
|
416
|
+
/** Whether `markReviewed` already ran for this session. */
|
|
417
|
+
export function isReviewed(key, dir) {
|
|
359
418
|
try {
|
|
360
419
|
const kd = keyDir(key, dir);
|
|
361
420
|
if (isUnsafePath(kd))
|
|
@@ -368,7 +427,7 @@ export function isReviewed(key, dir = antigravityStateDir()) {
|
|
|
368
427
|
}
|
|
369
428
|
}
|
|
370
429
|
/**
|
|
371
|
-
* Remove a
|
|
430
|
+
* Remove a session's whole state directory once it is older than
|
|
372
431
|
* `maxAgeMs` (default 7 days). Staleness is read with `lstatSync` on the
|
|
373
432
|
* entry itself: a `statSync` would follow a symlink an attacker planted
|
|
374
433
|
* under the state directory and judge staleness by whatever it points to
|
|
@@ -377,7 +436,7 @@ export function isReviewed(key, dir = antigravityStateDir()) {
|
|
|
377
436
|
* link (`rmSync` never descends into a symlink's target), never whatever
|
|
378
437
|
* it points to.
|
|
379
438
|
*/
|
|
380
|
-
export function pruneStale(dir
|
|
439
|
+
export function pruneStale(dir, now = Date.now(), maxAgeMs = DEFAULT_MAX_AGE_MS) {
|
|
381
440
|
try {
|
|
382
441
|
const entries = readdirSync(dir);
|
|
383
442
|
for (const name of entries) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"antigravity-session.js","sourceRoot":"","sources":["../../../src/hooks/runtime/antigravity-session.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"antigravity-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;AAC3D,MAAM,UAAU,UAAU,CAAC,GAAW,EAAE,GAAW;IACjD,IAAI,CAAC;QACH,MAAM,EAAE,GAAG,MAAM,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QAC5B,IAAI,YAAY,CAAC,EAAE,CAAC;YAAE,OAAO,KAAK,CAAC;QACnC,uEAAuE;QACvE,OAAO,SAAS,CAAC,IAAI,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAClD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CACxB,GAAW,EACX,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,EAChB,QAAQ,GAAG,kBAAkB;IAE7B,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;QACjC,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;YAC3B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YAClC,IAAI,CAAC;gBACH,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;gBACzC,IAAI,GAAG,GAAG,OAAO,GAAG,QAAQ,EAAE,CAAC;oBAC7B,MAAM,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;gBACtD,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,sDAAsD;YACxD,CAAC;QACH,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,uDAAuD;IACzD,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The files an OpenCode `apply_patch` call touches (BACK-255).
|
|
3
|
+
*
|
|
4
|
+
* OpenCode's `apply_patch` tool takes the whole patch as one string,
|
|
5
|
+
* `args.patchText`, in the Codex patch format. The files are named on header
|
|
6
|
+
* lines, and OpenCode's own parser acts on exactly these four
|
|
7
|
+
* (`packages/opencode/src/patch/index.ts:76-96`, v1.19.4):
|
|
8
|
+
*
|
|
9
|
+
* *** Add File: <path>
|
|
10
|
+
* *** Update File: <path>
|
|
11
|
+
* *** Delete File: <path>
|
|
12
|
+
* *** Move to: <path> (the destination of an Update File)
|
|
13
|
+
*
|
|
14
|
+
* A header is a line that STARTS with the marker, the path is the rest of the
|
|
15
|
+
* line trimmed (`line.slice(marker.length).trim()`), so `*** Add File:x` is a
|
|
16
|
+
* header too and a header with no path is skipped. Every line of the patch's
|
|
17
|
+
* content carries a prefix (`+`, `-`, a space, `@@`), so a header-looking text
|
|
18
|
+
* inside a hunk is never read as one.
|
|
19
|
+
*
|
|
20
|
+
* A path resolves the way OpenCode resolves it: `path.resolve(directory,
|
|
21
|
+
* path)` (`tool/apply_patch.ts:73` and `:142`), so a relative path is under
|
|
22
|
+
* the instance directory and `~` or `$VAR` are NOT expanded: `~/.ssh/x` is
|
|
23
|
+
* written under `<directory>/~/.ssh/x`. The guard gates the file OpenCode
|
|
24
|
+
* writes, not the one a shell would have meant.
|
|
25
|
+
*
|
|
26
|
+
* Headers are read anywhere in the text, not only between `*** Begin Patch`
|
|
27
|
+
* and `*** End Patch`: a patch OpenCode refuses reads a few files more than
|
|
28
|
+
* it would apply, and the guard never reads fewer files than OpenCode writes.
|
|
29
|
+
*
|
|
30
|
+
* `filePathFromPatch` (sniff.ts) stays the Codex reader: one file, relative,
|
|
31
|
+
* for a Codex payload.
|
|
32
|
+
*
|
|
33
|
+
* OpenCode V2's `patch` tool takes the same text and the same four headers,
|
|
34
|
+
* read differently ({@link parseV2PatchFiles}).
|
|
35
|
+
*/
|
|
36
|
+
import { resolve as resolvePath } from 'node:path';
|
|
37
|
+
/** The header markers that name a file, as OpenCode's parser spells them. */
|
|
38
|
+
const FILE_HEADERS = [
|
|
39
|
+
'*** Add File:',
|
|
40
|
+
'*** Update File:',
|
|
41
|
+
'*** Delete File:',
|
|
42
|
+
'*** Move to:',
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
* Every path `readLine` finds in a header of `patchText`, trimmed, through
|
|
46
|
+
* `resolveFile`, distinct, in the order they appear.
|
|
47
|
+
*/
|
|
48
|
+
function headerFiles(patchText, readLine, resolveFile) {
|
|
49
|
+
if (typeof patchText !== 'string')
|
|
50
|
+
return [];
|
|
51
|
+
const seen = new Set();
|
|
52
|
+
const files = [];
|
|
53
|
+
for (const raw of patchText.split('\n')) {
|
|
54
|
+
const line = readLine(raw);
|
|
55
|
+
const marker = FILE_HEADERS.find((m) => line.startsWith(m));
|
|
56
|
+
if (marker === undefined)
|
|
57
|
+
continue;
|
|
58
|
+
const path = line.slice(marker.length).trim();
|
|
59
|
+
if (path.length === 0)
|
|
60
|
+
continue;
|
|
61
|
+
const file = resolveFile(path);
|
|
62
|
+
if (seen.has(file))
|
|
63
|
+
continue;
|
|
64
|
+
seen.add(file);
|
|
65
|
+
files.push(file);
|
|
66
|
+
}
|
|
67
|
+
return files;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The paths of every `Add File`, `Update File`, `Delete File` and `Move to`
|
|
71
|
+
* header of `patchText`, trimmed, resolved against `baseDir` (an absolute
|
|
72
|
+
* path is kept), distinct, in the order they appear. `[]` for a value that is
|
|
73
|
+
* not a string and for a text with no header. Never throws on its text.
|
|
74
|
+
*/
|
|
75
|
+
export function parseApplyPatchFiles(patchText, baseDir) {
|
|
76
|
+
return headerFiles(patchText, (line) => line, (path) => resolvePath(baseDir, path));
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The same headers as OpenCode V2 reads them (`parse`, `@opencode/util/patch`,
|
|
80
|
+
* v2.2.1), which differs in two ways. A line is trimmed before it is looked at
|
|
81
|
+
* (`const header = line.trim()`), so an indented ` *** Add File: .env` writes
|
|
82
|
+
* `.env`, where V1 sees a line of a hunk. A path goes through
|
|
83
|
+
* `FileAccess.resolvePath`, so `resolveFile` is the caller's
|
|
84
|
+
* (`resolveOpenCodeV2Path`, sniff.ts). A content line keeps its `+`, so a
|
|
85
|
+
* header quoted in a hunk is still not one. V2 requires a space after each
|
|
86
|
+
* colon and refuses more than this reads: as above, the guard never reads
|
|
87
|
+
* fewer files than OpenCode writes.
|
|
88
|
+
*/
|
|
89
|
+
export function parseV2PatchFiles(patchText, resolveFile) {
|
|
90
|
+
return headerFiles(patchText, (line) => line.trim(), resolveFile);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=apply-patch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apply-patch.js","sourceRoot":"","sources":["../../../src/hooks/runtime/apply-patch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAEnD,6EAA6E;AAC7E,MAAM,YAAY,GAAsB;IACtC,eAAe;IACf,kBAAkB;IAClB,kBAAkB;IAClB,cAAc;CACf,CAAC;AAEF;;;GAGG;AACH,SAAS,WAAW,CAClB,SAAiB,EACjB,QAAkC,EAClC,WAAqC;IAErC,IAAI,OAAO,SAAS,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IAC7C,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAC/B,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,KAAK,MAAM,GAAG,IAAI,SAAS,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC3B,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5D,IAAI,MAAM,KAAK,SAAS;YAAE,SAAS;QACnC,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,CAAC;QAC9C,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC;YAAE,SAAS;QAChC,MAAM,IAAI,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;YAAE,SAAS;QAC7B,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,SAAiB,EACjB,OAAe;IAEf,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;AACtF,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,iBAAiB,CAC/B,SAAiB,EACjB,WAAqC;IAErC,OAAO,WAAW,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,WAAW,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Repo-mode caller gate. Cursor, VS Code Copilot and Devin also run the hooks
|
|
3
|
+
* of `.claude/settings*.json`; a hook command written for Claude Code
|
|
4
|
+
* (`--client claude-code`) fired by one of them must do nothing. The caller is
|
|
5
|
+
* read from the stdin payload.
|
|
6
|
+
*
|
|
7
|
+
* Only Claude Code's hooks are gated: `.claude/settings*.json` is the one
|
|
8
|
+
* repo-mode hook file another agent reads. `detectClient` falls back to
|
|
9
|
+
* `claude-code` for an ambiguous payload (Codex's SessionStart carries no
|
|
10
|
+
* `turn_id`, for one), so gating any other client would drop its own hooks.
|
|
11
|
+
* Runtime module: node builtins and other runtime
|
|
12
|
+
* modules only.
|
|
13
|
+
*/
|
|
14
|
+
import { isRepoScope } from './repo-scope.js';
|
|
15
|
+
import { detectClient } from './sniff.js';
|
|
16
|
+
/** True only in repo scope, for a Claude Code command whose payload is not Claude Code's. Never throws. */
|
|
17
|
+
export function callerMismatch(client, envelope, config) {
|
|
18
|
+
if (client !== 'claude-code' || !isRepoScope(config))
|
|
19
|
+
return false;
|
|
20
|
+
try {
|
|
21
|
+
return detectClient(envelope) !== client;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=caller-gate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caller-gate.js","sourceRoot":"","sources":["../../../src/hooks/runtime/caller-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG1C,2GAA2G;AAC3G,MAAM,UAAU,cAAc,CAC5B,MAA2B,EAC3B,QAAiC,EACjC,MAA4B;IAE5B,IAAI,MAAM,KAAK,aAAa,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC;QAAE,OAAO,KAAK,CAAC;IACnE,IAAI,CAAC;QACH,OAAO,YAAY,CAAC,QAAQ,CAAC,KAAK,MAAM,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|