@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.51
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 +147 -0
- package/README.md +142 -17
- package/dist/agents-store.js +7 -3
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -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/console/assets/index-Bt1B51b7.js +733 -0
- package/dist/console/assets/index-sVftE9Ht.css +1 -0
- 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/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/secrets.js +14 -3
- package/dist/learning-words.d.ts +1 -1
- package/dist/learning-words.js +1 -1
- package/dist/mcp-pin-first.js +2 -1
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- 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 +89 -13
- package/dist/run-launch.d.ts +14 -0
- package/dist/run-launch.js +4 -0
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +12 -7
- package/dist/runner/adapter-loop.js +29 -26
- package/dist/runner/adapter-run-spec.js +2 -2
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/cli-run-spec.js +2 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +3 -1
- package/dist/runner/journal-kinds.d.ts +1 -1
- package/dist/runner/learning-end.js +4 -0
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +46 -108
- 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 +43 -3
- package/dist/runner/sdk-loop.js +34 -22
- package/dist/runs-over-store.d.ts +8 -1
- package/dist/runs-over-store.js +57 -9
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +103 -34
- package/dist/server.d.ts +3 -0
- package/dist/server.js +149 -26
- 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 +12 -0
- package/dist/store/agent-body.js +16 -2
- 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/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/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +18 -1
- package/dist/store/schema.js +33 -2
- package/dist/store/sqlite/run-launch.d.ts +9 -1
- package/dist/store/sqlite/run-launch.js +44 -0
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +87 -10
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +53 -1
- 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-view.d.ts +4 -3
- package/dist/store-view.js +11 -7
- package/dist/templates.d.ts +3 -2
- package/dist/tool-gate.d.ts +4 -2
- 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 +430 -0
- package/dist/uploads.d.ts +55 -1
- package/dist/uploads.js +185 -98
- package/dist/validate.js +1 -1
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil.js +3 -2
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D0mr9wfZ.css +0 -1
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
|
@@ -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>;
|