@bjoernrochel/sevro 1.0.0 → 1.1.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/CONTRIBUTING.md +34 -4
- package/README.md +7 -6
- package/dist/examples/basic/graded.json +13 -0
- package/dist/examples/basic/host.js +9 -0
- package/dist/examples/basic/host.js.map +1 -0
- package/dist/examples/basic/prompt-only.json +7 -0
- package/dist/examples/recipes/candidate.js +23 -0
- package/dist/examples/recipes/candidate.js.map +1 -0
- package/dist/examples/recipes/cases/coding-change.json +21 -0
- package/dist/examples/recipes/cases/host-tools.json +21 -0
- package/dist/examples/recipes/cases/mise.json +21 -0
- package/dist/examples/recipes/cases/node.json +21 -0
- package/dist/examples/recipes/cases/python-uv.json +21 -0
- package/dist/examples/recipes/cases/semantic.json +17 -0
- package/dist/examples/recipes/coding-change/check.js +16 -0
- package/dist/examples/recipes/coding-change/check.js.map +1 -0
- package/dist/examples/recipes/executable.js +20 -0
- package/dist/examples/recipes/executable.js.map +1 -0
- package/dist/examples/recipes/extension-artifacts.js +56 -0
- package/dist/examples/recipes/extension-artifacts.js.map +1 -0
- package/dist/examples/recipes/extension-methods.js +167 -0
- package/dist/examples/recipes/extension-methods.js.map +1 -0
- package/dist/examples/recipes/extension.js +28 -0
- package/dist/examples/recipes/extension.js.map +1 -0
- package/dist/examples/recipes/modules.js +9 -0
- package/dist/examples/recipes/modules.js.map +1 -0
- package/dist/examples/recipes/repository-skill/.agents/skills/startup-guide/SKILL.md +7 -0
- package/dist/examples/recipes/repository-skill/.claude/skills/startup-guide/SKILL.md +7 -0
- package/dist/examples/recipes/repository-skill/README.md +3 -0
- package/dist/examples/recipes/run-inputs.js +144 -0
- package/dist/examples/recipes/run-inputs.js.map +1 -0
- package/dist/examples/recipes/run-options.js +103 -0
- package/dist/examples/recipes/run-options.js.map +1 -0
- package/dist/examples/recipes/run.js +62 -0
- package/dist/examples/recipes/run.js.map +1 -0
- package/dist/examples/recipes/runtime/empty.json +1 -0
- package/dist/examples/recipes/runtime/goals.json +1 -0
- package/dist/examples/recipes/runtime/mise.json +6 -0
- package/dist/examples/recipes/runtime/path.json +1 -0
- package/dist/examples/recipes/runtime/plugins.json +4 -0
- package/dist/examples/recipes/runtime/python-uv.json +10 -0
- package/dist/examples/recipes/semantic-judge.js +27 -0
- package/dist/examples/recipes/semantic-judge.js.map +1 -0
- package/dist/examples/templates/coding/adapter.js +14 -0
- package/dist/examples/templates/coding/adapter.js.map +1 -0
- package/dist/examples/templates/coding/case.json +15 -0
- package/dist/examples/templates/repository-skill/.agents/skills/startup-guide/SKILL.md +6 -0
- package/dist/examples/templates/repository-skill/extension-data.js +61 -0
- package/dist/examples/templates/repository-skill/extension-data.js.map +1 -0
- package/dist/examples/templates/repository-skill/extension.js +29 -0
- package/dist/examples/templates/repository-skill/extension.js.map +1 -0
- package/dist/examples/templates/response/adapter.js +13 -0
- package/dist/examples/templates/response/adapter.js.map +1 -0
- package/dist/examples/templates/response/case.json +13 -0
- package/dist/src/advisory.js +86 -0
- package/dist/src/advisory.js.map +1 -0
- package/dist/src/candidate-artifacts.js +139 -0
- package/dist/src/candidate-artifacts.js.map +1 -0
- package/dist/src/candidate-codex-state.js +110 -0
- package/dist/src/candidate-codex-state.js.map +1 -0
- package/dist/src/case-validation.js +92 -0
- package/dist/src/case-validation.js.map +1 -0
- package/dist/src/cli/cancellation.js +21 -0
- package/dist/src/cli/cancellation.js.map +1 -0
- package/dist/src/cli/command.js +60 -0
- package/dist/src/cli/command.js.map +1 -0
- package/dist/src/cli/completion.js +14 -0
- package/dist/src/cli/completion.js.map +1 -0
- package/dist/src/cli/demo.js +45 -0
- package/dist/src/cli/demo.js.map +1 -0
- package/dist/src/cli/evaluation.js +40 -0
- package/dist/src/cli/evaluation.js.map +1 -0
- package/dist/src/cli/extension.js +54 -0
- package/dist/src/cli/extension.js.map +1 -0
- package/dist/src/cli/help.js +190 -0
- package/dist/src/cli/help.js.map +1 -0
- package/dist/src/cli/hosts.js +33 -0
- package/dist/src/cli/hosts.js.map +1 -0
- package/dist/src/cli/init-settings.js +29 -0
- package/dist/src/cli/init-settings.js.map +1 -0
- package/dist/src/cli/init.js +82 -0
- package/dist/src/cli/init.js.map +1 -0
- package/dist/src/cli/invocation.js +431 -0
- package/dist/src/cli/invocation.js.map +1 -0
- package/dist/src/cli/loading.js +110 -0
- package/dist/src/cli/loading.js.map +1 -0
- package/dist/src/cli/preparation.js +88 -0
- package/dist/src/cli/preparation.js.map +1 -0
- package/dist/src/cli/presentation.js +61 -0
- package/dist/src/cli/presentation.js.map +1 -0
- package/dist/src/cli/progress.js +5 -0
- package/dist/src/cli/progress.js.map +1 -0
- package/dist/src/cli/run-manifest.js +108 -0
- package/dist/src/cli/run-manifest.js.map +1 -0
- package/dist/src/cli/run-options.js +367 -0
- package/dist/src/cli/run-options.js.map +1 -0
- package/dist/src/cli/run-overrides.js +51 -0
- package/dist/src/cli/run-overrides.js.map +1 -0
- package/dist/src/cli/settings.js +127 -0
- package/dist/src/cli/settings.js.map +1 -0
- package/dist/src/cli/summary.js +28 -0
- package/dist/src/cli/summary.js.map +1 -0
- package/dist/src/cli.js +20 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/contract-types.js +2 -0
- package/dist/src/contract-types.js.map +1 -0
- package/dist/src/engine.js +4 -0
- package/dist/src/engine.js.map +1 -0
- package/dist/src/evaluation/advisory.js +85 -0
- package/dist/src/evaluation/advisory.js.map +1 -0
- package/dist/src/evaluation/check-plan.js +292 -0
- package/dist/src/evaluation/check-plan.js.map +1 -0
- package/dist/src/evaluation/collection.js +61 -0
- package/dist/src/evaluation/collection.js.map +1 -0
- package/dist/src/evaluation/context.js +2 -0
- package/dist/src/evaluation/context.js.map +1 -0
- package/dist/src/evaluation/grading-host.js +28 -0
- package/dist/src/evaluation/grading-host.js.map +1 -0
- package/dist/src/evaluation/grading.js +154 -0
- package/dist/src/evaluation/grading.js.map +1 -0
- package/dist/src/evaluation/invocation-plan.js +312 -0
- package/dist/src/evaluation/invocation-plan.js.map +1 -0
- package/dist/src/evaluation/plan.js +376 -0
- package/dist/src/evaluation/plan.js.map +1 -0
- package/dist/src/evaluation/progress.js +14 -0
- package/dist/src/evaluation/progress.js.map +1 -0
- package/dist/src/evaluation/resources.js +159 -0
- package/dist/src/evaluation/resources.js.map +1 -0
- package/dist/src/evaluation/run.js +148 -0
- package/dist/src/evaluation/run.js.map +1 -0
- package/dist/src/evaluation/scheduler.js +27 -0
- package/dist/src/evaluation/scheduler.js.map +1 -0
- package/dist/src/evaluation/semantic.js +183 -0
- package/dist/src/evaluation/semantic.js.map +1 -0
- package/dist/src/evaluation/trial.js +593 -0
- package/dist/src/evaluation/trial.js.map +1 -0
- package/dist/src/evaluation/types.js +20 -0
- package/dist/src/evaluation/types.js.map +1 -0
- package/dist/src/evidence/host-results.js +67 -0
- package/dist/src/evidence/host-results.js.map +1 -0
- package/dist/src/evidence/retained-artifacts.js +17 -0
- package/dist/src/evidence/retained-artifacts.js.map +1 -0
- package/dist/src/evidence/trial-writer.js +131 -0
- package/dist/src/evidence/trial-writer.js.map +1 -0
- package/dist/src/evidence/usage.js +14 -0
- package/dist/src/evidence/usage.js.map +1 -0
- package/dist/src/executable.js +20 -0
- package/dist/src/executable.js.map +1 -0
- package/dist/src/extension-client.js +212 -0
- package/dist/src/extension-client.js.map +1 -0
- package/dist/src/extension-session.js +236 -0
- package/dist/src/extension-session.js.map +1 -0
- package/dist/src/fixtures/advisory.js +206 -0
- package/dist/src/fixtures/advisory.js.map +1 -0
- package/dist/src/fixtures/bin.js +41 -0
- package/dist/src/fixtures/bin.js.map +1 -0
- package/dist/src/fixtures/cleanup.js +43 -0
- package/dist/src/fixtures/cleanup.js.map +1 -0
- package/dist/src/fixtures/create.js +94 -0
- package/dist/src/fixtures/create.js.map +1 -0
- package/dist/src/fixtures/generated.js +181 -0
- package/dist/src/fixtures/generated.js.map +1 -0
- package/dist/src/fixtures/git-hooks.js +16 -0
- package/dist/src/fixtures/git-hooks.js.map +1 -0
- package/dist/src/fixtures/preparation.js +201 -0
- package/dist/src/fixtures/preparation.js.map +1 -0
- package/dist/src/fixtures/repository.js +255 -0
- package/dist/src/fixtures/repository.js.map +1 -0
- package/dist/src/fixtures/setup.js +175 -0
- package/dist/src/fixtures/setup.js.map +1 -0
- package/dist/src/fixtures/tools.js +57 -0
- package/dist/src/fixtures/tools.js.map +1 -0
- package/dist/src/fixtures/workspace-state.js +155 -0
- package/dist/src/fixtures/workspace-state.js.map +1 -0
- package/dist/src/generated/cli-result.cjs +2 -0
- package/dist/src/generated/extension.cjs +2 -0
- package/dist/src/generated/report.cjs +2 -0
- package/dist/src/generated/run-evidence.cjs +2 -0
- package/dist/src/generated/runtime.cjs +2 -0
- package/dist/src/git.js +72 -0
- package/dist/src/git.js.map +1 -0
- package/dist/src/graders/artifact.js +68 -0
- package/dist/src/graders/artifact.js.map +1 -0
- package/dist/src/graders/git-head.js +112 -0
- package/dist/src/graders/git-head.js.map +1 -0
- package/dist/src/graders/output.js +345 -0
- package/dist/src/graders/output.js.map +1 -0
- package/dist/src/graders/semantic.js +132 -0
- package/dist/src/graders/semantic.js.map +1 -0
- package/dist/src/graders/shell.js +321 -0
- package/dist/src/graders/shell.js.map +1 -0
- package/dist/src/host-diagnostic-redaction.js +52 -0
- package/dist/src/host-diagnostic-redaction.js.map +1 -0
- package/dist/src/host-diagnostics.js +248 -0
- package/dist/src/host-diagnostics.js.map +1 -0
- package/dist/src/hosts/claude-continuation.js +89 -0
- package/dist/src/hosts/claude-continuation.js.map +1 -0
- package/dist/src/hosts/claude-credential.js +121 -0
- package/dist/src/hosts/claude-credential.js.map +1 -0
- package/dist/src/hosts/claude-events.js +136 -0
- package/dist/src/hosts/claude-events.js.map +1 -0
- package/dist/src/hosts/claude-keychain.js +100 -0
- package/dist/src/hosts/claude-keychain.js.map +1 -0
- package/dist/src/hosts/claude-login-recovery.js +67 -0
- package/dist/src/hosts/claude-login-recovery.js.map +1 -0
- package/dist/src/hosts/claude-login-refresh.js +146 -0
- package/dist/src/hosts/claude-login-refresh.js.map +1 -0
- package/dist/src/hosts/claude-login-store.js +124 -0
- package/dist/src/hosts/claude-login-store.js.map +1 -0
- package/dist/src/hosts/claude-login.js +74 -0
- package/dist/src/hosts/claude-login.js.map +1 -0
- package/dist/src/hosts/claude-native-goal.js +138 -0
- package/dist/src/hosts/claude-native-goal.js.map +1 -0
- package/dist/src/hosts/claude-process.js +10 -0
- package/dist/src/hosts/claude-process.js.map +1 -0
- package/dist/src/hosts/claude-refresh-lock.js +76 -0
- package/dist/src/hosts/claude-refresh-lock.js.map +1 -0
- package/dist/src/hosts/claude-repository-invocation.js +229 -0
- package/dist/src/hosts/claude-repository-invocation.js.map +1 -0
- package/dist/src/hosts/claude-settings.js +158 -0
- package/dist/src/hosts/claude-settings.js.map +1 -0
- package/dist/src/hosts/claude-skill-activations.js +131 -0
- package/dist/src/hosts/claude-skill-activations.js.map +1 -0
- package/dist/src/hosts/claude-state.js +237 -0
- package/dist/src/hosts/claude-state.js.map +1 -0
- package/dist/src/hosts/claude-tool-calls.js +150 -0
- package/dist/src/hosts/claude-tool-calls.js.map +1 -0
- package/dist/src/hosts/claude.js +373 -0
- package/dist/src/hosts/claude.js.map +1 -0
- package/dist/src/hosts/codex-app-server.js +764 -0
- package/dist/src/hosts/codex-app-server.js.map +1 -0
- package/dist/src/hosts/codex-configuration.js +91 -0
- package/dist/src/hosts/codex-configuration.js.map +1 -0
- package/dist/src/hosts/codex-events.js +104 -0
- package/dist/src/hosts/codex-events.js.map +1 -0
- package/dist/src/hosts/codex-exec-controls.js +434 -0
- package/dist/src/hosts/codex-exec-controls.js.map +1 -0
- package/dist/src/hosts/codex-invocation.js +54 -0
- package/dist/src/hosts/codex-invocation.js.map +1 -0
- package/dist/src/hosts/codex-marketplace.js +185 -0
- package/dist/src/hosts/codex-marketplace.js.map +1 -0
- package/dist/src/hosts/codex-native-calls.js +516 -0
- package/dist/src/hosts/codex-native-calls.js.map +1 -0
- package/dist/src/hosts/codex-process.js +10 -0
- package/dist/src/hosts/codex-process.js.map +1 -0
- package/dist/src/hosts/codex-profile.js +206 -0
- package/dist/src/hosts/codex-profile.js.map +1 -0
- package/dist/src/hosts/codex-session-files.js +89 -0
- package/dist/src/hosts/codex-session-files.js.map +1 -0
- package/dist/src/hosts/codex-state.js +310 -0
- package/dist/src/hosts/codex-state.js.map +1 -0
- package/dist/src/hosts/codex.js +527 -0
- package/dist/src/hosts/codex.js.map +1 -0
- package/dist/src/hosts/isolation-common.js +43 -0
- package/dist/src/hosts/isolation-common.js.map +1 -0
- package/dist/src/hosts/isolation-roots.js +64 -0
- package/dist/src/hosts/isolation-roots.js.map +1 -0
- package/dist/src/hosts/isolation.js +12 -0
- package/dist/src/hosts/isolation.js.map +1 -0
- package/dist/src/hosts/linux-sandbox.js +127 -0
- package/dist/src/hosts/linux-sandbox.js.map +1 -0
- package/dist/src/hosts/mac-sandbox.js +137 -0
- package/dist/src/hosts/mac-sandbox.js.map +1 -0
- package/dist/src/hosts/native-controls.js +151 -0
- package/dist/src/hosts/native-controls.js.map +1 -0
- package/dist/src/hosts/native-request.js +33 -0
- package/dist/src/hosts/native-request.js.map +1 -0
- package/dist/src/hosts/process-lifecycle.js +167 -0
- package/dist/src/hosts/process-lifecycle.js.map +1 -0
- package/dist/src/hosts/protected-worktrees.js +81 -0
- package/dist/src/hosts/protected-worktrees.js.map +1 -0
- package/dist/src/hosts/skill-hook-catalog.js +100 -0
- package/dist/src/hosts/skill-hook-catalog.js.map +1 -0
- package/dist/src/hosts/skill-hook-handler.js +228 -0
- package/dist/src/hosts/skill-hook-handler.js.map +1 -0
- package/dist/src/hosts/skill-hooks.js +423 -0
- package/dist/src/hosts/skill-hooks.js.map +1 -0
- package/dist/src/hosts/workspace-fingerprint.js +72 -0
- package/dist/src/hosts/workspace-fingerprint.js.map +1 -0
- package/dist/src/identity.js +167 -0
- package/dist/src/identity.js.map +1 -0
- package/dist/src/instrumentation.js +83 -0
- package/dist/src/instrumentation.js.map +1 -0
- package/dist/src/native-transcript-state.js +85 -0
- package/dist/src/native-transcript-state.js.map +1 -0
- package/dist/src/native-transcript-view.js +65 -0
- package/dist/src/native-transcript-view.js.map +1 -0
- package/dist/src/native-transcripts.js +208 -0
- package/dist/src/native-transcripts.js.map +1 -0
- package/dist/src/paths.js +13 -0
- package/dist/src/paths.js.map +1 -0
- package/dist/src/process-lifecycle.js +101 -0
- package/dist/src/process-lifecycle.js.map +1 -0
- package/dist/src/provenance.js +263 -0
- package/dist/src/provenance.js.map +1 -0
- package/dist/src/prune.js +228 -0
- package/dist/src/prune.js.map +1 -0
- package/dist/src/report.js +276 -0
- package/dist/src/report.js.map +1 -0
- package/dist/src/resolved-case.js +29 -0
- package/dist/src/resolved-case.js.map +1 -0
- package/dist/src/results-lock.js +40 -0
- package/dist/src/results-lock.js.map +1 -0
- package/dist/src/results.js +127 -0
- package/dist/src/results.js.map +1 -0
- package/dist/src/run-owner.js +283 -0
- package/dist/src/run-owner.js.map +1 -0
- package/dist/src/runner-paths.js +11 -0
- package/dist/src/runner-paths.js.map +1 -0
- package/dist/src/runtime/config.js +323 -0
- package/dist/src/runtime/config.js.map +1 -0
- package/dist/src/runtime/discovery-apple.js +65 -0
- package/dist/src/runtime/discovery-apple.js.map +1 -0
- package/dist/src/runtime/discovery-providers.js +37 -0
- package/dist/src/runtime/discovery-providers.js.map +1 -0
- package/dist/src/runtime/discovery.js +40 -0
- package/dist/src/runtime/discovery.js.map +1 -0
- package/dist/src/runtime/hook-processes.js +81 -0
- package/dist/src/runtime/hook-processes.js.map +1 -0
- package/dist/src/runtime/hooks.js +304 -0
- package/dist/src/runtime/hooks.js.map +1 -0
- package/dist/src/runtime/paths.js +244 -0
- package/dist/src/runtime/paths.js.map +1 -0
- package/dist/src/runtime/query.js +76 -0
- package/dist/src/runtime/query.js.map +1 -0
- package/dist/src/runtime/seeds.js +98 -0
- package/dist/src/runtime/seeds.js.map +1 -0
- package/dist/src/runtime/shared-cache.js +81 -0
- package/dist/src/runtime/shared-cache.js.map +1 -0
- package/dist/src/runtime/state.js +106 -0
- package/dist/src/runtime/state.js.map +1 -0
- package/dist/src/runtime-process.js +148 -0
- package/dist/src/runtime-process.js.map +1 -0
- package/dist/src/schema-types.js +2 -0
- package/dist/src/schema-types.js.map +1 -0
- package/dist/src/schema.js +16 -0
- package/dist/src/schema.js.map +1 -0
- package/dist/src/shell.js +5 -0
- package/dist/src/shell.js.map +1 -0
- package/dist/src/sqlite-lock.js +18 -0
- package/dist/src/sqlite-lock.js.map +1 -0
- package/dist/src/storage.js +21 -0
- package/dist/src/storage.js.map +1 -0
- package/dist/src/transcript-retention.js +109 -0
- package/dist/src/transcript-retention.js.map +1 -0
- package/dist/src/value-guards.js +26 -0
- package/dist/src/value-guards.js.map +1 -0
- package/docs/architecture.md +5 -2
- package/docs/creating-cases.md +2 -3
- package/docs/development-cli.md +12 -7
- package/docs/documentation-quality.md +4 -3
- package/docs/evaluation-workflow.md +8 -8
- package/docs/getting-started.md +7 -6
- package/docs/guide-evaluation.md +1 -1
- package/docs/identity-v1.md +4 -1
- package/docs/installing.md +31 -13
- package/docs/licensing.md +2 -2
- package/docs/native-hosts.md +1 -1
- package/docs/recipes.md +41 -40
- package/docs/releases.md +20 -4
- package/docs/run-settings-v1.md +3 -3
- package/docs/specs/repository-guide.md +1 -1
- package/docs/troubleshooting.md +1 -1
- package/docs/typescript-quality.md +18 -1
- package/examples/recipes/executable.ts +19 -0
- package/examples/recipes/extension-artifacts.ts +1 -1
- package/examples/recipes/extension.ts +2 -1
- package/examples/recipes/modules.ts +9 -0
- package/examples/recipes/run-inputs.ts +14 -19
- package/examples/recipes/run-options.ts +9 -8
- package/examples/recipes/run.ts +21 -7
- package/examples/templates/repository-skill/extension-data.ts +1 -1
- package/examples/templates/repository-skill/extension.ts +2 -1
- package/package.json +14 -6
- package/src/cli/demo.ts +3 -2
- package/src/cli/help.ts +4 -3
- package/src/cli/init-settings.ts +5 -4
- package/src/cli/init.ts +9 -8
- package/src/cli/invocation.ts +2 -1
- package/src/cli/preparation.ts +2 -2
- package/src/cli.ts +1 -1
- package/src/executable.ts +19 -0
- package/src/extension-client.ts +6 -12
- package/src/fixtures/setup.ts +3 -2
- package/src/git.ts +2 -1
- package/src/graders/git-head.ts +3 -2
- package/src/graders/shell.ts +4 -3
- package/src/hosts/claude-keychain.ts +3 -2
- package/src/hosts/claude-login-refresh.ts +3 -2
- package/src/hosts/claude-refresh-lock.ts +2 -1
- package/src/hosts/claude-settings.ts +3 -1
- package/src/hosts/claude.ts +1 -1
- package/src/hosts/isolation-roots.ts +3 -2
- package/src/hosts/process-lifecycle.ts +4 -6
- package/src/hosts/protected-worktrees.ts +2 -1
- package/src/hosts/skill-hook-handler.ts +1 -1
- package/src/hosts/skill-hooks.ts +10 -2
- package/src/provenance.ts +7 -6
- package/src/results-lock.ts +4 -4
- package/src/run-owner.ts +15 -9
- package/src/runner-paths.ts +21 -0
- package/src/runtime/hook-processes.ts +2 -1
- package/src/runtime/hooks.ts +9 -7
- package/src/runtime-process.ts +194 -0
- package/src/sqlite-lock.ts +25 -0
package/src/results-lock.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { openLockDatabase } from "./sqlite-lock";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { lstat } from "node:fs/promises";
|
|
4
4
|
|
|
@@ -28,10 +28,10 @@ export async function withResultsLock<T>(
|
|
|
28
28
|
/** Hold a root lock while discovering and validating additional nested roots. */
|
|
29
29
|
export async function acquireResultsLock(root: string): Promise<() => void> {
|
|
30
30
|
await retainedFile(join(root, ".retention-lock.sqlite"));
|
|
31
|
-
const database =
|
|
31
|
+
const database = openLockDatabase(join(root, ".retention-lock.sqlite"));
|
|
32
32
|
try {
|
|
33
|
-
database.
|
|
34
|
-
database.
|
|
33
|
+
database.exec("PRAGMA busy_timeout = 5000");
|
|
34
|
+
database.exec("BEGIN IMMEDIATE");
|
|
35
35
|
return () => {
|
|
36
36
|
database.close();
|
|
37
37
|
};
|
package/src/run-owner.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { spawnSync } from "./runtime-process";
|
|
1
2
|
import { isRecord } from "./value-guards";
|
|
2
|
-
import {
|
|
3
|
+
import { openLockDatabase } from "./sqlite-lock";
|
|
3
4
|
import { randomUUID } from "node:crypto";
|
|
4
5
|
import {
|
|
5
6
|
mkdirSync,
|
|
@@ -115,11 +116,16 @@ function atomicJson(path: string, value: unknown): void {
|
|
|
115
116
|
function withClaimLock<T>(claimPath: string, action: () => T): T {
|
|
116
117
|
const locks = join(dirname(dirname(claimPath)), "locks");
|
|
117
118
|
mkdirSync(locks, { recursive: true, mode: 0o700 });
|
|
118
|
-
const database =
|
|
119
|
+
const database = openLockDatabase(
|
|
120
|
+
join(locks, `${basename(claimPath)}.sqlite`),
|
|
121
|
+
);
|
|
119
122
|
try {
|
|
120
|
-
database.
|
|
121
|
-
database.
|
|
122
|
-
|
|
123
|
+
database.exec("PRAGMA busy_timeout = 5000");
|
|
124
|
+
database.exec("CREATE TABLE IF NOT EXISTS mutex (id INTEGER PRIMARY KEY)");
|
|
125
|
+
database.exec("BEGIN IMMEDIATE");
|
|
126
|
+
const result = action();
|
|
127
|
+
database.exec("COMMIT");
|
|
128
|
+
return result;
|
|
123
129
|
} finally {
|
|
124
130
|
database.close();
|
|
125
131
|
}
|
|
@@ -159,16 +165,16 @@ function identityEnvironment(windows: boolean) {
|
|
|
159
165
|
: { PATH: "/usr/bin:/bin", LC_ALL: "C" };
|
|
160
166
|
}
|
|
161
167
|
|
|
162
|
-
function processStartTime(result: ReturnType<typeof
|
|
163
|
-
return result.stdout
|
|
168
|
+
function processStartTime(result: ReturnType<typeof spawnSync>): string {
|
|
169
|
+
return result.stdout.toString().trim();
|
|
164
170
|
}
|
|
165
171
|
|
|
166
172
|
export function processIdentity(pid: number): ProcessIdentity | null {
|
|
167
173
|
const windows = process.platform === "win32";
|
|
168
174
|
const argv = identityCommand(pid, windows);
|
|
169
|
-
let result: ReturnType<typeof
|
|
175
|
+
let result: ReturnType<typeof spawnSync>;
|
|
170
176
|
try {
|
|
171
|
-
result =
|
|
177
|
+
result = spawnSync(argv, {
|
|
172
178
|
env: identityEnvironment(windows),
|
|
173
179
|
stdout: "pipe",
|
|
174
180
|
stderr: "ignore",
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { resolve, join } from "node:path";
|
|
2
|
+
|
|
3
|
+
export const sourceRuntime = import.meta.filename.endsWith(".ts");
|
|
4
|
+
export const runnerRoot = resolve(
|
|
5
|
+
import.meta.dirname,
|
|
6
|
+
sourceRuntime ? ".." : "../..",
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
export function examplePath(...parts: string[]): string {
|
|
10
|
+
const path = join(
|
|
11
|
+
runnerRoot,
|
|
12
|
+
...(sourceRuntime ? [] : ["dist"]),
|
|
13
|
+
"examples",
|
|
14
|
+
...parts,
|
|
15
|
+
);
|
|
16
|
+
return runtimeModule(path);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function runtimeModule(path: string): string {
|
|
20
|
+
return sourceRuntime ? path : path.replace(/\.ts$/, ".js");
|
|
21
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { spawn } from "../runtime-process";
|
|
1
2
|
import { readFile, readdir, writeFile } from "node:fs/promises";
|
|
2
3
|
import { basename, dirname, join } from "node:path";
|
|
3
4
|
import { isRecord } from "../value-guards";
|
|
@@ -22,7 +23,7 @@ export async function hookExecutions(
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
async function processOutput(argv: string[]): Promise<string> {
|
|
25
|
-
const child =
|
|
26
|
+
const child = spawn(argv, { stdout: "pipe", stderr: "ignore" });
|
|
26
27
|
const output = await new Response(child.stdout).text();
|
|
27
28
|
await child.exited;
|
|
28
29
|
if (Buffer.byteLength(output) > 1024 * 1024)
|
package/src/runtime/hooks.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
2
|
+
import { existsSync } from "node:fs";
|
|
1
3
|
import {
|
|
2
4
|
cp,
|
|
3
5
|
mkdir,
|
|
@@ -253,23 +255,23 @@ async function rewritePlugin(
|
|
|
253
255
|
manifest: Record<string, unknown>,
|
|
254
256
|
state: HookRewrite,
|
|
255
257
|
): Promise<void> {
|
|
256
|
-
|
|
258
|
+
requireHookOnlyPlugin(state.root);
|
|
257
259
|
await rewriteManifest(manifest, state, ".claude-plugin/plugin.json");
|
|
258
260
|
const native = join(state.root, ".codex-plugin/plugin.json");
|
|
259
|
-
if (
|
|
261
|
+
if (existsSync(native))
|
|
260
262
|
await rewriteManifest(
|
|
261
263
|
object(JSON.parse(await readFile(native, "utf8"))),
|
|
262
264
|
state,
|
|
263
265
|
".codex-plugin/plugin.json",
|
|
264
266
|
);
|
|
265
267
|
const standard = join(state.root, "hooks/hooks.json");
|
|
266
|
-
if (
|
|
268
|
+
if (existsSync(standard)) await hookFile(standard, state);
|
|
267
269
|
await rewriteFrontmatter(state.root, state);
|
|
268
270
|
}
|
|
269
271
|
|
|
270
|
-
|
|
272
|
+
function requireHookOnlyPlugin(root: string): void {
|
|
271
273
|
for (const name of [".mcp.json", ".lsp.json"])
|
|
272
|
-
if (
|
|
274
|
+
if (existsSync(join(root, name)))
|
|
273
275
|
throw new Error("runtime auxiliary plugin execution is unsupported");
|
|
274
276
|
}
|
|
275
277
|
|
|
@@ -432,7 +434,7 @@ async function rewriteMarkdown(
|
|
|
432
434
|
else delete metadata.hooks;
|
|
433
435
|
await writeFile(
|
|
434
436
|
path,
|
|
435
|
-
`---\n${
|
|
437
|
+
`---\n${stringifyYaml(metadata)}\n---\n${body.slice(header[0].length)}`,
|
|
436
438
|
);
|
|
437
439
|
}
|
|
438
440
|
|
|
@@ -440,7 +442,7 @@ function hookFrontmatter(
|
|
|
440
442
|
header: string | undefined,
|
|
441
443
|
): Record<string, unknown> | undefined {
|
|
442
444
|
if (!header?.includes("hooks")) return undefined;
|
|
443
|
-
const metadata = object(
|
|
445
|
+
const metadata = object(parseYaml(header));
|
|
444
446
|
return metadata.hooks === undefined ? undefined : metadata;
|
|
445
447
|
}
|
|
446
448
|
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import {
|
|
2
|
+
spawn as nodeSpawn,
|
|
3
|
+
spawnSync as nodeSpawnSync,
|
|
4
|
+
type ChildProcess,
|
|
5
|
+
} from "node:child_process";
|
|
6
|
+
import { Readable, Writable } from "node:stream";
|
|
7
|
+
import { constants } from "node:os";
|
|
8
|
+
|
|
9
|
+
interface ProcessWriter {
|
|
10
|
+
write(data: string | Uint8Array): unknown;
|
|
11
|
+
end(): unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Subprocess {
|
|
15
|
+
pid: number;
|
|
16
|
+
stdin: ProcessWriter | null;
|
|
17
|
+
stdout: ReadableStream<Uint8Array>;
|
|
18
|
+
stderr: ReadableStream<Uint8Array>;
|
|
19
|
+
exited: Promise<number>;
|
|
20
|
+
readonly signalCode: string | null;
|
|
21
|
+
kill(signal: NodeJS.Signals): void;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface SpawnOptions {
|
|
25
|
+
cwd?: string;
|
|
26
|
+
env?: NodeJS.ProcessEnv;
|
|
27
|
+
detached?: boolean;
|
|
28
|
+
stdin?: "pipe" | "ignore" | Uint8Array;
|
|
29
|
+
stdout?: "pipe" | "ignore";
|
|
30
|
+
stderr?: "pipe" | "ignore";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function emptyStream(): ReadableStream<Uint8Array> {
|
|
34
|
+
return new ReadableStream({
|
|
35
|
+
start(controller) {
|
|
36
|
+
controller.close();
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function readable(stream: Readable | null): ReadableStream<Uint8Array> {
|
|
42
|
+
// Node and Bun declare different overloads for the same Web Streams API.
|
|
43
|
+
return stream
|
|
44
|
+
? (Readable.toWeb(stream) as unknown as ReadableStream<Uint8Array>)
|
|
45
|
+
: emptyStream();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function output(
|
|
49
|
+
stream: ReadableStream<Uint8Array> | null | undefined,
|
|
50
|
+
): ReadableStream<Uint8Array> {
|
|
51
|
+
return stream ?? emptyStream();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function writer(stream: Writable | null): ProcessWriter | null {
|
|
55
|
+
if (!stream) return null;
|
|
56
|
+
const destination = Writable.toWeb(stream).getWriter();
|
|
57
|
+
return {
|
|
58
|
+
write: (data) =>
|
|
59
|
+
destination.write(typeof data === "string" ? Buffer.from(data) : data),
|
|
60
|
+
end: () => destination.close(),
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function commandName(argv: string[]): string {
|
|
65
|
+
const name = argv[0];
|
|
66
|
+
if (!name) throw new Error("process command must be nonempty");
|
|
67
|
+
return name;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function stdinMode(input: SpawnOptions["stdin"]) {
|
|
71
|
+
return input === "pipe" || input instanceof Uint8Array ? "pipe" : "ignore";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function processId(child: ChildProcess): number {
|
|
75
|
+
if (child.pid !== undefined) return child.pid;
|
|
76
|
+
child.once("error", () => {});
|
|
77
|
+
throw new Error("could not start process");
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function exitCode(code: number | null, signal: NodeJS.Signals | null): number {
|
|
81
|
+
return code ?? 128 + (signal ? constants.signals[signal] : 0);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function completion(child: ChildProcess): Promise<number> {
|
|
85
|
+
return new Promise((resolve, reject) => {
|
|
86
|
+
child.once("error", reject);
|
|
87
|
+
child.once("exit", (code, signal) => {
|
|
88
|
+
resolve(exitCode(code, signal));
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function initialInput(
|
|
94
|
+
stdin: ProcessWriter | null,
|
|
95
|
+
input: SpawnOptions["stdin"],
|
|
96
|
+
) {
|
|
97
|
+
if (!(input instanceof Uint8Array)) return;
|
|
98
|
+
if (!stdin) throw new Error("process input pipe unavailable");
|
|
99
|
+
await stdin.write(input);
|
|
100
|
+
await stdin.end();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function nodeProcess(argv: string[], options: SpawnOptions): Subprocess {
|
|
104
|
+
const child = nodeSpawn(commandName(argv), argv.slice(1), {
|
|
105
|
+
cwd: options.cwd,
|
|
106
|
+
env: options.env,
|
|
107
|
+
detached: options.detached,
|
|
108
|
+
stdio: [
|
|
109
|
+
stdinMode(options.stdin),
|
|
110
|
+
options.stdout ?? "pipe",
|
|
111
|
+
options.stderr ?? "pipe",
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
const pid = processId(child);
|
|
115
|
+
const exited = completion(child);
|
|
116
|
+
const stdin = writer(child.stdin);
|
|
117
|
+
return {
|
|
118
|
+
pid,
|
|
119
|
+
stdin,
|
|
120
|
+
stdout: readable(child.stdout),
|
|
121
|
+
stderr: readable(child.stderr),
|
|
122
|
+
exited: Promise.all([exited, initialInput(stdin, options.stdin)]).then(
|
|
123
|
+
([code]) => code,
|
|
124
|
+
),
|
|
125
|
+
get signalCode() {
|
|
126
|
+
return child.signalCode;
|
|
127
|
+
},
|
|
128
|
+
kill(signal) {
|
|
129
|
+
child.kill(signal);
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function bunProcess(argv: string[], options: SpawnOptions): Subprocess {
|
|
135
|
+
const child = Bun.spawn(argv, {
|
|
136
|
+
...options,
|
|
137
|
+
stdin: options.stdin ?? "ignore",
|
|
138
|
+
stderr: options.stderr ?? "pipe",
|
|
139
|
+
});
|
|
140
|
+
return {
|
|
141
|
+
pid: child.pid,
|
|
142
|
+
stdin: typeof child.stdin === "object" ? child.stdin : null,
|
|
143
|
+
stdout: output(child.stdout),
|
|
144
|
+
stderr: output(child.stderr),
|
|
145
|
+
exited: child.exited,
|
|
146
|
+
get signalCode() {
|
|
147
|
+
return child.signalCode ?? null;
|
|
148
|
+
},
|
|
149
|
+
kill(signal) {
|
|
150
|
+
child.kill(signal);
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/** Keep the runner's process/stream contract independent of its JS runtime. */
|
|
156
|
+
export function spawn(argv: string[], options: SpawnOptions = {}): Subprocess {
|
|
157
|
+
return process.versions.bun
|
|
158
|
+
? bunProcess(argv, options)
|
|
159
|
+
: nodeProcess(argv, options);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
function buffer(bytes: Buffer | null | undefined): Buffer {
|
|
163
|
+
return bytes ?? Buffer.alloc(0);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
function bunSync(argv: string[], options: SpawnOptions) {
|
|
167
|
+
const result = Bun.spawnSync(argv, options);
|
|
168
|
+
return {
|
|
169
|
+
exitCode: result.exitCode,
|
|
170
|
+
stdout: buffer(result.stdout),
|
|
171
|
+
stderr: buffer(result.stderr),
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function nodeSync(argv: string[], options: SpawnOptions) {
|
|
176
|
+
const result = nodeSpawnSync(commandName(argv), argv.slice(1), {
|
|
177
|
+
cwd: options.cwd,
|
|
178
|
+
env: options.env,
|
|
179
|
+
stdio: ["ignore", options.stdout ?? "pipe", options.stderr ?? "pipe"],
|
|
180
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
181
|
+
});
|
|
182
|
+
if (result.error) throw result.error;
|
|
183
|
+
return {
|
|
184
|
+
exitCode: result.status ?? 1,
|
|
185
|
+
stdout: buffer(result.stdout),
|
|
186
|
+
stderr: buffer(result.stderr),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function spawnSync(argv: string[], options: SpawnOptions = {}) {
|
|
191
|
+
return process.versions.bun
|
|
192
|
+
? bunSync(argv, options)
|
|
193
|
+
: nodeSync(argv, options);
|
|
194
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
|
|
5
|
+
interface LockDatabase {
|
|
6
|
+
exec(sql: string): unknown;
|
|
7
|
+
close(): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/** Both drivers use SQLite file locks, including across Node and Bun runners. */
|
|
11
|
+
export function openLockDatabase(path: string): LockDatabase {
|
|
12
|
+
if (process.versions.bun) {
|
|
13
|
+
const { Database } = require("bun:sqlite") as typeof import("bun:sqlite");
|
|
14
|
+
const database = new Database(path);
|
|
15
|
+
return {
|
|
16
|
+
exec: (sql) => database.run(sql),
|
|
17
|
+
close() {
|
|
18
|
+
database.close();
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const { DatabaseSync } =
|
|
23
|
+
require("node:sqlite") as typeof import("node:sqlite");
|
|
24
|
+
return new DatabaseSync(path);
|
|
25
|
+
}
|