@opencorelabs/lucidity 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -2
- package/dist/assets/speech/lucidity-speech +0 -0
- package/dist/automations/agent.d.ts.map +1 -1
- package/dist/automations/agent.js +2 -0
- package/dist/automations/designer.d.ts +1 -1
- package/dist/chat/server.d.ts +1 -0
- package/dist/chat/server.d.ts.map +1 -1
- package/dist/chat/server.js +6 -1
- package/dist/coding/conduct.d.ts +1 -22
- package/dist/coding/conduct.d.ts.map +1 -1
- package/dist/coding/conduct.js +9 -94
- package/dist/coding/runCodeTurn.d.ts +3 -16
- package/dist/coding/runCodeTurn.d.ts.map +1 -1
- package/dist/coding/runCodeTurn.js +157 -165
- package/dist/coding/workspaceRegistry.d.ts +24 -0
- package/dist/coding/workspaceRegistry.d.ts.map +1 -0
- package/dist/coding/workspaceRegistry.js +230 -0
- package/dist/coding/worktree.d.ts +11 -14
- package/dist/coding/worktree.d.ts.map +1 -1
- package/dist/coding/worktree.js +41 -21
- package/dist/config.d.ts +2 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/daemonLease.d.ts +12 -0
- package/dist/daemonLease.d.ts.map +1 -0
- package/dist/daemonLease.js +32 -0
- package/dist/goals/assessment.d.ts +115 -0
- package/dist/goals/assessment.d.ts.map +1 -0
- package/dist/goals/assessment.js +67 -0
- package/dist/goals/notes.d.ts +18 -0
- package/dist/goals/notes.d.ts.map +1 -0
- package/dist/goals/notes.js +72 -0
- package/dist/index.js +57 -15
- package/dist/jobs/goals.d.ts +15 -0
- package/dist/jobs/goals.d.ts.map +1 -0
- package/dist/jobs/goals.js +286 -0
- package/dist/jobs/weeklyReview.d.ts.map +1 -1
- package/dist/jobs/weeklyReview.js +3 -2
- package/dist/queue.d.ts +1 -0
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +4 -0
- package/dist/room/client.d.ts +5 -0
- package/dist/room/client.d.ts.map +1 -1
- package/dist/room/client.js +116 -101
- package/dist/room/computer.d.ts.map +1 -1
- package/dist/room/computer.js +1 -0
- package/dist/room/durablePublish.d.ts +6 -0
- package/dist/room/durablePublish.d.ts.map +1 -0
- package/dist/room/durablePublish.js +19 -0
- package/dist/room/incidents.d.ts +1 -1
- package/dist/room/incidents.d.ts.map +1 -1
- package/dist/room/incidents.js +14 -7
- package/dist/room/turnQueue.d.ts.map +1 -1
- package/dist/room/turnQueue.js +27 -24
- package/dist/runtimeStore.d.ts +44 -0
- package/dist/runtimeStore.d.ts.map +1 -0
- package/dist/runtimeStore.js +188 -0
- package/dist/setup/server.js +1 -1
- package/dist/turnLog.d.ts +10 -40
- package/dist/turnLog.d.ts.map +1 -1
- package/dist/turnLog.js +33 -56
- package/package.json +4 -4
- package/src/automations/agent.ts +2 -0
- package/src/chat/server.ts +7 -1
- package/src/coding/conduct.ts +10 -147
- package/src/coding/runCodeTurn.ts +42 -61
- package/src/coding/workspaceRegistry.ts +210 -0
- package/src/coding/worktree.ts +44 -20
- package/src/config.ts +2 -0
- package/src/daemonLease.ts +33 -0
- package/src/goals/assessment.ts +106 -0
- package/src/goals/notes.ts +88 -0
- package/src/index.ts +57 -18
- package/src/jobs/goals.ts +384 -0
- package/src/jobs/weeklyReview.ts +4 -3
- package/src/queue.ts +4 -0
- package/src/room/client.ts +77 -74
- package/src/room/computer.ts +1 -0
- package/src/room/durablePublish.ts +25 -0
- package/src/room/incidents.ts +16 -8
- package/src/room/turnQueue.ts +26 -27
- package/src/runtimeStore.ts +190 -0
- package/src/setup/server.ts +1 -1
- package/src/turnLog.ts +32 -75
- package/vendor/mcp-server/dist/index.js +2 -0
- package/vendor/mcp-server/dist/tools/goals.d.ts +4 -0
- package/vendor/mcp-server/dist/tools/goals.d.ts.map +1 -0
- package/vendor/mcp-server/dist/tools/goals.js +38 -0
- package/vendor/mcp-server/package.json +1 -1
- package/vendor/mcp-server/src/index.ts +2 -0
- package/vendor/mcp-server/src/tools/goals.ts +62 -0
- package/vendor/runtime/README.md +2 -2
- package/vendor/runtime/dist/executor/asyncQueue.d.ts +1 -0
- package/vendor/runtime/dist/executor/asyncQueue.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/asyncQueue.js +3 -0
- package/vendor/runtime/dist/executor/claudeAgent.d.ts +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/claudeAgent.js +20 -9
- package/vendor/runtime/dist/executor/codex.d.ts +1 -0
- package/vendor/runtime/dist/executor/codex.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codex.js +68 -36
- package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts +4 -1
- package/vendor/runtime/dist/executor/codexProtocol/FunctionCallOutputContentItem.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts +3 -0
- package/vendor/runtime/dist/executor/codexProtocol/Personality.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/PlanType.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts +6 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/CyberAccessProgram.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts +5 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/GetAccountRateLimitsResponse.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts +8 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/Model.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts +11 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ModelAccessPrograms.js +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts +4 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/RateLimitSnapshot.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts +2 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/ReviewStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts +4 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadResumeParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts +3 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/ThreadStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts +7 -2
- package/vendor/runtime/dist/executor/codexProtocol/v2/TurnStartParams.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts +3 -0
- package/vendor/runtime/dist/executor/codexProtocol/v2/UserInput.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexRpc.d.ts +10 -3
- package/vendor/runtime/dist/executor/codexRpc.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/codexRpc.js +18 -3
- package/vendor/runtime/dist/executor/codexSessions.d.ts +30 -0
- package/vendor/runtime/dist/executor/codexSessions.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/codexSessions.js +88 -0
- package/vendor/runtime/dist/executor/health.d.ts +2 -1
- package/vendor/runtime/dist/executor/health.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/health.js +17 -5
- package/vendor/runtime/dist/executor/liveTurns.d.ts +2 -1
- package/vendor/runtime/dist/executor/liveTurns.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/liveTurns.js +12 -5
- package/vendor/runtime/dist/executor/ownership.d.ts +35 -0
- package/vendor/runtime/dist/executor/ownership.d.ts.map +1 -0
- package/vendor/runtime/dist/executor/ownership.js +99 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts +1 -0
- package/vendor/runtime/dist/executor/providerRouter.d.ts.map +1 -1
- package/vendor/runtime/dist/executor/providerRouter.js +5 -0
- package/vendor/runtime/dist/executor/types.d.ts +2 -0
- package/vendor/runtime/dist/executor/types.d.ts.map +1 -1
- package/vendor/runtime/dist/index.d.ts +1 -0
- package/vendor/runtime/dist/index.d.ts.map +1 -1
- package/vendor/runtime/dist/index.js +1 -0
- package/vendor/runtime/src/executor/asyncQueue.ts +3 -0
- package/vendor/runtime/src/executor/claudeAgent.ts +16 -9
- package/vendor/runtime/src/executor/codex.ts +75 -44
- package/vendor/runtime/src/executor/codexProtocol/FunctionCallOutputContentItem.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/Personality.ts +3 -0
- package/vendor/runtime/src/executor/codexProtocol/PlanType.ts +1 -1
- package/vendor/runtime/src/executor/codexProtocol/README.md +2 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/CyberAccessProgram.ts +9 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/GetAccountRateLimitsResponse.ts +5 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/Model.ts +11 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/ModelAccessPrograms.ts +13 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/RateLimitSnapshot.ts +5 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ReviewStartParams.ts +2 -0
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadResumeParams.ts +5 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/ThreadStartParams.ts +4 -1
- package/vendor/runtime/src/executor/codexProtocol/v2/TurnStartParams.ts +7 -2
- package/vendor/runtime/src/executor/codexProtocol/v2/UserInput.ts +1 -1
- package/vendor/runtime/src/executor/codexRpc.ts +22 -4
- package/vendor/runtime/src/executor/codexSessions.ts +108 -0
- package/vendor/runtime/src/executor/health.ts +16 -6
- package/vendor/runtime/src/executor/liveTurns.ts +12 -5
- package/vendor/runtime/src/executor/ownership.ts +76 -0
- package/vendor/runtime/src/executor/providerRouter.ts +6 -0
- package/vendor/runtime/src/executor/types.ts +2 -0
- package/vendor/runtime/src/index.ts +1 -0
- package/vendor/shared/dist/agentCommands.d.ts +1 -0
- package/vendor/shared/dist/agentCommands.d.ts.map +1 -1
- package/vendor/shared/dist/cardStudio.d.ts +41 -0
- package/vendor/shared/dist/cardStudio.d.ts.map +1 -1
- package/vendor/shared/dist/cardStudio.js +13 -3
- package/vendor/shared/dist/computer.d.ts +7 -1
- package/vendor/shared/dist/computer.d.ts.map +1 -1
- package/vendor/shared/dist/computer.js +12 -2
- package/vendor/shared/dist/constants.d.ts +3 -3
- package/vendor/shared/dist/constants.d.ts.map +1 -1
- package/vendor/shared/dist/constants.js +5 -4
- package/vendor/shared/dist/goalNotes.d.ts +4 -0
- package/vendor/shared/dist/goalNotes.d.ts.map +1 -0
- package/vendor/shared/dist/goalNotes.js +23 -0
- package/vendor/shared/dist/goals.d.ts +835 -0
- package/vendor/shared/dist/goals.d.ts.map +1 -0
- package/vendor/shared/dist/goals.js +198 -0
- package/vendor/shared/dist/index.d.ts +3 -0
- package/vendor/shared/dist/index.d.ts.map +1 -1
- package/vendor/shared/dist/index.js +3 -0
- package/vendor/shared/dist/schemas/harness.d.ts +101 -0
- package/vendor/shared/dist/schemas/harness.d.ts.map +1 -1
- package/vendor/shared/dist/schemas/harness.js +6 -0
- package/vendor/shared/dist/workspaces.d.ts +138 -0
- package/vendor/shared/dist/workspaces.d.ts.map +1 -0
- package/vendor/shared/dist/workspaces.js +40 -0
- package/vendor/shared/src/agentCommands.ts +1 -0
- package/vendor/shared/src/cardStudio.ts +13 -3
- package/vendor/shared/src/computer.ts +16 -2
- package/vendor/shared/src/constants.ts +5 -4
- package/vendor/shared/src/goalNotes.ts +23 -0
- package/vendor/shared/src/goals.ts +237 -0
- package/vendor/shared/src/index.ts +4 -0
- package/vendor/shared/src/schemas/harness.ts +6 -0
- package/vendor/shared/src/workspaces.ts +48 -0
- package/dist/coding/fleetIntegrate.d.ts +0 -37
- package/dist/coding/fleetIntegrate.d.ts.map +0 -1
- package/dist/coding/fleetIntegrate.js +0 -64
- package/dist/coding/openFleetPr.d.ts +0 -41
- package/dist/coding/openFleetPr.d.ts.map +0 -1
- package/dist/coding/openFleetPr.js +0 -121
- package/src/coding/fleetIntegrate.ts +0 -95
- package/src/coding/openFleetPr.ts +0 -148
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// @ts-expect-error Node 22 runtime API; the repository's Node type baseline is 20.
|
|
2
|
+
import { DatabaseSync } from 'node:sqlite';
|
|
3
|
+
import { chmodSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { dirname } from 'node:path';
|
|
5
|
+
import type { HarnessRequest } from '@lucidity/shared';
|
|
6
|
+
import type { TurnFrame, TurnState } from './turnLog.js';
|
|
7
|
+
|
|
8
|
+
const terminalTypes = new Set(['done', 'error', 'cancelled']);
|
|
9
|
+
|
|
10
|
+
function canonical(value: unknown): string {
|
|
11
|
+
if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
|
|
12
|
+
if (value && typeof value === 'object')
|
|
13
|
+
return `{${Object.entries(value).filter(([, v]) => v !== undefined).sort(([a], [b]) => a.localeCompare(b)).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).join(',')}}`;
|
|
14
|
+
return JSON.stringify(value);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function conversationKey(request: { kind: string; repoId?: string; workerId?: string; mode?: string }): string {
|
|
18
|
+
return request.kind === 'code'
|
|
19
|
+
? JSON.stringify(['code', request.repoId, request.workerId ?? request.mode ?? 'worktree'])
|
|
20
|
+
: request.kind;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Local execution authority. Transactions commit before their receipts reach the transport. */
|
|
24
|
+
export class RuntimeStore {
|
|
25
|
+
private db: any;
|
|
26
|
+
private storageError?: Error;
|
|
27
|
+
get writable(): boolean { return !this.storageError; }
|
|
28
|
+
private write<T>(action: () => T): T {
|
|
29
|
+
if (this.storageError) throw new Error(`Runtime storage is unavailable until restart: ${this.storageError.message}`);
|
|
30
|
+
try { return action(); }
|
|
31
|
+
catch (error) {
|
|
32
|
+
const code = (error as { code?: string })?.code ?? '';
|
|
33
|
+
if (code.includes('SQLITE') || code === 'ERR_INVALID_STATE')
|
|
34
|
+
this.storageError = error instanceof Error ? error : new Error(String(error));
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
constructor(path: string) {
|
|
39
|
+
mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
|
|
40
|
+
this.db = new DatabaseSync(path);
|
|
41
|
+
chmodSync(path, 0o600);
|
|
42
|
+
this.db.exec(`
|
|
43
|
+
PRAGMA journal_mode=WAL;
|
|
44
|
+
PRAGMA synchronous=FULL;
|
|
45
|
+
PRAGMA busy_timeout=5000;
|
|
46
|
+
CREATE TABLE IF NOT EXISTS runs (
|
|
47
|
+
id TEXT PRIMARY KEY, command TEXT, conversation TEXT,
|
|
48
|
+
state TEXT NOT NULL DEFAULT 'accepted', cursor INTEGER NOT NULL DEFAULT 0,
|
|
49
|
+
terminal TEXT, updated INTEGER NOT NULL
|
|
50
|
+
);
|
|
51
|
+
CREATE INDEX IF NOT EXISTS runs_conversation ON runs(conversation, updated);
|
|
52
|
+
CREATE TABLE IF NOT EXISTS events (
|
|
53
|
+
run_id TEXT NOT NULL, seq INTEGER NOT NULL, frame TEXT NOT NULL,
|
|
54
|
+
PRIMARY KEY(run_id, seq)
|
|
55
|
+
);
|
|
56
|
+
CREATE TABLE IF NOT EXISTS records (
|
|
57
|
+
bucket TEXT NOT NULL, id TEXT NOT NULL, value TEXT NOT NULL,
|
|
58
|
+
PRIMARY KEY(bucket, id)
|
|
59
|
+
);
|
|
60
|
+
`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
transaction<T>(action: () => T): T {
|
|
64
|
+
return this.write(() => {
|
|
65
|
+
this.db.exec('BEGIN IMMEDIATE');
|
|
66
|
+
try {
|
|
67
|
+
const result = action();
|
|
68
|
+
this.db.exec('COMMIT');
|
|
69
|
+
return result;
|
|
70
|
+
} catch (error) {
|
|
71
|
+
try { this.db.exec('ROLLBACK'); } catch { /* preserve the original storage failure */ }
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
get<T>(bucket: string, id: string): T | undefined {
|
|
78
|
+
const row = this.db.prepare('SELECT value FROM records WHERE bucket=? AND id=?').get(bucket, id);
|
|
79
|
+
return row ? JSON.parse(row.value) as T : undefined;
|
|
80
|
+
}
|
|
81
|
+
set(bucket: string, id: string, value: unknown): void {
|
|
82
|
+
this.write(() => this.db.prepare('INSERT INTO records VALUES (?, ?, ?) ON CONFLICT(bucket,id) DO UPDATE SET value=excluded.value')
|
|
83
|
+
.run(bucket, id, JSON.stringify(value)));
|
|
84
|
+
}
|
|
85
|
+
list<T>(bucket: string): T[] {
|
|
86
|
+
return this.db.prepare('SELECT value FROM records WHERE bucket=? ORDER BY rowid').all(bucket)
|
|
87
|
+
.map((row: { value: string }) => JSON.parse(row.value) as T);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The command and its first replayable receipt are one durable operation. */
|
|
91
|
+
accept(request: HarnessRequest, queuedEntry?: unknown): { duplicate: boolean; frames: TurnFrame[] } {
|
|
92
|
+
return this.transaction(() => {
|
|
93
|
+
const payload = canonical(request);
|
|
94
|
+
const old = this.db.prepare('SELECT command, cursor FROM runs WHERE id=?').get(request.id);
|
|
95
|
+
if (old?.command && old.command !== payload)
|
|
96
|
+
throw new Error('This request ID already belongs to different input.');
|
|
97
|
+
if (old) return { duplicate: true, frames: this.read(request.id).frames };
|
|
98
|
+
this.db.prepare('INSERT INTO runs (id,command,conversation,updated) VALUES (?,?,?,?)')
|
|
99
|
+
.run(request.id, payload, conversationKey(request), Date.now());
|
|
100
|
+
const scope = {
|
|
101
|
+
kind: request.kind,
|
|
102
|
+
...('repoId' in request ? { repoId: request.repoId } : {}),
|
|
103
|
+
...('workerId' in request ? { workerId: request.workerId } : {}),
|
|
104
|
+
...('mode' in request ? { mode: request.mode } : {}),
|
|
105
|
+
};
|
|
106
|
+
const frames = [this.appendInside(request.id, { type: 'accepted', requestId: request.id, scope })];
|
|
107
|
+
if (queuedEntry) {
|
|
108
|
+
this.set('queue', request.id, queuedEntry);
|
|
109
|
+
frames.push(this.appendInside(request.id, { type: 'queue_state', requestId: request.id, state: 'queued' }));
|
|
110
|
+
}
|
|
111
|
+
return { duplicate: false, frames };
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
private appendInside(id: string, event: Record<string, unknown>): TurnFrame {
|
|
116
|
+
this.db.prepare('INSERT OR IGNORE INTO runs (id,updated) VALUES (?,?)').run(id, Date.now());
|
|
117
|
+
const run = this.db.prepare('SELECT cursor, terminal FROM runs WHERE id=?').get(id);
|
|
118
|
+
if (run.terminal) {
|
|
119
|
+
// Reconfirm the committed outcome, never continue a completed attempt.
|
|
120
|
+
this.set('protocol-fault', id, { type: event.type, at: new Date().toISOString() });
|
|
121
|
+
return JSON.parse(run.terminal);
|
|
122
|
+
}
|
|
123
|
+
const frame = { ...event, seq: run.cursor + 1 };
|
|
124
|
+
const serialized = JSON.stringify(frame);
|
|
125
|
+
const terminal = terminalTypes.has(String(event.type));
|
|
126
|
+
const state = terminal ? String(event.type) : event.type === 'accepted' ? 'accepted' : event.type === 'queue_state' ? String(event.state) : 'running';
|
|
127
|
+
this.db.prepare('INSERT INTO events VALUES (?,?,?)').run(id, frame.seq, serialized);
|
|
128
|
+
this.db.prepare('UPDATE runs SET cursor=?, terminal=?, state=?, updated=? WHERE id=?')
|
|
129
|
+
.run(frame.seq, terminal ? serialized : null, state, Date.now(), id);
|
|
130
|
+
return frame;
|
|
131
|
+
}
|
|
132
|
+
append(id: string, event: Record<string, unknown>): TurnFrame {
|
|
133
|
+
return this.transaction(() => this.appendInside(id, event));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
status(id: string): Omit<TurnState, 'frames'> {
|
|
137
|
+
const run = this.db.prepare('SELECT cursor, terminal FROM runs WHERE id=?').get(id);
|
|
138
|
+
return { exists: !!run, maxSeq: run?.cursor ?? 0, terminated: !!run?.terminal };
|
|
139
|
+
}
|
|
140
|
+
read(id: string): TurnState {
|
|
141
|
+
const status = this.status(id);
|
|
142
|
+
if (!status.exists) return { ...status, frames: [] };
|
|
143
|
+
const frames = this.db.prepare('SELECT frame FROM events WHERE run_id=? ORDER BY seq').all(id)
|
|
144
|
+
.map((row: { frame: string }) => JSON.parse(row.frame) as TurnFrame);
|
|
145
|
+
return { ...status, frames };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
importLog(id: string, state: TurnState): void {
|
|
149
|
+
if (!state.exists || this.read(id).exists) return;
|
|
150
|
+
this.transaction(() => {
|
|
151
|
+
const last = [...state.frames].reverse().find((f) => terminalTypes.has(String(f.type)));
|
|
152
|
+
this.db.prepare('INSERT OR IGNORE INTO runs (id,cursor,terminal,state,updated) VALUES (?,?,?,?,?)')
|
|
153
|
+
.run(id, state.maxSeq, last ? JSON.stringify(last) : null, last ? String(last.type) : 'interrupted_unknown', Date.now());
|
|
154
|
+
for (const frame of state.frames)
|
|
155
|
+
this.db.prepare('INSERT OR IGNORE INTO events VALUES (?,?,?)').run(id, frame.seq, JSON.stringify(frame));
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
commands(conversation: string, page?: { before?: string; after?: string; limit: number }): { request: HarnessRequest; state: TurnState }[] {
|
|
160
|
+
const rows: { id: string; command: string }[] = page
|
|
161
|
+
? this.db.prepare(`SELECT id,command FROM runs WHERE conversation=? AND command IS NOT NULL
|
|
162
|
+
AND rowid < COALESCE((SELECT rowid FROM runs WHERE id=?), 9223372036854775807)
|
|
163
|
+
AND rowid > COALESCE((SELECT rowid FROM runs WHERE id=?), 0)
|
|
164
|
+
ORDER BY rowid DESC LIMIT ?`).all(conversation, page.before ?? '', page.after ?? '', page.limit).reverse()
|
|
165
|
+
: this.db.prepare('SELECT id,command FROM runs WHERE conversation=? AND command IS NOT NULL ORDER BY rowid').all(conversation);
|
|
166
|
+
return rows.map((row) => ({ request: JSON.parse(row.command), state: this.read(row.id) }));
|
|
167
|
+
}
|
|
168
|
+
latestSession(conversation: string, after?: string): string | undefined {
|
|
169
|
+
return this.db.prepare(`SELECT json_extract(events.frame, '$.sessionId') AS session
|
|
170
|
+
FROM runs JOIN events ON events.run_id=runs.id WHERE runs.conversation=?
|
|
171
|
+
AND json_type(events.frame, '$.sessionId')='text'
|
|
172
|
+
AND runs.rowid > COALESCE((SELECT rowid FROM runs WHERE id=?), 0)
|
|
173
|
+
ORDER BY runs.rowid DESC, events.seq DESC LIMIT 1`).get(conversation, after ?? '')?.session;
|
|
174
|
+
}
|
|
175
|
+
lastCommand(conversation: string): string | undefined {
|
|
176
|
+
return this.db.prepare('SELECT id FROM runs WHERE conversation=? AND command IS NOT NULL ORDER BY rowid DESC LIMIT 1').get(conversation)?.id;
|
|
177
|
+
}
|
|
178
|
+
unfinished(conversation: string): boolean {
|
|
179
|
+
return !!this.db.prepare('SELECT id FROM runs WHERE conversation=? AND terminal IS NULL LIMIT 1').get(conversation);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
reconcile(owns: (id: string) => boolean): void {
|
|
183
|
+
for (const row of this.db.prepare('SELECT id FROM runs WHERE terminal IS NULL').all() as { id: string }[]) {
|
|
184
|
+
if (owns(row.id)) continue;
|
|
185
|
+
this.append(row.id, { type: 'error', requestId: row.id, code: 'interrupted_unknown',
|
|
186
|
+
message: 'Lucid restarted before this turn settled. It was not run again. Review its work before continuing.' });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
close(): void { this.db.close(); }
|
|
190
|
+
}
|
package/src/setup/server.ts
CHANGED
|
@@ -122,7 +122,7 @@ export async function checkSetupProviders() {
|
|
|
122
122
|
message: '',
|
|
123
123
|
};
|
|
124
124
|
} catch (e) {
|
|
125
|
-
const health = providerFailure(e);
|
|
125
|
+
const health = providerFailure(e) ?? { auth: 'unknown', problem: 'unavailable' };
|
|
126
126
|
return {
|
|
127
127
|
id,
|
|
128
128
|
label: id === 'claude' ? 'Claude' : 'Codex',
|
package/src/turnLog.ts
CHANGED
|
@@ -9,23 +9,12 @@ import {
|
|
|
9
9
|
} from 'node:fs';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
11
|
import { TURNS_DIR } from './config.js';
|
|
12
|
+
import { RuntimeStore } from './runtimeStore.js';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* appended (with a monotonic `seq`) BEFORE it goes on the socket, so a frame produced
|
|
18
|
-
* while the socket is down — or while the phone is away — survives on disk. The phone
|
|
19
|
-
* recovers by sending a `pull` request; the daemon replays `readState().frames` after
|
|
20
|
-
* the phone's `sinceSeq`.
|
|
21
|
-
*
|
|
22
|
-
* The daemon OWNS `seq` here (starting at 1, per requestId). This is the linchpin of the
|
|
23
|
-
* whole recovery scheme: the same `seq` must appear on the live-forwarded frame, the
|
|
24
|
-
* server's replay-on-rejoin, and a daemon pull, so the phone can de-dup across all three.
|
|
25
|
-
* The relay forwards frames verbatim (it no longer stamps `seq`).
|
|
26
|
-
*
|
|
27
|
-
* Never throws — a logging or disk error must not take a turn down; it just makes that
|
|
28
|
-
* turn unrecoverable (the live frame still goes out). Mirrors `runlog.ts`.
|
|
15
|
+
* SQLite owns command receipts and ordered run events. JSONL files remain bounded
|
|
16
|
+
* diagnostic exports and are imported once when opening an older installation.
|
|
17
|
+
* A storage failure rejects admission or propagates to the execution owner.
|
|
29
18
|
*/
|
|
30
19
|
|
|
31
20
|
/** A logged frame: the exact wire frame plus its daemon-authored `seq`. */
|
|
@@ -114,59 +103,13 @@ function appendLine(path: string, line: string): boolean {
|
|
|
114
103
|
}
|
|
115
104
|
}
|
|
116
105
|
|
|
117
|
-
/**
|
|
118
|
-
* One turn's log. Owns the per-requestId `seq` counter (a shared handle, NOT a closure
|
|
119
|
-
* local, so a concurrent `cancel`'s terminal frame gets the next `seq` on the same
|
|
120
|
-
* counter). Seeds itself from any existing file so seq keeps climbing across a daemon
|
|
121
|
-
* restart (a re-created handle resumes from the file's `maxSeq`).
|
|
122
|
-
*/
|
|
123
|
-
export class TurnLog {
|
|
124
|
-
private readonly path: string;
|
|
125
|
-
private readonly maxBytes: number;
|
|
126
|
-
private nextSeq: number;
|
|
127
|
-
private bytes: number;
|
|
128
|
-
private terminatedFlag: boolean;
|
|
129
|
-
|
|
130
|
-
constructor(requestId: string, dir: string, maxBytes = MAX_TURN_LOG_BYTES) {
|
|
131
|
-
this.path = join(dir, `${requestId}.jsonl`);
|
|
132
|
-
this.maxBytes = maxBytes;
|
|
133
|
-
const st = scanTurnFile(this.path);
|
|
134
|
-
this.nextSeq = st.maxSeq + 1;
|
|
135
|
-
this.bytes = st.bytes;
|
|
136
|
-
this.terminatedFlag = st.terminated;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
get terminated(): boolean {
|
|
140
|
-
return this.terminatedFlag;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/** Stamp the next `seq`, append the frame (unless a droppable delta past the byte cap),
|
|
144
|
-
* and return the stamped frame to put on the wire. */
|
|
145
|
-
write(event: Record<string, unknown>): TurnFrame {
|
|
146
|
-
const seq = this.nextSeq++;
|
|
147
|
-
const frame: TurnFrame = { ...event, seq };
|
|
148
|
-
const type = typeof event.type === 'string' ? event.type : '';
|
|
149
|
-
const droppable = type === 'delta' && this.bytes >= this.maxBytes;
|
|
150
|
-
if (!droppable) {
|
|
151
|
-
const line = JSON.stringify(frame) + '\n';
|
|
152
|
-
if (appendLine(this.path, line))
|
|
153
|
-
this.bytes += Buffer.byteLength(line, 'utf8');
|
|
154
|
-
}
|
|
155
|
-
if (isTerminalType(type)) this.terminatedFlag = true;
|
|
156
|
-
return frame;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* All turn logs for this daemon. Keeps an in-memory {@link TurnLog} per in-flight turn
|
|
162
|
-
* (the live seq counter), dropped once the turn terminates — the file lives on for 24h.
|
|
163
|
-
* The file is the source of truth for replay ({@link read}).
|
|
164
|
-
*/
|
|
106
|
+
/** Compatibility reader/exporter around the transactional local runtime ledger. */
|
|
165
107
|
export class TurnLogStore {
|
|
166
108
|
private readonly dir: string;
|
|
167
109
|
private readonly clock: () => number;
|
|
168
110
|
private readonly maxBytes: number;
|
|
169
|
-
private readonly
|
|
111
|
+
private readonly exportBytes = new Map<string, number>();
|
|
112
|
+
readonly runtime: RuntimeStore;
|
|
170
113
|
|
|
171
114
|
queueDirectory(): string {
|
|
172
115
|
return join(this.dir, 'queue');
|
|
@@ -178,6 +121,7 @@ export class TurnLogStore {
|
|
|
178
121
|
this.dir = opts.dir ?? TURNS_DIR;
|
|
179
122
|
this.clock = opts.now ?? Date.now;
|
|
180
123
|
this.maxBytes = opts.maxBytes ?? MAX_TURN_LOG_BYTES;
|
|
124
|
+
this.runtime = new RuntimeStore(join(this.dir, 'runtime.sqlite'));
|
|
181
125
|
try {
|
|
182
126
|
mkdirSync(this.dir, { recursive: true });
|
|
183
127
|
} catch {
|
|
@@ -187,24 +131,37 @@ export class TurnLogStore {
|
|
|
187
131
|
|
|
188
132
|
/** Log + stamp one outgoing stream frame; returns the stamped frame to send. */
|
|
189
133
|
append(requestId: string, event: Record<string, unknown>): TurnFrame {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
134
|
+
if (!this.runtime.status(requestId).exists) this.read(requestId);
|
|
135
|
+
const before = this.runtime.status(requestId);
|
|
136
|
+
const frame = this.runtime.append(requestId, event);
|
|
137
|
+
if (before.terminated) return frame;
|
|
138
|
+
// Bounded diagnostic exports are optional; a failed export never loses the SQLite event.
|
|
139
|
+
const path = join(this.dir, `${requestId}.jsonl`);
|
|
140
|
+
const bytes = this.exportBytes.get(requestId) ?? (existsSync(path) ? statSync(path).size : 0);
|
|
141
|
+
if (event.type !== 'delta' || bytes < this.maxBytes) {
|
|
142
|
+
const line = JSON.stringify(frame) + '\n';
|
|
143
|
+
if (appendLine(path, line)) this.exportBytes.set(requestId, bytes + Buffer.byteLength(line));
|
|
194
144
|
}
|
|
195
|
-
|
|
196
|
-
if (log.terminated) this.logs.delete(requestId); // free memory; file persists
|
|
145
|
+
if (TERMINAL_TYPES.has(String(event.type))) this.exportBytes.delete(requestId);
|
|
197
146
|
return frame;
|
|
198
147
|
}
|
|
199
148
|
|
|
200
|
-
/** The durable state of a turn, read from disk — for serving a `pull`. */
|
|
201
149
|
read(requestId: string): TurnState {
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
);
|
|
205
|
-
return
|
|
150
|
+
const state = this.runtime.read(requestId);
|
|
151
|
+
if (state.exists) return state;
|
|
152
|
+
this.runtime.importLog(requestId, scanTurnFile(join(this.dir, `${requestId}.jsonl`)));
|
|
153
|
+
return this.runtime.read(requestId);
|
|
206
154
|
}
|
|
207
155
|
|
|
156
|
+
/** Startup recovery is independent of whether a phone asks to replay a turn. */
|
|
157
|
+
reconcile(owns: (id: string) => boolean): void {
|
|
158
|
+
for (const name of readdirSync(this.dir))
|
|
159
|
+
if (name.endsWith('.jsonl')) this.read(name.slice(0, -6));
|
|
160
|
+
this.runtime.reconcile(owns);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
close(): void { this.runtime.close(); }
|
|
164
|
+
|
|
208
165
|
/** Delete turn logs whose file hasn't been touched in `maxAgeMs`. Never throws. */
|
|
209
166
|
prune(maxAgeMs: number = TURN_LOG_MAX_AGE_MS): void {
|
|
210
167
|
const now = this.clock();
|
|
@@ -8,6 +8,7 @@ import { registerTaskTrashTools } from './tools/taskTrash.js';
|
|
|
8
8
|
import { registerTaskOccurrenceTools } from './tools/taskOccurrences.js';
|
|
9
9
|
import { setClientNameReader } from './client.js';
|
|
10
10
|
import { registerProjectTools } from './tools/projects.js';
|
|
11
|
+
import { registerGoalTools } from './tools/goals.js';
|
|
11
12
|
import { registerQueryTools } from './tools/queries.js';
|
|
12
13
|
import { registerMilestoneTools } from './tools/milestones.js';
|
|
13
14
|
import { registerCommentTools } from './tools/comments.js';
|
|
@@ -31,6 +32,7 @@ registerTaskActivityTools(server);
|
|
|
31
32
|
registerTaskTrashTools(server);
|
|
32
33
|
registerTaskOccurrenceTools(server);
|
|
33
34
|
registerProjectTools(server);
|
|
35
|
+
registerGoalTools(server);
|
|
34
36
|
registerQueryTools(server);
|
|
35
37
|
registerMilestoneTools(server);
|
|
36
38
|
registerCommentTools(server);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"goals.d.ts","sourceRoot":"","sources":["../../src/tools/goals.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAWzE,6EAA6E;AAC7E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,SAAS,QAiDlD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from '#lucidity-zod';
|
|
2
|
+
import { apiRequest } from '../client.js';
|
|
3
|
+
/** Discussion can inspect goals; it cannot approve its own proposed work. */
|
|
4
|
+
export function registerGoalTools(server) {
|
|
5
|
+
const annotations = {
|
|
6
|
+
readOnlyHint: true,
|
|
7
|
+
destructiveHint: false,
|
|
8
|
+
idempotentHint: true,
|
|
9
|
+
openWorldHint: false,
|
|
10
|
+
};
|
|
11
|
+
server.tool('list_goals', 'List personal goals, their timeframes and latest dated observations. Missing checks do not mean inactivity.', {}, annotations, async () => {
|
|
12
|
+
const result = await apiRequest('/api/goals');
|
|
13
|
+
return {
|
|
14
|
+
content: [
|
|
15
|
+
{
|
|
16
|
+
type: 'text',
|
|
17
|
+
text: JSON.stringify(result.goals.map(({ goal, checks }) => ({
|
|
18
|
+
goal,
|
|
19
|
+
latestCheck: checks.find((check) => check.cadence === 'daily') ?? null,
|
|
20
|
+
}))),
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
server.tool('get_goal', 'Read one personal goal with linked sources, evidence, reviews and draft proposals. Work must be approved in the app; a context link is not permission to act.', { id: z.string().uuid() }, annotations, async ({ id }) => {
|
|
26
|
+
const result = await apiRequest('/api/goals');
|
|
27
|
+
const goal = result.goals.find((detail) => detail.goal.id === id);
|
|
28
|
+
return {
|
|
29
|
+
content: [
|
|
30
|
+
{
|
|
31
|
+
type: 'text',
|
|
32
|
+
text: goal ? JSON.stringify(goal) : 'Goal not found.',
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
isError: !goal,
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -9,6 +9,7 @@ import { registerTaskTrashTools } from './tools/taskTrash.js';
|
|
|
9
9
|
import { registerTaskOccurrenceTools } from './tools/taskOccurrences.js';
|
|
10
10
|
import { setClientNameReader } from './client.js';
|
|
11
11
|
import { registerProjectTools } from './tools/projects.js';
|
|
12
|
+
import { registerGoalTools } from './tools/goals.js';
|
|
12
13
|
import { registerQueryTools } from './tools/queries.js';
|
|
13
14
|
import { registerMilestoneTools } from './tools/milestones.js';
|
|
14
15
|
import { registerCommentTools } from './tools/comments.js';
|
|
@@ -41,6 +42,7 @@ registerTaskActivityTools(server);
|
|
|
41
42
|
registerTaskTrashTools(server);
|
|
42
43
|
registerTaskOccurrenceTools(server);
|
|
43
44
|
registerProjectTools(server);
|
|
45
|
+
registerGoalTools(server);
|
|
44
46
|
registerQueryTools(server);
|
|
45
47
|
registerMilestoneTools(server);
|
|
46
48
|
registerCommentTools(server);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
|
+
import { z } from '#lucidity-zod';
|
|
3
|
+
import { apiRequest } from '../client.js';
|
|
4
|
+
// This independently published package keeps its small API projection local.
|
|
5
|
+
interface GoalsSnapshot {
|
|
6
|
+
goals: {
|
|
7
|
+
goal: { id: string; [key: string]: unknown };
|
|
8
|
+
checks: { cadence: string; [key: string]: unknown }[];
|
|
9
|
+
}[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Discussion can inspect goals; it cannot approve its own proposed work. */
|
|
13
|
+
export function registerGoalTools(server: McpServer) {
|
|
14
|
+
const annotations = {
|
|
15
|
+
readOnlyHint: true,
|
|
16
|
+
destructiveHint: false,
|
|
17
|
+
idempotentHint: true,
|
|
18
|
+
openWorldHint: false,
|
|
19
|
+
};
|
|
20
|
+
server.tool(
|
|
21
|
+
'list_goals',
|
|
22
|
+
'List personal goals, their timeframes and latest dated observations. Missing checks do not mean inactivity.',
|
|
23
|
+
{},
|
|
24
|
+
annotations,
|
|
25
|
+
async () => {
|
|
26
|
+
const result = await apiRequest<GoalsSnapshot>('/api/goals');
|
|
27
|
+
return {
|
|
28
|
+
content: [
|
|
29
|
+
{
|
|
30
|
+
type: 'text' as const,
|
|
31
|
+
text: JSON.stringify(
|
|
32
|
+
result.goals.map(({ goal, checks }) => ({
|
|
33
|
+
goal,
|
|
34
|
+
latestCheck:
|
|
35
|
+
checks.find((check) => check.cadence === 'daily') ?? null,
|
|
36
|
+
})),
|
|
37
|
+
),
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
);
|
|
43
|
+
server.tool(
|
|
44
|
+
'get_goal',
|
|
45
|
+
'Read one personal goal with linked sources, evidence, reviews and draft proposals. Work must be approved in the app; a context link is not permission to act.',
|
|
46
|
+
{ id: z.string().uuid() },
|
|
47
|
+
annotations,
|
|
48
|
+
async ({ id }) => {
|
|
49
|
+
const result = await apiRequest<GoalsSnapshot>('/api/goals');
|
|
50
|
+
const goal = result.goals.find((detail) => detail.goal.id === id);
|
|
51
|
+
return {
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: 'text' as const,
|
|
55
|
+
text: goal ? JSON.stringify(goal) : 'Goal not found.',
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
isError: !goal,
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
);
|
|
62
|
+
}
|
package/vendor/runtime/README.md
CHANGED
|
@@ -17,9 +17,9 @@ The runtime just turns data into prompts and runs them through an executor.
|
|
|
17
17
|
|
|
18
18
|
**Executor seam** — the boundary between prompt assembly and the model engine:
|
|
19
19
|
- `AgentExecutor`: buffered/streamed runs, active-turn correction, model discovery, and disposal.
|
|
20
|
-
- `ClaudeAgentExecutor`: pinned Agent SDK 0.3.
|
|
20
|
+
- `ClaudeAgentExecutor`: pinned Agent SDK 0.3.287 and its bundled runtime, with subscription
|
|
21
21
|
authentication, streaming input, cancellation, and tool permissions.
|
|
22
|
-
- `CodexExecutor`: pinned Codex 0.
|
|
22
|
+
- `CodexExecutor`: pinned Codex 0.160.0 App Server over local stdio, with ChatGPT login,
|
|
23
23
|
generated protocol types, thread resume, steering, interruption, and scoped MCP tools.
|
|
24
24
|
- `HealthAwareExecutor`: observes authentication and inference failures on the same adapters
|
|
25
25
|
used for interactive and scheduled work. Catalog success leaves allowance unknown;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"asyncQueue.d.ts","sourceRoot":"","sources":["../../src/executor/asyncQueue.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,IAAI,CAAC,CAAa;IAC1B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAAC,CAAQ;IAEtB,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAKnB,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"asyncQueue.d.ts","sourceRoot":"","sources":["../../src/executor/asyncQueue.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,qBAAa,UAAU,CAAC,CAAC,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IACpD,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,IAAI,CAAC,CAAa;IAC1B,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,KAAK,CAAC,CAAQ;IAEtB,IAAI,CAAC,IAAI,EAAE,CAAC,GAAG,IAAI;IAKnB,GAAG,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;IAKxB,cAAc,IAAI,IAAI;IAGf,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC;CAenD"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AgentCommandOption } from '@lucidity/shared';
|
|
2
2
|
import { query, type Options, type AccountInfo } from '@anthropic-ai/claude-agent-sdk';
|
|
3
3
|
import type { AgentExecutor, ExecutorRunInput, ExecutorStreamEvent, ExecutorResult, ExecutorModel } from './types.js';
|
|
4
|
-
export declare const CLAUDE_AGENT_SDK_VERSION = "0.3.
|
|
4
|
+
export declare const CLAUDE_AGENT_SDK_VERSION = "0.3.287";
|
|
5
5
|
export declare function claudeSubscriptionEnv(oauthToken?: string): NodeJS.ProcessEnv;
|
|
6
6
|
export declare function claudeAgentOptions(input: ExecutorRunInput, oauthToken?: string): Options;
|
|
7
7
|
/** Check resolved authentication after settings load, before sending any prompt. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claudeAgent.d.ts","sourceRoot":"","sources":["../../src/executor/claudeAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,KAAK,EACL,KAAK,OAAO,EAGZ,KAAK,WAAW,EACjB,MAAM,gCAAgC,CAAC;AAIxC,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,wBAAwB,YAAY,CAAC;AAIlD,wBAAgB,qBAAqB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAa5E;AA4BD,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,gBAAgB,EACvB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CA8ET;AAED,oFAAoF;AACpF,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAuBpE;AAmBD,mFAAmF;AACnF,qBAAa,mBAAoB,YAAW,aAAa;IAKrD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,QAAQ,CAAC,IAAI,sBAAsB;IACnC,QAAQ,CAAC,YAAY,QAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;gBAEtB,OAAO,GAAE;QACxB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;KACjB;IAGR,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAG/B,SAAS,CAAC,SAAS,EAAE,MAAM;IAG3B,OAAO;IAIb,gFAAgF;IAC1E,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"claudeAgent.d.ts","sourceRoot":"","sources":["../../src/executor/claudeAgent.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,KAAK,EACL,KAAK,OAAO,EAGZ,KAAK,WAAW,EACjB,MAAM,gCAAgC,CAAC;AAIxC,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,aAAa,EACd,MAAM,YAAY,CAAC;AAEpB,eAAO,MAAM,wBAAwB,YAAY,CAAC;AAIlD,wBAAgB,qBAAqB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,UAAU,CAa5E;AA4BD,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,gBAAgB,EACvB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CA8ET;AAED,oFAAoF;AACpF,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,CAuBpE;AAmBD,mFAAmF;AACnF,qBAAa,mBAAoB,YAAW,aAAa;IAKrD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJ1B,QAAQ,CAAC,IAAI,sBAAsB;IACnC,QAAQ,CAAC,YAAY,QAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;gBAEtB,OAAO,GAAE;QACxB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;KACjB;IAGR,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAG/B,SAAS,CAAC,SAAS,EAAE,MAAM;IAG3B,OAAO;IAIb,gFAAgF;IAC1E,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IA2ClC,QAAQ,CAAC,KAAK,GAAE,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,gBAAgB,GAAG,KAAK,CAAM,GAAG,OAAO,CAAC,kBAAkB,EAAE,CAAC;IAiC7G,GAAG,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IAMpD,SAAS,CACd,KAAK,EAAE,gBAAgB,GACtB,aAAa,CAAC,mBAAmB,CAAC;CA4JtC"}
|
|
@@ -5,7 +5,7 @@ import { query, } from '@anthropic-ai/claude-agent-sdk';
|
|
|
5
5
|
import { stripUnsafeEnv } from './claudeCode.js';
|
|
6
6
|
import { AsyncQueue } from './asyncQueue.js';
|
|
7
7
|
import { LiveTurns } from './liveTurns.js';
|
|
8
|
-
export const CLAUDE_AGENT_SDK_VERSION = '0.3.
|
|
8
|
+
export const CLAUDE_AGENT_SDK_VERSION = '0.3.287';
|
|
9
9
|
const INTERACTIVE_TOOLS = ['AskUserQuestion', 'EnterPlanMode', 'ExitPlanMode'];
|
|
10
10
|
const WRITE_TOOLS = ['Bash', 'Write', 'Edit', 'NotebookEdit'];
|
|
11
11
|
export function claudeSubscriptionEnv(oauthToken) {
|
|
@@ -163,7 +163,7 @@ export class ClaudeAgentExecutor {
|
|
|
163
163
|
return this.turns.interrupt(requestId);
|
|
164
164
|
}
|
|
165
165
|
async dispose() {
|
|
166
|
-
this.turns.dispose();
|
|
166
|
+
await this.turns.dispose();
|
|
167
167
|
}
|
|
168
168
|
/** Start the SDK control channel without ever supplying an inference prompt. */
|
|
169
169
|
async models() {
|
|
@@ -202,6 +202,7 @@ export class ClaudeAgentExecutor {
|
|
|
202
202
|
incoming.end();
|
|
203
203
|
abortController.abort();
|
|
204
204
|
active.close();
|
|
205
|
+
await active.return();
|
|
205
206
|
}
|
|
206
207
|
}
|
|
207
208
|
async commands(input = {}) {
|
|
@@ -231,6 +232,7 @@ export class ClaudeAgentExecutor {
|
|
|
231
232
|
incoming.end();
|
|
232
233
|
abortController.abort();
|
|
233
234
|
active.close();
|
|
235
|
+
await active.return();
|
|
234
236
|
}
|
|
235
237
|
}
|
|
236
238
|
async run(input) {
|
|
@@ -331,12 +333,16 @@ export class ClaudeAgentExecutor {
|
|
|
331
333
|
}
|
|
332
334
|
}
|
|
333
335
|
else if (event.type === 'result') {
|
|
336
|
+
// A priority correction interrupts the old native loop before its own loop
|
|
337
|
+
// starts. The pinned SDK reports this intermediate result before echoing
|
|
338
|
+
// the queued correction. Drain it without turning it into a Lucidity terminal.
|
|
339
|
+
if (pending.size && event.subtype === 'error_during_execution' &&
|
|
340
|
+
event.errors.length === 1 &&
|
|
341
|
+
event.errors[0] === '[ede_diagnostic] result_type=user last_content_type=n/a stop_reason=null')
|
|
342
|
+
continue;
|
|
334
343
|
if (event.subtype !== 'success' || event.is_error) {
|
|
335
|
-
throw new Error((
|
|
336
|
-
|
|
337
|
-
? event.result
|
|
338
|
-
: event.errors.join('\n'))) ||
|
|
339
|
-
`Claude could not complete the turn (${event.subtype}). Check subscription access and usage limits.`);
|
|
344
|
+
throw new Error((event.subtype === 'success' ? event.result : event.errors.join('\n')) ||
|
|
345
|
+
`Claude turn ended with ${event.subtype}.`);
|
|
340
346
|
}
|
|
341
347
|
// A late priority message may become a subsequent loop in this same SDK
|
|
342
348
|
// query. Keep consuming until its echoed user message and result arrive.
|
|
@@ -377,8 +383,13 @@ export class ClaudeAgentExecutor {
|
|
|
377
383
|
finally {
|
|
378
384
|
ended = true;
|
|
379
385
|
incoming.end();
|
|
380
|
-
|
|
381
|
-
|
|
386
|
+
try {
|
|
387
|
+
active?.close();
|
|
388
|
+
await active?.return();
|
|
389
|
+
}
|
|
390
|
+
finally {
|
|
391
|
+
owner.close();
|
|
392
|
+
}
|
|
382
393
|
}
|
|
383
394
|
}
|
|
384
395
|
}
|
|
@@ -9,6 +9,7 @@ export declare class CodexExecutor implements AgentExecutor {
|
|
|
9
9
|
readonly name = "codex-app-server";
|
|
10
10
|
readonly strictResume = true;
|
|
11
11
|
private readonly turns;
|
|
12
|
+
private readonly sessions;
|
|
12
13
|
constructor(options?: {
|
|
13
14
|
command?: string;
|
|
14
15
|
connect?: (cwd?: string) => CodexConnection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/executor/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/executor/codex.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,eAAe,CAAC;AAOvB,OAAO,KAAK,EACV,aAAa,EACb,gBAAgB,EAChB,mBAAmB,EACnB,aAAa,EACb,cAAc,EACf,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AA6BjF,uEAAuE;AACvE,wBAAgB,cAAc,CAC5B,KAAK,EAAE,gBAAgB,EACvB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,WAAW,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAmG1C;AAED,qBAAa,aAAc,YAAW,aAAa;IAM/C,OAAO,CAAC,QAAQ,CAAC,OAAO;IAL1B,QAAQ,CAAC,IAAI,sBAAsB;IACnC,QAAQ,CAAC,YAAY,QAAQ;IAC7B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAmB;IACzC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAuB;gBAE7B,OAAO,GAAE;QACxB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,OAAO,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,MAAM,KAAK,eAAe,CAAC;KACxC;IAER,OAAO,CAAC,OAAO;IAKf,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;IAG/B,SAAS,CAAC,SAAS,EAAE,MAAM;IAG3B,OAAO;IAIP,MAAM,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAgClC,QAAQ,CACZ,KAAK,GAAE,IAAI,CAAC,gBAAgB,EAAE,KAAK,GAAG,gBAAgB,CAAM,GAC3D,OAAO,CAAC,kBAAkB,EAAE,CAAC;IA2C1B,GAAG,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;IAMpD,SAAS,CACd,KAAK,EAAE,gBAAgB,GACtB,aAAa,CAAC,mBAAmB,CAAC;CA6YtC"}
|