@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52
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/CHANGELOG.md +185 -0
- package/README.md +236 -30
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +17 -7
- package/dist/api-only.d.ts +6 -3
- package/dist/api-only.js +8 -5
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +2 -2
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +14 -3
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +6 -1
- package/dist/learning-words.js +6 -1
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +3 -2
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/mcp-servers-store.d.ts +1 -0
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +133 -24
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-launch.d.ts +27 -4
- package/dist/run-launch.js +18 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +8 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +41 -35
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +15 -15
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +14 -13
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +8 -3
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +51 -22
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +52 -112
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +58 -6
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +37 -25
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +13 -3
- package/dist/runs-over-store.js +71 -16
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +167 -82
- package/dist/server.d.ts +3 -0
- package/dist/server.js +230 -43
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +16 -0
- package/dist/store/agent-body.js +20 -3
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +32 -2
- package/dist/store/schema.js +74 -5
- package/dist/store/sqlite/run-launch.d.ts +31 -1
- package/dist/store/sqlite/run-launch.js +111 -2
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +226 -37
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +120 -5
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +4 -3
- package/dist/store-view.js +11 -7
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +6 -2
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tools.js +1 -1
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +431 -0
- package/dist/uploads.d.ts +52 -1
- package/dist/uploads.js +186 -108
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +4 -3
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { mkdir, readFile, realpath, rm } from 'node:fs/promises';
|
|
2
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import { parseArgs } from 'node:util';
|
|
4
|
+
import { secret } from '../secrets.js';
|
|
5
|
+
import { defaultData } from '../server-fs.js';
|
|
6
|
+
import { takeHold, releaseHold } from '../harness-install.js';
|
|
7
|
+
import { cliLearningUrl, installCliLearning, removeCliLearning, statusCliLearning } from './install.js';
|
|
8
|
+
import { connectionFile, readConnection, saveConnection } from './state.js';
|
|
9
|
+
const USAGE = 'usage: agentrun-serve learning connect|status|disconnect|retry --runtime codex|claude-code [--project PATH] [--url LOOPBACK_URL] [--data SERVER_DATA]';
|
|
10
|
+
async function ownerToken(data) {
|
|
11
|
+
const fromEnvironment = secret('AGENTRUN_API_KEY') || secret('AGENTRUN_TOKEN');
|
|
12
|
+
if (fromEnvironment)
|
|
13
|
+
return fromEnvironment;
|
|
14
|
+
let value;
|
|
15
|
+
try {
|
|
16
|
+
value = (await readFile(join(data, '.token'), 'utf8')).trim();
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new Error('Cannot read the local server token. Start AgentRun and use its --data directory.');
|
|
20
|
+
}
|
|
21
|
+
if (!value)
|
|
22
|
+
throw new Error('The local server token is empty.');
|
|
23
|
+
return value;
|
|
24
|
+
}
|
|
25
|
+
async function serverUrl(value, data) {
|
|
26
|
+
if (value)
|
|
27
|
+
return cliLearningUrl(value);
|
|
28
|
+
let recorded;
|
|
29
|
+
try {
|
|
30
|
+
const record = JSON.parse(await readFile(join(data, '.server.json'), 'utf8'));
|
|
31
|
+
if (typeof record.base_url === 'string')
|
|
32
|
+
recorded = record.base_url;
|
|
33
|
+
}
|
|
34
|
+
catch { /* A stopped/default server has no record. */ }
|
|
35
|
+
return cliLearningUrl(recorded);
|
|
36
|
+
}
|
|
37
|
+
async function request(fetcher, url, path, token, method, body) {
|
|
38
|
+
return fetcher(new URL(path, cliLearningUrl(url)), {
|
|
39
|
+
method, redirect: 'error', signal: AbortSignal.timeout(8_000),
|
|
40
|
+
headers: { authorization: `Bearer ${token}`, 'content-type': 'application/json' },
|
|
41
|
+
...(body === undefined ? {} : { body: JSON.stringify(body) }),
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async function revoke(fetcher, connection, token) {
|
|
45
|
+
const response = await request(fetcher, connection.url, `/v2/cli-learning/connections/${encodeURIComponent(connection.connection_id)}`, token, 'DELETE');
|
|
46
|
+
if (!response.ok && response.status !== 404)
|
|
47
|
+
throw new Error(`Server refused disconnection (HTTP ${response.status}).`);
|
|
48
|
+
}
|
|
49
|
+
async function hookInput(input) {
|
|
50
|
+
const chunks = [];
|
|
51
|
+
let bytes = 0;
|
|
52
|
+
for await (const chunk of input) {
|
|
53
|
+
const buffer = Buffer.from(chunk);
|
|
54
|
+
bytes += buffer.byteLength;
|
|
55
|
+
if (bytes > 1_048_576)
|
|
56
|
+
throw new Error('Hook input exceeds the limit.');
|
|
57
|
+
chunks.push(buffer);
|
|
58
|
+
}
|
|
59
|
+
return JSON.parse(Buffer.concat(chunks).toString('utf8'));
|
|
60
|
+
}
|
|
61
|
+
async function connectionLock(file, operation) {
|
|
62
|
+
await mkdir(dirname(file), { recursive: true, mode: 0o700 });
|
|
63
|
+
const holdPath = `${file}.lock`;
|
|
64
|
+
// A long retry must never lose its hold merely because time passed. A dead local
|
|
65
|
+
// process (including PID reuse) or an abandoned legacy empty lock is recoverable.
|
|
66
|
+
const token = await takeHold(dirname(file), { holdPath, timeoutMs: Infinity });
|
|
67
|
+
if (!token)
|
|
68
|
+
throw new Error('Another learning connection change is in progress for this project.');
|
|
69
|
+
try {
|
|
70
|
+
return await operation();
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
await releaseHold(dirname(file), token, { holdPath });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/** Installer/status command plus the bounded stdin worker invoked by ordinary CLI hooks. */
|
|
77
|
+
export async function learningMain(argv, io = {}) {
|
|
78
|
+
const output = io.stdout ?? ((text) => console.log(text));
|
|
79
|
+
const errorOutput = io.stderr ?? ((text) => console.error(text));
|
|
80
|
+
const fetcher = io.fetch ?? fetch;
|
|
81
|
+
const isHook = argv[0] === 'hook';
|
|
82
|
+
try {
|
|
83
|
+
const { values, positionals } = parseArgs({ args: argv, allowPositionals: true, options: {
|
|
84
|
+
project: { type: 'string' }, runtime: { type: 'string' }, data: { type: 'string' }, url: { type: 'string' },
|
|
85
|
+
json: { type: 'boolean' }, help: { type: 'boolean' },
|
|
86
|
+
} });
|
|
87
|
+
if (values.help) {
|
|
88
|
+
output(USAGE);
|
|
89
|
+
return 0;
|
|
90
|
+
}
|
|
91
|
+
const operation = positionals[0];
|
|
92
|
+
if (positionals.length !== 1 || !['connect', 'status', 'disconnect', 'retry', 'hook'].includes(operation ?? ''))
|
|
93
|
+
throw new Error(USAGE);
|
|
94
|
+
if (values.runtime !== 'codex' && values.runtime !== 'claude-code')
|
|
95
|
+
throw new Error(`--runtime must be codex or claude-code.\n${USAGE}`);
|
|
96
|
+
const runtime = values.runtime;
|
|
97
|
+
const project = await realpath(resolve(values.project ?? process.cwd()));
|
|
98
|
+
const requestedData = resolve(values.data ?? defaultData());
|
|
99
|
+
const dataDir = await realpath(requestedData).catch((error) => {
|
|
100
|
+
if (error.code === 'ENOENT')
|
|
101
|
+
return requestedData;
|
|
102
|
+
throw error;
|
|
103
|
+
});
|
|
104
|
+
const dataRelative = relative(project, dataDir);
|
|
105
|
+
if (dataRelative === '' || (dataRelative !== '..' && !dataRelative.startsWith(`..${sep}`) && !isAbsolute(dataRelative))) {
|
|
106
|
+
throw new Error('Use a server --data directory outside the project so connection credentials stay out of source control.');
|
|
107
|
+
}
|
|
108
|
+
const options = { runtime, project, dataDir };
|
|
109
|
+
if (operation === 'hook') {
|
|
110
|
+
const input = await hookInput(io.stdin ?? process.stdin);
|
|
111
|
+
const { runCliLearningHook } = await import('./hook.js');
|
|
112
|
+
const result = await runCliLearningHook({ ...options, ...(values.url ? { url: cliLearningUrl(values.url) } : {}) }, input);
|
|
113
|
+
if (result !== undefined)
|
|
114
|
+
output(JSON.stringify(result));
|
|
115
|
+
return 0;
|
|
116
|
+
}
|
|
117
|
+
const execute = async () => {
|
|
118
|
+
const existing = await readConnection(dataDir, runtime, project);
|
|
119
|
+
if (operation === 'retry') {
|
|
120
|
+
const { flushCliLearning } = await import('./hook.js');
|
|
121
|
+
const result = await flushCliLearning(options, { fetch: fetcher });
|
|
122
|
+
output(JSON.stringify(result));
|
|
123
|
+
if (result.blocked_journals)
|
|
124
|
+
errorOutput('CLI capture journals from another enrollment or without a destination binding are preserved for review. They were not retried.');
|
|
125
|
+
return result.pending > 0 || result.blocked_journals > 0 ? 1 : 0;
|
|
126
|
+
}
|
|
127
|
+
if (operation === 'status') {
|
|
128
|
+
const installation = await statusCliLearning(options);
|
|
129
|
+
let server = null;
|
|
130
|
+
if (existing) {
|
|
131
|
+
try {
|
|
132
|
+
const response = await request(fetcher, existing.url, '/v2/cli-learning/connections', await ownerToken(dataDir), 'GET');
|
|
133
|
+
if (!response.ok)
|
|
134
|
+
throw new Error('Unavailable');
|
|
135
|
+
const body = await response.json();
|
|
136
|
+
if (!Array.isArray(body.connections))
|
|
137
|
+
throw new Error('Invalid status');
|
|
138
|
+
const connection = body.connections.find((c) => c && typeof c === 'object' && c.connection_id === existing.connection_id);
|
|
139
|
+
server = { reachable: true, enrolled: !!connection, active: connection?.active === true,
|
|
140
|
+
...(typeof connection?.last_hook_at === 'string' ? { last_hook_at: connection.last_hook_at } : {}),
|
|
141
|
+
...(typeof connection?.last_run_id === 'string' ? { last_run_id: connection.last_run_id } : {}) };
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
server = { reachable: false };
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
output(JSON.stringify({ ...installation, connection: existing ? { connection_id: existing.connection_id, agent_id: existing.agent_id, url: existing.url, capture_enabled: !existing.revocation_pending } : null, server }, null, 2));
|
|
148
|
+
return 0;
|
|
149
|
+
}
|
|
150
|
+
if (operation === 'disconnect') {
|
|
151
|
+
// Loaded CLI sessions can retain hooks after their files are removed. Disable capture durably first.
|
|
152
|
+
if (existing)
|
|
153
|
+
await saveConnection(dataDir, { ...existing, revocation_pending: true });
|
|
154
|
+
const installation = await removeCliLearning(options);
|
|
155
|
+
if (existing) {
|
|
156
|
+
try {
|
|
157
|
+
await revoke(fetcher, existing, await ownerToken(dataDir));
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
output(JSON.stringify({ ...installation, revoked: false, warnings: [...installation.warnings, 'Hooks removed; server revocation is pending. Run disconnect again when the server is available.'] }, null, 2));
|
|
161
|
+
return 1;
|
|
162
|
+
}
|
|
163
|
+
await rm(connectionFile(dataDir, runtime, project), { force: true });
|
|
164
|
+
}
|
|
165
|
+
output(JSON.stringify({ ...installation, revoked: true }, null, 2));
|
|
166
|
+
return 0;
|
|
167
|
+
}
|
|
168
|
+
const url = await serverUrl(values.url, dataDir);
|
|
169
|
+
const before = await statusCliLearning(options);
|
|
170
|
+
if (before.state === 'partial')
|
|
171
|
+
throw new Error('AgentRun hooks were changed or disabled. Run learning disconnect before reconnecting.');
|
|
172
|
+
if (existing) {
|
|
173
|
+
if (existing.revocation_pending)
|
|
174
|
+
throw new Error('Capture is disabled while server revocation is pending. Run learning disconnect before reconnecting.');
|
|
175
|
+
if (existing.url !== url)
|
|
176
|
+
throw new Error('This project is connected to another server. Run learning disconnect before reconnecting.');
|
|
177
|
+
let active = false;
|
|
178
|
+
try {
|
|
179
|
+
const response = await request(fetcher, url, '/v2/cli-learning/connections', await ownerToken(dataDir), 'GET');
|
|
180
|
+
if (!response.ok)
|
|
181
|
+
throw new Error('Unavailable');
|
|
182
|
+
const body = await response.json();
|
|
183
|
+
if (!Array.isArray(body.connections))
|
|
184
|
+
throw new Error('Invalid status');
|
|
185
|
+
active = body.connections.some((c) => c && typeof c === 'object'
|
|
186
|
+
&& c.connection_id === existing.connection_id
|
|
187
|
+
&& c.active === true);
|
|
188
|
+
}
|
|
189
|
+
catch {
|
|
190
|
+
throw new Error('Cannot verify the existing learning connection. Retry when the local server is available.');
|
|
191
|
+
}
|
|
192
|
+
if (!active)
|
|
193
|
+
throw new Error('This learning connection is inactive. Run learning disconnect, then learning connect to enroll again.');
|
|
194
|
+
const installation = await installCliLearning({ ...options, url, command: io.command });
|
|
195
|
+
output(JSON.stringify({ ...installation, connection_id: existing.connection_id, agent_id: existing.agent_id }, null, 2));
|
|
196
|
+
return 0;
|
|
197
|
+
}
|
|
198
|
+
const token = await ownerToken(dataDir);
|
|
199
|
+
const response = await request(fetcher, url, '/v2/cli-learning/connections', token, 'POST', { project, runtime });
|
|
200
|
+
if (!response.ok)
|
|
201
|
+
throw new Error(`Server refused the learning connection (HTTP ${response.status}).`);
|
|
202
|
+
const body = await response.json();
|
|
203
|
+
if (!body || typeof body.connection_id !== 'string' || typeof body.agent_id !== 'string' || typeof body.token !== 'string'
|
|
204
|
+
|| !body.connection_id || !body.agent_id || !body.token)
|
|
205
|
+
throw new Error('The server returned an invalid learning connection.');
|
|
206
|
+
const connection = { version: 1, project, runtime, url, connection_id: body.connection_id, agent_id: body.agent_id, token: body.token };
|
|
207
|
+
let saved = false;
|
|
208
|
+
try {
|
|
209
|
+
await saveConnection(dataDir, connection);
|
|
210
|
+
saved = true;
|
|
211
|
+
const installation = await installCliLearning({ ...options, url, command: io.command });
|
|
212
|
+
output(JSON.stringify({ ...installation, connection_id: connection.connection_id, agent_id: connection.agent_id }, null, 2));
|
|
213
|
+
return 0;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
if (saved)
|
|
217
|
+
await saveConnection(dataDir, { ...connection, revocation_pending: true });
|
|
218
|
+
if (before.state === 'not-installed')
|
|
219
|
+
await removeCliLearning(options).catch(() => undefined);
|
|
220
|
+
try {
|
|
221
|
+
await revoke(fetcher, connection, token);
|
|
222
|
+
if (saved)
|
|
223
|
+
await rm(connectionFile(dataDir, runtime, project), { force: true });
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
throw new Error('Connection setup failed and server revocation is pending. Run learning disconnect when the server is available.');
|
|
227
|
+
}
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
return operation === 'status' ? await execute() : await connectionLock(connectionFile(dataDir, runtime, project), execute);
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
if (isHook) {
|
|
235
|
+
errorOutput('AgentRun learning hook skipped; use learning status to check the connection.');
|
|
236
|
+
return 0;
|
|
237
|
+
}
|
|
238
|
+
errorOutput(`agentrun learning: ${error instanceof Error ? error.message : 'Command failed.'}`);
|
|
239
|
+
return 2;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** A bounded, non-following read: project configuration must be a regular file we own. */
|
|
2
|
+
export declare function readConfigText(path: string): Promise<string | undefined>;
|
|
3
|
+
type CodexHookLocation = {
|
|
4
|
+
checkoutRoot?: string;
|
|
5
|
+
configRoot: string;
|
|
6
|
+
linkedWorktree: boolean;
|
|
7
|
+
};
|
|
8
|
+
/** Match Codex's root-checkout hook mapping, including Git's reciprocal worktree ownership checks. */
|
|
9
|
+
export declare function codexHookLocation(project: string): Promise<CodexHookLocation>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { constants } from 'node:fs';
|
|
2
|
+
import { lstat, open, realpath } from 'node:fs/promises';
|
|
3
|
+
import { basename, dirname, join, relative, resolve, sep } from 'node:path';
|
|
4
|
+
const missing = (error) => error.code === 'ENOENT';
|
|
5
|
+
/** A bounded, non-following read: project configuration must be a regular file we own. */
|
|
6
|
+
export async function readConfigText(path) {
|
|
7
|
+
let handle;
|
|
8
|
+
try {
|
|
9
|
+
handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (missing(error))
|
|
13
|
+
return;
|
|
14
|
+
throw error;
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
const info = await handle.stat();
|
|
18
|
+
if (!info.isFile() || info.size > 64 * 1024 || (process.getuid && info.uid !== process.getuid())) {
|
|
19
|
+
throw new Error(`Unsafe project configuration: ${path}; nothing was replaced.`);
|
|
20
|
+
}
|
|
21
|
+
const buffer = Buffer.alloc(64 * 1024 + 1);
|
|
22
|
+
let total = 0;
|
|
23
|
+
while (total < buffer.length) {
|
|
24
|
+
const { bytesRead } = await handle.read(buffer, total, buffer.length - total, total);
|
|
25
|
+
if (!bytesRead)
|
|
26
|
+
break;
|
|
27
|
+
total += bytesRead;
|
|
28
|
+
}
|
|
29
|
+
if (total > 64 * 1024)
|
|
30
|
+
throw new Error(`Oversized project configuration: ${path}; nothing was replaced.`);
|
|
31
|
+
return buffer.subarray(0, total).toString('utf8');
|
|
32
|
+
}
|
|
33
|
+
finally {
|
|
34
|
+
await handle.close();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function directory(path) {
|
|
38
|
+
const info = await lstat(path);
|
|
39
|
+
if (info.isSymbolicLink() || !info.isDirectory())
|
|
40
|
+
throw new Error(`Unsafe Git configuration directory: ${path}`);
|
|
41
|
+
return realpath(path);
|
|
42
|
+
}
|
|
43
|
+
async function pointer(path, prefix = '') {
|
|
44
|
+
const text = await readConfigText(path);
|
|
45
|
+
if (text === undefined)
|
|
46
|
+
return;
|
|
47
|
+
const trimmed = text.trim();
|
|
48
|
+
if (!trimmed.startsWith(prefix))
|
|
49
|
+
throw new Error(`Invalid Git worktree pointer: ${path}; nothing was replaced.`);
|
|
50
|
+
const value = trimmed.slice(prefix.length).trim();
|
|
51
|
+
if (!value || /[\0\r\n]/.test(value))
|
|
52
|
+
throw new Error(`Invalid Git worktree pointer: ${path}; nothing was replaced.`);
|
|
53
|
+
return resolve(dirname(path), value);
|
|
54
|
+
}
|
|
55
|
+
/** Match Codex's root-checkout hook mapping, including Git's reciprocal worktree ownership checks. */
|
|
56
|
+
export async function codexHookLocation(project) {
|
|
57
|
+
let current = project;
|
|
58
|
+
for (let depth = 0; depth < 32; depth++) {
|
|
59
|
+
const git = join(current, '.git');
|
|
60
|
+
let info;
|
|
61
|
+
try {
|
|
62
|
+
info = await lstat(git);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (!missing(error))
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
if (info) {
|
|
69
|
+
if (info.isSymbolicLink())
|
|
70
|
+
throw new Error(`Refusing Git configuration symlink: ${git}`);
|
|
71
|
+
if (info.isDirectory())
|
|
72
|
+
return { checkoutRoot: current, configRoot: project, linkedWorktree: false };
|
|
73
|
+
const gitDirPath = await pointer(git, 'gitdir:');
|
|
74
|
+
if (!gitDirPath)
|
|
75
|
+
throw new Error(`Missing Git worktree pointer: ${git}`);
|
|
76
|
+
const gitDir = await directory(gitDirPath);
|
|
77
|
+
const commonPath = await pointer(join(gitDir, 'commondir'));
|
|
78
|
+
if (!commonPath)
|
|
79
|
+
return { checkoutRoot: current, configRoot: project, linkedWorktree: false };
|
|
80
|
+
const common = await directory(commonPath);
|
|
81
|
+
if (basename(dirname(gitDir)) !== 'worktrees' || dirname(dirname(gitDir)) !== common) {
|
|
82
|
+
throw new Error('Git worktree common directory does not match its registered owner.');
|
|
83
|
+
}
|
|
84
|
+
const registeredGit = await pointer(join(gitDir, 'gitdir'));
|
|
85
|
+
if (!registeredGit || basename(registeredGit) !== '.git' || await directory(dirname(registeredGit)) !== current) {
|
|
86
|
+
throw new Error('Git worktree registration does not match this checkout.');
|
|
87
|
+
}
|
|
88
|
+
const root = await directory(dirname(common));
|
|
89
|
+
const mainGit = join(root, '.git');
|
|
90
|
+
const mainInfo = await lstat(mainGit);
|
|
91
|
+
if (mainInfo.isSymbolicLink())
|
|
92
|
+
throw new Error(`Refusing Git configuration symlink: ${mainGit}`);
|
|
93
|
+
const mainGitDir = mainInfo.isDirectory() ? mainGit : await pointer(mainGit, 'gitdir:');
|
|
94
|
+
if (!mainGitDir || await directory(mainGitDir) !== common)
|
|
95
|
+
throw new Error('Git main checkout does not own the common directory.');
|
|
96
|
+
const configRoot = resolve(root, relative(current, project));
|
|
97
|
+
// Refuse a shared project path redirected through a symlink. Missing corresponding folders can be created later.
|
|
98
|
+
let component = root;
|
|
99
|
+
for (const part of relative(root, configRoot).split(sep).filter(Boolean)) {
|
|
100
|
+
component = join(component, part);
|
|
101
|
+
try {
|
|
102
|
+
const entry = await lstat(component);
|
|
103
|
+
if (entry.isSymbolicLink() || !entry.isDirectory())
|
|
104
|
+
throw new Error(`Unsafe shared project configuration directory: ${component}`);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
if (!missing(error))
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { checkoutRoot: current, configRoot, linkedWorktree: true };
|
|
112
|
+
}
|
|
113
|
+
const parent = dirname(current);
|
|
114
|
+
if (parent === current)
|
|
115
|
+
return { configRoot: project, linkedWorktree: false };
|
|
116
|
+
current = parent;
|
|
117
|
+
}
|
|
118
|
+
throw new Error('Could not determine the Codex project hook scope within 32 parent directories.');
|
|
119
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { NativeBinding } from '../native/types.js';
|
|
2
|
+
import type { Store } from '../store/store.js';
|
|
3
|
+
export type CliConnection = {
|
|
4
|
+
connection_id: string;
|
|
5
|
+
agent_id: string;
|
|
6
|
+
runtime: 'codex' | 'claude-code';
|
|
7
|
+
project: string;
|
|
8
|
+
active: boolean;
|
|
9
|
+
generation: string;
|
|
10
|
+
native: NativeBinding;
|
|
11
|
+
last_hook_at?: string;
|
|
12
|
+
last_run_id?: string;
|
|
13
|
+
hook_sessions?: Record<string, string>;
|
|
14
|
+
};
|
|
15
|
+
export declare class CliLearningConnections {
|
|
16
|
+
private readonly store;
|
|
17
|
+
private readonly secret;
|
|
18
|
+
constructor(store: Store, secret: string);
|
|
19
|
+
token(row: CliConnection): string;
|
|
20
|
+
get(id: string): Promise<CliConnection>;
|
|
21
|
+
authenticate(id: string, token: string): Promise<CliConnection>;
|
|
22
|
+
enroll(body: Record<string, unknown>): Promise<{
|
|
23
|
+
token: string;
|
|
24
|
+
last_run_id?: string | undefined;
|
|
25
|
+
last_hook_at?: string | undefined;
|
|
26
|
+
connection_id: string;
|
|
27
|
+
agent_id: string;
|
|
28
|
+
runtime: "codex" | "claude-code";
|
|
29
|
+
project: string;
|
|
30
|
+
active: boolean;
|
|
31
|
+
}>;
|
|
32
|
+
view(row: CliConnection): {
|
|
33
|
+
last_run_id?: string | undefined;
|
|
34
|
+
last_hook_at?: string | undefined;
|
|
35
|
+
connection_id: string;
|
|
36
|
+
agent_id: string;
|
|
37
|
+
runtime: "codex" | "claude-code";
|
|
38
|
+
project: string;
|
|
39
|
+
active: boolean;
|
|
40
|
+
};
|
|
41
|
+
recordWindow(id: string, generation: string, runId: string, sessionId?: string): Promise<void>;
|
|
42
|
+
list(): Promise<{
|
|
43
|
+
connections: {
|
|
44
|
+
last_run_id?: string | undefined;
|
|
45
|
+
last_hook_at?: string | undefined;
|
|
46
|
+
connection_id: string;
|
|
47
|
+
agent_id: string;
|
|
48
|
+
runtime: "codex" | "claude-code";
|
|
49
|
+
project: string;
|
|
50
|
+
active: boolean;
|
|
51
|
+
}[];
|
|
52
|
+
}>;
|
|
53
|
+
revoke(id: string): Promise<{
|
|
54
|
+
last_run_id?: string | undefined;
|
|
55
|
+
last_hook_at?: string | undefined;
|
|
56
|
+
connection_id: string;
|
|
57
|
+
agent_id: string;
|
|
58
|
+
runtime: "codex" | "claude-code";
|
|
59
|
+
project: string;
|
|
60
|
+
active: boolean;
|
|
61
|
+
}>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// A local owner enrolls one installed CLI. Its hook credential can only submit prompt windows for this agent.
|
|
2
|
+
import { createHash, createHmac, randomBytes, timingSafeEqual } from 'node:crypto';
|
|
3
|
+
import { basename } from 'node:path';
|
|
4
|
+
import { createAgent, getAgent } from '../agents-store.js';
|
|
5
|
+
import { ApiError } from '../errors.js';
|
|
6
|
+
import { selectedNative, launchNative } from '../native/connection.js';
|
|
7
|
+
import { cliLearningOf, isObject } from '../store/agent-body.js';
|
|
8
|
+
const key = (id) => `cli-learning-connection:${id}`;
|
|
9
|
+
const hash = (text) => createHash('sha256').update(text).digest();
|
|
10
|
+
export class CliLearningConnections {
|
|
11
|
+
store;
|
|
12
|
+
secret;
|
|
13
|
+
constructor(store, secret) {
|
|
14
|
+
this.store = store;
|
|
15
|
+
this.secret = secret;
|
|
16
|
+
}
|
|
17
|
+
token(row) { return `ar_cli_${createHmac('sha256', this.secret).update(`${row.connection_id}\0${row.generation}`).digest('base64url')}`; }
|
|
18
|
+
async get(id) { const row = await this.store.settings.get(key(id)); if (!isObject(row))
|
|
19
|
+
throw new ApiError('not_found', 'No CLI learning connection with that id.'); return row; }
|
|
20
|
+
async authenticate(id, token) { let row; try {
|
|
21
|
+
row = await this.get(id);
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new ApiError('unauthenticated', 'This credential is not a CLI learning connection.');
|
|
25
|
+
} if (!row.active || !timingSafeEqual(hash(token), hash(this.token(row))))
|
|
26
|
+
throw new ApiError('unauthenticated', 'This CLI learning connection is disconnected or the credential has a different scope.'); return row; }
|
|
27
|
+
async enroll(body) {
|
|
28
|
+
if (Object.keys(body).some(key => !['runtime', 'project', 'name'].includes(key)) || !['codex', 'claude-code'].includes(String(body.runtime)) || typeof body.project !== 'string' || (body.name !== undefined && typeof body.name !== 'string'))
|
|
29
|
+
throw new ApiError('input_invalid', 'Supply the local project, runtime (codex or claude-code), and optional name.');
|
|
30
|
+
const target = await selectedNative(body);
|
|
31
|
+
const native = await launchNative({ ...target, connected: true });
|
|
32
|
+
const id = createHash('sha256').update(`${target.runtime}\0${target.machine_id}\0${target.project}`).digest('hex').slice(0, 32);
|
|
33
|
+
const agentId = `cli-${id}`;
|
|
34
|
+
// Agent creation is deterministic. Concurrent enrollments keep the winner's revision and learning folder.
|
|
35
|
+
if (!await getAgent(this.store, agentId))
|
|
36
|
+
try {
|
|
37
|
+
await createAgent(this.store, { definition: { id: agentId, name: typeof body.name === 'string' ? body.name : `${basename(target.project)} (${target.runtime})`, instructions: '', tools: [], learning: true, cli_learning: { runtime: target.runtime, connection_id: id, project: target.project } } });
|
|
38
|
+
}
|
|
39
|
+
catch (error) {
|
|
40
|
+
if (!await getAgent(this.store, agentId))
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
const candidate = { connection_id: id, agent_id: agentId, runtime: target.runtime, project: target.project, active: true, generation: randomBytes(24).toString('base64url'), native };
|
|
44
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
45
|
+
const row = await this.store.settings.putIfAbsent(key(id), candidate);
|
|
46
|
+
if (row.active)
|
|
47
|
+
return { ...this.view(row), token: this.token(row) };
|
|
48
|
+
if (await this.store.settings.replaceIf(key(id), row, candidate))
|
|
49
|
+
return { ...this.view(candidate), token: this.token(candidate) };
|
|
50
|
+
}
|
|
51
|
+
throw new ApiError('home_busy', 'The connection changed concurrently; retry enrolling it.');
|
|
52
|
+
}
|
|
53
|
+
view(row) { const { connection_id, agent_id, runtime, project, active, last_hook_at, last_run_id } = row; return { connection_id, agent_id, runtime, project, active, ...(last_hook_at ? { last_hook_at } : {}), ...(last_run_id ? { last_run_id } : {}) }; }
|
|
54
|
+
async recordWindow(id, generation, runId, sessionId) {
|
|
55
|
+
for (let attempt = 0; attempt < 20; attempt++) {
|
|
56
|
+
const row = await this.get(id);
|
|
57
|
+
if (!row.active || row.generation !== generation)
|
|
58
|
+
return;
|
|
59
|
+
const at = new Date().toISOString();
|
|
60
|
+
// Activation belongs to this credential generation and exact native session. Keep a bounded set
|
|
61
|
+
// of hashes rather than session IDs, matching the observation session retention window.
|
|
62
|
+
const sessions = { ...row.hook_sessions, ...(sessionId ? { [hash(sessionId).toString('hex')]: at } : {}) };
|
|
63
|
+
const floor = Date.parse(at) - 90 * 86_400_000;
|
|
64
|
+
const hook_sessions = Object.fromEntries(Object.entries(sessions).filter(([, seen]) => Date.parse(seen) >= floor).sort((a, b) => b[1].localeCompare(a[1])).slice(0, 1000));
|
|
65
|
+
const next = { ...row, last_hook_at: at, last_run_id: runId, ...(sessionId ? { hook_sessions } : {}) };
|
|
66
|
+
if (await this.store.settings.replaceIf(key(id), row, next))
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
throw new ApiError("home_busy", "The connection changed concurrently; retry this prompt-window acknowledgement.");
|
|
70
|
+
}
|
|
71
|
+
async list() { const result = []; for (const agent of await this.store.agents.list()) {
|
|
72
|
+
const entry = await getAgent(this.store, agent.id), binding = cliLearningOf(entry?.revision?.body);
|
|
73
|
+
if (binding) {
|
|
74
|
+
const row = await this.get(binding.connection_id).catch(() => undefined);
|
|
75
|
+
if (row)
|
|
76
|
+
result.push(this.view(row));
|
|
77
|
+
}
|
|
78
|
+
} return { connections: result }; }
|
|
79
|
+
async revoke(id) { for (let attempt = 0; attempt < 20; attempt++) {
|
|
80
|
+
const row = await this.get(id);
|
|
81
|
+
if (!row.active)
|
|
82
|
+
return this.view(row);
|
|
83
|
+
const next = { ...row, active: false };
|
|
84
|
+
if (await this.store.settings.replaceIf(key(id), row, next))
|
|
85
|
+
return this.view(next);
|
|
86
|
+
} throw new ApiError('home_busy', 'The connection changed concurrently; retry disconnecting it.'); }
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Small hook entrypoint: do not load the server, runner, SQLite or provider SDKs for each local CLI event.
|
|
2
|
+
import { learningMain } from './cli.js';
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
process.exitCode = await learningMain(args[0] === 'learning' ? args.slice(1) : args);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { type CliLearningRuntime } from './state.js';
|
|
2
|
+
import type { SdkUsage } from '../sdk/runs.js';
|
|
3
|
+
export type TranscriptCursor = {
|
|
4
|
+
path: string;
|
|
5
|
+
offset: number;
|
|
6
|
+
dev: number;
|
|
7
|
+
ino: number;
|
|
8
|
+
/** Only an ENOENT observed at the first Claude submit may later establish a new file boundary. */
|
|
9
|
+
absent?: {
|
|
10
|
+
observedAt: number;
|
|
11
|
+
sessionId: string;
|
|
12
|
+
turnId: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type DialogueMessage = {
|
|
16
|
+
role: 'user' | 'assistant';
|
|
17
|
+
text: string;
|
|
18
|
+
};
|
|
19
|
+
export type ToolEvidence = {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
status: 'started' | 'completed' | 'failed';
|
|
23
|
+
};
|
|
24
|
+
export type PromptEvidence = {
|
|
25
|
+
messages: DialogueMessage[];
|
|
26
|
+
tools: ToolEvidence[];
|
|
27
|
+
answer: string;
|
|
28
|
+
model?: string;
|
|
29
|
+
/** Native counters for this prompt only; absent when source usage cannot be established. */
|
|
30
|
+
usage?: SdkUsage;
|
|
31
|
+
/** Newly born first-Claude file, verified against the submitted prompt before policy capture. */
|
|
32
|
+
verifiedCursor?: TranscriptCursor;
|
|
33
|
+
complete: boolean;
|
|
34
|
+
reason?: string;
|
|
35
|
+
seedObserved: boolean;
|
|
36
|
+
redacted?: boolean;
|
|
37
|
+
truncated?: boolean;
|
|
38
|
+
};
|
|
39
|
+
export type CliHookInput = {
|
|
40
|
+
event: 'UserPromptSubmit' | 'Stop' | 'Interrupt' | 'StopFailure' | 'SessionEnd';
|
|
41
|
+
sessionId: string;
|
|
42
|
+
turnId?: string;
|
|
43
|
+
cwd: string;
|
|
44
|
+
transcriptPath?: string;
|
|
45
|
+
prompt?: string;
|
|
46
|
+
answer?: string;
|
|
47
|
+
model?: string;
|
|
48
|
+
stopHookActive?: boolean;
|
|
49
|
+
};
|
|
50
|
+
/** SDK text is limited in UTF-16 code units. Also keep the source UTF-8 budget and
|
|
51
|
+
* leave room for an event envelope inside the SDK's 256 KB JSON batch. Call only
|
|
52
|
+
* after redacting the whole value, so a cut cannot expose part of a held secret. */
|
|
53
|
+
export declare function boundCaptureText(text: string, maxBytes?: number): {
|
|
54
|
+
text: string;
|
|
55
|
+
truncated: boolean;
|
|
56
|
+
};
|
|
57
|
+
/** The two harnesses use different prompt identities. Missing identities are not guessed from timestamps. */
|
|
58
|
+
export declare function normalizeHookInput(runtime: CliLearningRuntime, input: unknown): CliHookInput | null;
|
|
59
|
+
export declare function captureTranscriptCursor(path?: string, firstPrompt?: {
|
|
60
|
+
runtime: CliLearningRuntime;
|
|
61
|
+
sessionId: string;
|
|
62
|
+
turnId: string;
|
|
63
|
+
}): Promise<TranscriptCursor | null>;
|
|
64
|
+
/** Read only bytes written after enrollment for this prompt. Tool results and reasoning never become dialogue. */
|
|
65
|
+
export declare function collectPromptEvidence(options: {
|
|
66
|
+
runtime: CliLearningRuntime;
|
|
67
|
+
cursor: TranscriptCursor | null;
|
|
68
|
+
turnId: string;
|
|
69
|
+
sessionId?: string;
|
|
70
|
+
prompt?: string;
|
|
71
|
+
answer?: string;
|
|
72
|
+
/** Original terminal text digest, retained only when a local size cut changed it. */
|
|
73
|
+
answerDigest?: string;
|
|
74
|
+
seedMarker?: string;
|
|
75
|
+
maxBytes?: number;
|
|
76
|
+
/** Redact whole source values before applying storage/upload limits. */
|
|
77
|
+
redact?: (text: string) => string;
|
|
78
|
+
}): Promise<PromptEvidence>;
|