@bjoernrochel/sevro 0.1.0-rc.2 → 0.1.0-rc.21
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 +170 -0
- package/LICENSE +63 -136
- package/README.md +83 -66
- package/docs/README.md +44 -0
- package/docs/acknowledgements.md +14 -0
- package/docs/architecture.md +146 -0
- package/docs/assets/README.md +27 -0
- package/docs/assets/sevro-logo.png +0 -0
- package/docs/assets/sevro-symbol.svg +1 -0
- package/docs/assets/sevro-wordmark.svg +1 -0
- package/docs/builtin-graders-v1.md +41 -13
- package/docs/codex-host.md +184 -52
- package/docs/contracts.md +19 -0
- package/docs/creating-cases.md +139 -0
- package/docs/development-cli.md +190 -30
- package/docs/documentation-quality.md +61 -0
- package/docs/evaluation-workflow.md +110 -0
- package/docs/evidence/code-mode-controls-71.md +64 -0
- package/docs/evidence/code-mode-programs-85.md +64 -0
- package/docs/evidence/codex-state-73/README.md +204 -0
- package/docs/evidence/codex-state-73/darrow-migration.patch +182 -0
- package/docs/evidence/codex-state-73/results.json +661 -0
- package/docs/evidence/local-http-74.md +104 -0
- package/docs/evidence/runtime-startup-30/README.md +185 -0
- package/docs/evidence/runtime-startup-30/after.json +319 -0
- package/docs/evidence/runtime-startup-30/baseline-timeout.jsonl +2 -0
- package/docs/evidence/runtime-startup-30/before.json +403 -0
- package/docs/evidence/runtime-startup-30/consumer-smoke.json +63 -0
- package/docs/evidence/runtime-startup-30/full-policy-diagnostic.jsonl +3 -0
- package/docs/evidence/runtime-startup-30/minimal-policy-diagnostic.jsonl +3 -0
- package/docs/evidence/runtime-startup-30/plugin-template-assessment.json +20 -0
- package/docs/evidence/runtime-startup-30/seedless-timeout.jsonl +2 -0
- package/docs/evidence/skill-reads-70/results.json +823 -0
- package/docs/evidence.md +21 -0
- package/docs/extension-protocol-v1.md +50 -16
- package/docs/fixture-cleanup-validation.md +3 -0
- package/docs/getting-started.md +102 -0
- package/docs/guide-evaluation.md +89 -0
- package/docs/guide-verification.json +239 -0
- package/docs/identity-v1.md +35 -1
- package/docs/installing.md +88 -0
- package/docs/licenses/BUSL-1.1-0.1.0-rc.2.txt +159 -0
- package/docs/licensing.md +42 -0
- package/docs/native-controls.md +76 -5
- package/docs/native-hosts.md +228 -0
- package/docs/reading-results.md +141 -0
- package/docs/recipes.md +489 -0
- package/docs/releases.md +81 -40
- package/docs/report-v1.md +29 -1
- package/docs/results-v1.md +180 -0
- package/docs/run-settings-v1.md +147 -0
- package/docs/running-evaluations.md +31 -0
- package/docs/runtime-v1.md +614 -0
- package/docs/specs/repository-guide.md +58 -0
- package/docs/troubleshooting.md +30 -0
- package/docs/typescript-quality.md +234 -0
- package/docs/usability-study.md +114 -0
- package/examples/basic/host.ts +2 -2
- package/examples/recipes/candidate.ts +26 -0
- package/examples/recipes/cases/coding-change.json +21 -0
- package/examples/recipes/cases/host-tools.json +21 -0
- package/examples/recipes/cases/mise.json +21 -0
- package/examples/recipes/cases/node.json +21 -0
- package/examples/recipes/cases/python-uv.json +21 -0
- package/examples/recipes/cases/semantic.json +17 -0
- package/examples/recipes/coding-change/check.ts +23 -0
- package/examples/recipes/extension-artifacts.ts +65 -0
- package/examples/recipes/extension-methods.ts +174 -0
- package/examples/recipes/extension.ts +37 -0
- package/examples/recipes/repository-skill/.agents/skills/startup-guide/SKILL.md +7 -0
- package/examples/recipes/repository-skill/.claude/skills/startup-guide/SKILL.md +7 -0
- package/examples/recipes/repository-skill/README.md +3 -0
- package/examples/recipes/run-inputs.ts +188 -0
- package/examples/recipes/run-options.ts +131 -0
- package/examples/recipes/run.ts +63 -0
- package/examples/recipes/runtime/empty.json +1 -0
- package/examples/recipes/runtime/goals.json +1 -0
- package/examples/recipes/runtime/mise.json +6 -0
- package/examples/recipes/runtime/path.json +1 -0
- package/examples/recipes/runtime/plugins.json +4 -0
- package/examples/recipes/runtime/python-uv.json +10 -0
- package/examples/recipes/semantic-judge.ts +29 -0
- package/examples/templates/coding/adapter.ts +17 -0
- package/examples/templates/coding/case.json +15 -0
- package/examples/templates/repository-skill/.agents/skills/startup-guide/SKILL.md +6 -0
- package/examples/templates/repository-skill/extension-data.ts +64 -0
- package/examples/templates/repository-skill/extension.ts +31 -0
- package/examples/templates/response/adapter.ts +12 -0
- package/examples/templates/response/case.json +13 -0
- package/package.json +39 -6
- package/schemas/report-v1.schema.json +9 -0
- package/schemas/run-evidence-v1.schema.json +2 -1
- package/schemas/runtime-v1.schema.json +193 -0
- package/src/advisory.ts +10 -5
- package/src/candidate-artifacts.ts +208 -0
- package/src/candidate-codex-state.ts +185 -0
- package/src/case-validation.ts +105 -0
- package/src/cli/cancellation.ts +20 -0
- package/src/cli/command.ts +81 -0
- package/src/cli/completion.ts +15 -0
- package/src/cli/demo.ts +59 -0
- package/src/cli/evaluation.ts +55 -0
- package/src/cli/extension.ts +79 -0
- package/src/cli/help.ts +222 -0
- package/src/cli/hosts.ts +59 -0
- package/src/cli/init-settings.ts +30 -0
- package/src/cli/init.ts +111 -0
- package/src/cli/invocation.ts +627 -0
- package/src/cli/loading.ts +151 -0
- package/src/cli/preparation.ts +163 -0
- package/src/cli/presentation.ts +91 -0
- package/src/cli/progress.ts +6 -0
- package/src/cli/run-manifest.ts +133 -0
- package/src/cli/run-options.ts +101 -0
- package/src/cli/run-overrides.ts +83 -0
- package/src/cli/settings.ts +160 -0
- package/src/cli/summary.ts +43 -0
- package/src/cli.ts +13 -843
- package/src/contract-types.ts +94 -0
- package/src/engine.ts +19 -2373
- package/src/evaluation/advisory.ts +150 -0
- package/src/evaluation/check-plan.ts +510 -0
- package/src/evaluation/collection.ts +88 -0
- package/src/evaluation/context.ts +10 -0
- package/src/evaluation/grading-host.ts +39 -0
- package/src/evaluation/grading.ts +258 -0
- package/src/evaluation/invocation-plan.ts +548 -0
- package/src/evaluation/plan.ts +736 -0
- package/src/evaluation/progress.ts +19 -0
- package/src/evaluation/resources.ts +241 -0
- package/src/evaluation/run.ts +206 -0
- package/src/{trial-scheduler.ts → evaluation/scheduler.ts} +3 -1
- package/src/evaluation/semantic.ts +312 -0
- package/src/evaluation/trial.ts +866 -0
- package/src/evaluation/types.ts +207 -0
- package/src/evidence/host-results.ts +92 -0
- package/src/evidence/retained-artifacts.ts +18 -0
- package/src/evidence/trial-writer.ts +203 -0
- package/src/evidence/usage.ts +17 -0
- package/src/extension-client.ts +228 -148
- package/src/extension-session.ts +326 -195
- package/src/fixtures/advisory.ts +338 -0
- package/src/fixtures/bin.ts +57 -0
- package/src/{fixture-cleanup.ts → fixtures/cleanup.ts} +13 -7
- package/src/fixtures/create.ts +187 -0
- package/src/fixtures/generated.ts +300 -0
- package/src/fixtures/git-hooks.ts +24 -0
- package/src/fixtures/preparation.ts +270 -0
- package/src/{repository-fixture.ts → fixtures/repository.ts} +207 -85
- package/src/fixtures/setup.ts +224 -0
- package/src/fixtures/tools.ts +88 -0
- package/src/fixtures/workspace-state.ts +212 -0
- package/src/generated/cli-result.cjs +2 -0
- package/src/generated/cli-result.d.cts +3 -0
- package/src/generated/extension.cjs +2 -0
- package/src/generated/extension.d.cts +3 -0
- package/src/generated/report.cjs +2 -0
- package/src/generated/report.d.cts +3 -0
- package/src/generated/run-evidence.cjs +2 -0
- package/src/generated/run-evidence.d.cts +3 -0
- package/src/generated/runtime.cjs +2 -0
- package/src/generated/runtime.d.cts +3 -0
- package/src/graders/artifact.ts +56 -23
- package/src/graders/git-head.ts +79 -75
- package/src/graders/output.ts +222 -140
- package/src/graders/semantic.ts +102 -43
- package/src/graders/shell.ts +379 -207
- package/src/host-diagnostic-redaction.ts +52 -0
- package/src/host-diagnostics.ts +319 -0
- package/src/hosts/claude-continuation.ts +63 -18
- package/src/hosts/claude-credential.ts +43 -62
- package/src/hosts/claude-events.ts +86 -51
- package/src/hosts/claude-keychain.ts +59 -0
- package/src/hosts/claude-native-goal.ts +57 -33
- package/src/hosts/claude-process.ts +111 -0
- package/src/hosts/claude-repository-invocation.ts +208 -117
- package/src/hosts/claude-settings.ts +240 -21
- package/src/hosts/claude-skill-activations.ts +166 -0
- package/src/hosts/claude-state.ts +403 -0
- package/src/hosts/claude-tool-calls.ts +171 -106
- package/src/hosts/claude.ts +561 -451
- package/src/hosts/codex-app-server.ts +326 -178
- package/src/hosts/codex-configuration.ts +44 -18
- package/src/hosts/codex-events.ts +97 -60
- package/src/hosts/codex-exec-controls.ts +516 -0
- package/src/hosts/codex-invocation.ts +70 -0
- package/src/hosts/codex-marketplace.ts +283 -0
- package/src/hosts/codex-native-calls.ts +546 -500
- package/src/hosts/codex-process.ts +202 -0
- package/src/hosts/codex-profile.ts +257 -28
- package/src/hosts/codex-session-files.ts +106 -0
- package/src/hosts/codex-state.ts +492 -0
- package/src/hosts/codex.ts +783 -832
- package/src/hosts/isolation-common.ts +94 -0
- package/src/hosts/isolation-roots.ts +54 -27
- package/src/hosts/isolation.ts +10 -0
- package/src/hosts/linux-sandbox.ts +159 -0
- package/src/hosts/mac-sandbox.ts +187 -61
- package/src/hosts/native-controls.ts +152 -62
- package/src/hosts/process-lifecycle.ts +37 -0
- package/src/hosts/protected-worktrees.ts +51 -19
- package/src/hosts/skill-hook-catalog.ts +131 -0
- package/src/hosts/skill-hook-handler.ts +374 -0
- package/src/hosts/skill-hooks.ts +580 -0
- package/src/hosts/workspace-fingerprint.ts +55 -35
- package/src/identity.ts +102 -48
- package/src/instrumentation.ts +109 -48
- package/src/native-transcript-state.ts +131 -0
- package/src/native-transcript-view.ts +90 -0
- package/src/native-transcripts.ts +286 -0
- package/src/process-lifecycle.ts +150 -0
- package/src/provenance.ts +161 -81
- package/src/prune.ts +215 -0
- package/src/report.ts +172 -140
- package/src/resolved-case.ts +33 -0
- package/src/results-lock.ts +29 -0
- package/src/results.ts +133 -86
- package/src/run-owner.ts +154 -63
- package/src/runtime/config.ts +456 -0
- package/src/runtime/discovery-apple.ts +90 -0
- package/src/runtime/discovery-providers.ts +63 -0
- package/src/runtime/discovery.ts +70 -0
- package/src/runtime/hook-processes.ts +97 -0
- package/src/runtime/hooks.ts +476 -0
- package/src/runtime/paths.ts +313 -0
- package/src/runtime/query.ts +85 -0
- package/src/runtime/seeds.ts +134 -0
- package/src/runtime/shared-cache.ts +143 -0
- package/src/runtime/state.ts +143 -0
- package/src/schema-types.ts +198 -0
- package/src/schema.ts +15 -19
- package/src/transcript-retention.ts +146 -0
- package/src/value-guards.ts +20 -0
- package/src/advisory-fixture.ts +0 -282
- package/src/fixture-bin.ts +0 -87
- package/src/fixture-setup.ts +0 -163
- package/src/generated-fixture.ts +0 -220
- package/src/git-hooks.ts +0 -63
- package/src/hosts/claude-nested-skills.ts +0 -218
- package/src/hosts/codex-command-output.ts +0 -399
- package/src/hosts/codex-executor-command.ts +0 -195
- package/src/hosts/codex-skill-reads.ts +0 -391
- package/src/preparation.ts +0 -211
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
import { isAbsolute } from "node:path";
|
|
2
2
|
import { CLAUDE_AUTH_VARIABLES } from "./claude-credential";
|
|
3
|
+
import type { RuntimePolicy } from "../runtime/config";
|
|
4
|
+
import { runtimeHooksEnabled } from "../runtime/hooks";
|
|
5
|
+
import { requireRuntimeReadRoots, isRuntimeHomeRoot } from "../runtime/paths";
|
|
6
|
+
import { nativeStatePath } from "../native-transcript-state";
|
|
7
|
+
import {
|
|
8
|
+
workspaceStatePath,
|
|
9
|
+
workspaceBoundaryException,
|
|
10
|
+
} from "../fixtures/workspace-state";
|
|
11
|
+
|
|
12
|
+
interface WritableRuntime {
|
|
13
|
+
root: string;
|
|
14
|
+
workspace: string;
|
|
15
|
+
cacheRoots?: string[];
|
|
16
|
+
}
|
|
3
17
|
|
|
4
18
|
function absoluteRule(root: string, tool: "Read" | "Edit"): string {
|
|
5
19
|
if (!isAbsolute(root) || /[\r\n()]/.test(root))
|
|
@@ -7,46 +21,251 @@ function absoluteRule(root: string, tool: "Read" | "Edit"): string {
|
|
|
7
21
|
return `${tool}(/${root}/**)`;
|
|
8
22
|
}
|
|
9
23
|
|
|
24
|
+
function validPrivatePaths(
|
|
25
|
+
privateRoot: string,
|
|
26
|
+
credentialFile: string,
|
|
27
|
+
roots: string[],
|
|
28
|
+
): boolean {
|
|
29
|
+
return !(
|
|
30
|
+
!isAbsolute(privateRoot) ||
|
|
31
|
+
!isAbsolute(credentialFile) ||
|
|
32
|
+
!credentialFile.startsWith(`${privateRoot}/`) ||
|
|
33
|
+
roots.some((root) => !isAbsolute(root) || /[\r\n()]/.test(root))
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
10
37
|
/** Keep agent tools away from the CLI's private state while core auth works. */
|
|
11
38
|
export function claudeHostSettings(
|
|
12
39
|
privateRoot: string,
|
|
13
40
|
credentialFile: string,
|
|
14
41
|
pluginRoots: string[] = [],
|
|
15
42
|
protectedRoots: string[] = [],
|
|
43
|
+
runtimePolicy?: RuntimePolicy,
|
|
44
|
+
transcriptReadRoots: string[] = [],
|
|
45
|
+
runtime?: WritableRuntime,
|
|
46
|
+
workspace?: string,
|
|
16
47
|
): Record<string, unknown> {
|
|
17
48
|
if (
|
|
18
|
-
!
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
(root) => !isAbsolute(root) || /[\r\n()]/.test(root),
|
|
23
|
-
)
|
|
49
|
+
!validPrivatePaths(privateRoot, credentialFile, [
|
|
50
|
+
...pluginRoots,
|
|
51
|
+
...protectedRoots,
|
|
52
|
+
])
|
|
24
53
|
)
|
|
25
54
|
throw new Error("Claude private state paths are invalid");
|
|
55
|
+
const readRoots = runtimeReadRoots(runtimePolicy);
|
|
56
|
+
requireRuntimeReadRoots(readRoots, [privateRoot, ...protectedRoots]);
|
|
57
|
+
requireRuntimeReadRoots(runtimeCacheRoots(runtime), [
|
|
58
|
+
privateRoot,
|
|
59
|
+
...protectedRoots,
|
|
60
|
+
]);
|
|
26
61
|
return {
|
|
27
|
-
disableAllHooks:
|
|
62
|
+
disableAllHooks: !runtimeHooksEnabled(runtimePolicy),
|
|
28
63
|
sandbox: {
|
|
29
64
|
enabled: true,
|
|
30
65
|
allowUnsandboxedCommands: false,
|
|
31
66
|
failIfUnavailable: true,
|
|
32
|
-
filesystem:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
67
|
+
filesystem: claudeFilesystemPolicy(
|
|
68
|
+
privateRoot,
|
|
69
|
+
protectedRoots,
|
|
70
|
+
readRoots,
|
|
71
|
+
transcriptReadRoots,
|
|
72
|
+
pluginRoots,
|
|
73
|
+
runtime,
|
|
74
|
+
workspace,
|
|
75
|
+
),
|
|
36
76
|
credentials: {
|
|
37
77
|
files: [{ path: credentialFile, mode: "deny" }],
|
|
38
78
|
envVars: CLAUDE_AUTH_VARIABLES.map((name) => ({ name, mode: "deny" })),
|
|
39
79
|
},
|
|
40
80
|
},
|
|
41
|
-
permissions:
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
81
|
+
permissions: claudePermissions(
|
|
82
|
+
privateRoot,
|
|
83
|
+
protectedRoots,
|
|
84
|
+
pluginRoots,
|
|
85
|
+
runtimePolicy,
|
|
86
|
+
transcriptReadRoots,
|
|
87
|
+
runtime,
|
|
88
|
+
workspace,
|
|
89
|
+
),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function claudeFilesystemPolicy(
|
|
94
|
+
privateRoot: string,
|
|
95
|
+
protectedRoots: string[],
|
|
96
|
+
readRoots: string[],
|
|
97
|
+
transcriptReadRoots: string[],
|
|
98
|
+
pluginRoots: string[],
|
|
99
|
+
runtime: WritableRuntime | undefined,
|
|
100
|
+
workspace: string | undefined,
|
|
101
|
+
) {
|
|
102
|
+
const runtimeWriteRoot = runtime?.root;
|
|
103
|
+
const writableRoots = runtimeWriteRoots(runtime);
|
|
104
|
+
return {
|
|
105
|
+
denyRead: [privateRoot, ...protectedRoots],
|
|
106
|
+
allowRead: [
|
|
107
|
+
...workspaceBoundaryException(workspaceStatePath(), workspace),
|
|
108
|
+
...readRoots,
|
|
109
|
+
...transcriptReadRoots,
|
|
110
|
+
...pluginRoots,
|
|
111
|
+
...writableRoots,
|
|
112
|
+
],
|
|
113
|
+
...(writableRoots.length ? { allowWrite: writableRoots } : {}),
|
|
114
|
+
denyWrite: [
|
|
115
|
+
privateRoot,
|
|
116
|
+
...pluginRoots,
|
|
117
|
+
...writableProtectedRoots(
|
|
118
|
+
protectedRoots,
|
|
119
|
+
runtimeWriteRoot,
|
|
120
|
+
workspace,
|
|
121
|
+
runtimeCacheRoots(runtime),
|
|
122
|
+
),
|
|
123
|
+
...readRoots,
|
|
124
|
+
...transcriptReadRoots,
|
|
125
|
+
],
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function claudePermissions(
|
|
130
|
+
privateRoot: string,
|
|
131
|
+
protectedRoots: string[],
|
|
132
|
+
pluginRoots: string[],
|
|
133
|
+
policy: RuntimePolicy | undefined,
|
|
134
|
+
transcriptReadRoots: string[],
|
|
135
|
+
runtime: WritableRuntime | undefined,
|
|
136
|
+
workspace: string | undefined,
|
|
137
|
+
) {
|
|
138
|
+
const runtimeWriteRoot = runtime?.root;
|
|
139
|
+
const roots = [
|
|
140
|
+
privateRoot,
|
|
141
|
+
...protectedRoots.filter(
|
|
142
|
+
(root) => !workspaceBoundaryException(root, workspace).length,
|
|
143
|
+
),
|
|
144
|
+
];
|
|
145
|
+
const managedWorkspace = workspaceBoundaryException(
|
|
146
|
+
workspaceStatePath(),
|
|
147
|
+
workspace,
|
|
148
|
+
)[0];
|
|
149
|
+
const readRoots = policy
|
|
150
|
+
? roots.filter((root) => !isRuntimeHomeRoot(root))
|
|
151
|
+
: roots;
|
|
152
|
+
const toolRoots = [...runtimeReadRoots(policy), ...transcriptReadRoots];
|
|
153
|
+
const writableRoots = runtimeWriteRoots(runtime);
|
|
154
|
+
return {
|
|
155
|
+
allow: claudeToolAllowRules(policy, runtime, managedWorkspace),
|
|
156
|
+
...(policy || managedWorkspace
|
|
157
|
+
? {
|
|
158
|
+
blockReadsOutsideWorkingDirectories: true,
|
|
159
|
+
additionalDirectories: [
|
|
160
|
+
...pluginRoots,
|
|
161
|
+
...toolRoots,
|
|
162
|
+
...writableRoots,
|
|
163
|
+
],
|
|
164
|
+
}
|
|
165
|
+
: {}),
|
|
166
|
+
deny: [
|
|
167
|
+
...writableProtectedRoots(
|
|
168
|
+
roots,
|
|
169
|
+
runtimeWriteRoot,
|
|
170
|
+
workspace,
|
|
171
|
+
runtimeCacheRoots(runtime),
|
|
172
|
+
).flatMap((root) =>
|
|
173
|
+
protectedToolRules(
|
|
174
|
+
root,
|
|
175
|
+
readRoots.includes(root) &&
|
|
176
|
+
![...transcriptReadRoots, ...pluginRoots].some((path) =>
|
|
177
|
+
path.startsWith(`${root}/`),
|
|
178
|
+
),
|
|
179
|
+
),
|
|
180
|
+
),
|
|
181
|
+
...[...pluginRoots, ...toolRoots].map((root) =>
|
|
182
|
+
absoluteRule(root, "Edit"),
|
|
183
|
+
),
|
|
184
|
+
],
|
|
51
185
|
};
|
|
52
186
|
}
|
|
187
|
+
|
|
188
|
+
function claudeToolAllowRules(
|
|
189
|
+
policy: RuntimePolicy | undefined,
|
|
190
|
+
runtime: WritableRuntime | undefined,
|
|
191
|
+
workspace?: string,
|
|
192
|
+
): string[] {
|
|
193
|
+
if (!policy)
|
|
194
|
+
return [
|
|
195
|
+
"Bash",
|
|
196
|
+
"Read",
|
|
197
|
+
"Skill",
|
|
198
|
+
"Agent",
|
|
199
|
+
workspace ? absoluteRule(workspace, "Edit") : "Edit",
|
|
200
|
+
];
|
|
201
|
+
if (!runtime) return ["Bash", "Edit", "Skill", "Agent"];
|
|
202
|
+
return [
|
|
203
|
+
"Bash",
|
|
204
|
+
"Skill",
|
|
205
|
+
"Agent",
|
|
206
|
+
absoluteRule(runtime.workspace, "Edit"),
|
|
207
|
+
absoluteRule(runtime.root, "Edit"),
|
|
208
|
+
...(runtime.cacheRoots ?? []).map((root) => absoluteRule(root, "Edit")),
|
|
209
|
+
];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Native write denies override grants; the namespace stays read-denied and has no write grant. */
|
|
213
|
+
function writableProtectedRoots(
|
|
214
|
+
roots: string[],
|
|
215
|
+
runtimeWriteRoot: string | undefined,
|
|
216
|
+
workspace?: string,
|
|
217
|
+
cacheRoots: string[] = [],
|
|
218
|
+
): string[] {
|
|
219
|
+
const namespace = nativeStatePath();
|
|
220
|
+
return roots.filter(
|
|
221
|
+
(root) =>
|
|
222
|
+
!workspaceBoundaryException(root, workspace).length &&
|
|
223
|
+
!sharedHomeGrant(root, cacheRoots) &&
|
|
224
|
+
keepNativeWriteDeny(root, namespace, runtimeWriteRoot),
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function sharedHomeGrant(root: string, cacheRoots: string[]): boolean {
|
|
229
|
+
return (
|
|
230
|
+
isRuntimeHomeRoot(root) &&
|
|
231
|
+
cacheRoots.some((cache) => cache.startsWith(`${root}/`))
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function runtimeCacheRoots(runtime: WritableRuntime | undefined): string[] {
|
|
236
|
+
return runtime?.cacheRoots ?? [];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function runtimeWriteRoots(runtime: WritableRuntime | undefined): string[] {
|
|
240
|
+
return [
|
|
241
|
+
...optionalRuntimeRoot(runtime?.root),
|
|
242
|
+
...(runtime?.cacheRoots ?? []),
|
|
243
|
+
];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
function keepNativeWriteDeny(
|
|
247
|
+
root: string,
|
|
248
|
+
namespace: string,
|
|
249
|
+
runtimeWriteRoot?: string,
|
|
250
|
+
): boolean {
|
|
251
|
+
return (
|
|
252
|
+
root !== namespace ||
|
|
253
|
+
runtimeWriteRoot === undefined ||
|
|
254
|
+
!runtimeWriteRoot.startsWith(`${namespace}/`)
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function optionalRuntimeRoot(root: string | undefined): string[] {
|
|
259
|
+
return root ? [root] : [];
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function protectedToolRules(root: string, denyRead: boolean): string[] {
|
|
263
|
+
return [
|
|
264
|
+
...(denyRead ? [absoluteRule(root, "Read")] : []),
|
|
265
|
+
absoluteRule(root, "Edit"),
|
|
266
|
+
];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function runtimeReadRoots(policy: RuntimePolicy | undefined): string[] {
|
|
270
|
+
return policy?.readOnlyRoots ?? [];
|
|
271
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { isRecord } from "../value-guards";
|
|
2
|
+
import { summarizeClaudeEvents } from "./claude-events";
|
|
3
|
+
|
|
4
|
+
const MAX_CALLS = 128;
|
|
5
|
+
type Entry = Record<string, unknown>;
|
|
6
|
+
interface SkillCall {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
parentToolUseId: string | null;
|
|
9
|
+
toolUseId: string;
|
|
10
|
+
invocation: string;
|
|
11
|
+
status: "unknown" | "succeeded" | "failed";
|
|
12
|
+
}
|
|
13
|
+
interface State {
|
|
14
|
+
calls: Map<string, SkillCall>;
|
|
15
|
+
partial: boolean;
|
|
16
|
+
truncated: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function label(value: unknown): string | null {
|
|
20
|
+
return typeof value === "string" && /^[A-Za-z0-9_.:-]{1,256}$/.test(value)
|
|
21
|
+
? value
|
|
22
|
+
: null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function blocks(event: Entry): unknown[] {
|
|
26
|
+
const content: unknown = isRecord(event.message)
|
|
27
|
+
? event.message.content
|
|
28
|
+
: null;
|
|
29
|
+
return Array.isArray(content) ? content : [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function key(event: Entry, id: string): string {
|
|
33
|
+
return JSON.stringify([
|
|
34
|
+
event.session_id ?? event.sessionId,
|
|
35
|
+
event.parent_tool_use_id ?? null,
|
|
36
|
+
id,
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function call(event: Entry, block: Entry, state: State) {
|
|
41
|
+
const id = label(block.id);
|
|
42
|
+
const sessionId = label(event.session_id ?? event.sessionId);
|
|
43
|
+
const invocation = skillInput(block.input);
|
|
44
|
+
if (!id || !sessionId || !invocation) {
|
|
45
|
+
state.partial = true;
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
addCall(
|
|
49
|
+
key(event, id),
|
|
50
|
+
{
|
|
51
|
+
sessionId,
|
|
52
|
+
parentToolUseId: label(event.parent_tool_use_id),
|
|
53
|
+
toolUseId: id,
|
|
54
|
+
invocation,
|
|
55
|
+
status: "unknown",
|
|
56
|
+
},
|
|
57
|
+
state,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function skillInput(input: unknown): string | null {
|
|
62
|
+
return isRecord(input) ? label(input.skill) : null;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function addCall(id: string, value: SkillCall, state: State) {
|
|
66
|
+
const previous = state.calls.get(id);
|
|
67
|
+
if (previous) {
|
|
68
|
+
state.partial ||= previous.invocation !== value.invocation;
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (state.calls.size >= MAX_CALLS) {
|
|
72
|
+
state.truncated = true;
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
state.calls.set(id, value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function result(event: Entry, block: Entry, state: State) {
|
|
79
|
+
const id = label(block.tool_use_id);
|
|
80
|
+
if (!id) return;
|
|
81
|
+
const pending = state.calls.get(key(event, id));
|
|
82
|
+
if (!pending) return;
|
|
83
|
+
const status = resultStatus(block.is_error);
|
|
84
|
+
if (!status) {
|
|
85
|
+
state.partial = true;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
state.partial ||= conflictingResult(pending.status, status);
|
|
89
|
+
pending.status = status;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function resultStatus(value: unknown): "failed" | "succeeded" | null {
|
|
93
|
+
if (value !== undefined && typeof value !== "boolean") return null;
|
|
94
|
+
return value === true ? "failed" : "succeeded";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function conflictingResult(
|
|
98
|
+
previous: SkillCall["status"],
|
|
99
|
+
next: SkillCall["status"],
|
|
100
|
+
): boolean {
|
|
101
|
+
return previous !== "unknown" && previous !== next;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function visit(line: string, state: State) {
|
|
105
|
+
try {
|
|
106
|
+
const event: unknown = JSON.parse(line);
|
|
107
|
+
if (!isRecord(event)) throw new Error("invalid Claude event");
|
|
108
|
+
for (const block of blocks(event)) visitBlock(event, block, state);
|
|
109
|
+
} catch {
|
|
110
|
+
state.partial = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function visitBlock(event: Entry, block: unknown, state: State) {
|
|
115
|
+
if (!isRecord(block)) return;
|
|
116
|
+
switch (event.type) {
|
|
117
|
+
case "assistant":
|
|
118
|
+
if (isSkillCall(block)) call(event, block, state);
|
|
119
|
+
break;
|
|
120
|
+
case "user":
|
|
121
|
+
if (block.type === "tool_result") result(event, block, state);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function isSkillCall(block: Entry): boolean {
|
|
126
|
+
return block.type === "tool_use" && block.name === "Skill";
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function completeCollection(completed: boolean, state: State): boolean {
|
|
130
|
+
return (
|
|
131
|
+
completed &&
|
|
132
|
+
!state.partial &&
|
|
133
|
+
!state.truncated &&
|
|
134
|
+
[...state.calls.values()].every((item) => item.status !== "unknown")
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Observe the native Skill seam and distinguish successful results from attempts. */
|
|
139
|
+
export function claudeSkillActivationsObservation(
|
|
140
|
+
stream: string,
|
|
141
|
+
code: number,
|
|
142
|
+
) {
|
|
143
|
+
const summary = summarizeClaudeEvents(stream, code);
|
|
144
|
+
const state: State = { calls: new Map(), partial: false, truncated: false };
|
|
145
|
+
for (const line of stream.split("\n").filter((line) => line.trim()))
|
|
146
|
+
visit(line, state);
|
|
147
|
+
const calls = [...state.calls.values()];
|
|
148
|
+
const complete = completeCollection(summary.complete, state);
|
|
149
|
+
return {
|
|
150
|
+
id: "sevro.host.skill-activations",
|
|
151
|
+
completeness: complete ? ("complete" as const) : ("partial" as const),
|
|
152
|
+
data: {
|
|
153
|
+
method: "skill_tool_result",
|
|
154
|
+
visibility: "skill_tool",
|
|
155
|
+
observedSkills: [
|
|
156
|
+
...new Set(
|
|
157
|
+
calls
|
|
158
|
+
.filter((item) => item.status === "succeeded")
|
|
159
|
+
.map((item) => item.invocation),
|
|
160
|
+
),
|
|
161
|
+
],
|
|
162
|
+
calls,
|
|
163
|
+
truncated: state.truncated,
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
}
|