@kirkchinese/harness-forge 0.4.0 → 0.5.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 +4 -0
- package/docs/DETAIL.zh.md +47 -0
- package/lib/agents/presets.d.ts +7 -0
- package/lib/agents/presets.js +11 -1
- package/lib/agents/profiles.js +3 -2
- package/lib/agents/row.js +3 -1
- package/lib/client/paths.d.ts +12 -0
- package/lib/client/paths.js +68 -0
- package/lib/client/typert.d.ts +12 -1
- package/lib/client/typert.js +54 -6
- package/lib/client.js +1593 -270
- package/lib/commands/row.js +1 -1
- package/lib/context/instructions.js +5 -5
- package/lib/dsh/host.d.ts +3 -0
- package/lib/dsh/host.js +3 -0
- package/lib/forge/contract.d.ts +42 -2
- package/lib/forge/contract.js +3 -1
- package/lib/forge/follow.d.ts +30 -0
- package/lib/forge/follow.js +73 -0
- package/lib/forge/ledger.d.ts +70 -7
- package/lib/forge/ledger.js +314 -42
- package/lib/forge/projects.d.ts +5 -2
- package/lib/forge/projects.js +23 -16
- package/lib/forge/remote/archive.d.ts +65 -0
- package/lib/forge/remote/archive.js +565 -0
- package/lib/forge/remote/code-parts.d.ts +18 -0
- package/lib/forge/remote/code-parts.js +76 -0
- package/lib/forge/remote/fetch.d.ts +265 -0
- package/lib/forge/remote/fetch.js +1133 -0
- package/lib/forge/remote/service.d.ts +256 -0
- package/lib/forge/remote/service.js +868 -0
- package/lib/forge/service.d.ts +19 -9
- package/lib/forge/service.js +47 -31
- package/lib/forge/settings.d.ts +5 -3
- package/lib/forge/settings.js +11 -4
- package/lib/forge/state.d.ts +60 -0
- package/lib/forge/state.js +174 -58
- package/lib/hooks/broker/engine.js +2 -8
- package/lib/hooks/broker/session-events.d.ts +5 -0
- package/lib/hooks/broker/session-events.js +12 -3
- package/lib/hooks/broker/types.d.ts +7 -5
- package/lib/hooks/condition.d.ts +78 -2
- package/lib/hooks/condition.js +494 -73
- package/lib/hooks/config.d.ts +1 -1
- package/lib/hooks/config.js +4 -0
- package/lib/hooks/glob.d.ts +41 -0
- package/lib/hooks/glob.js +114 -0
- package/lib/hooks/permissions.d.ts +8 -3
- package/lib/hooks/permissions.js +119 -26
- package/lib/hooks/powershell-aliases.d.ts +19 -0
- package/lib/hooks/powershell-aliases.js +58 -0
- package/lib/hooks/process.d.ts +17 -0
- package/lib/hooks/process.js +156 -1
- package/lib/hooks/row.js +2 -0
- package/lib/hooks/runner.d.ts +17 -4
- package/lib/hooks/runner.js +42 -13
- package/lib/hooks/shell-commands.d.ts +10 -1
- package/lib/hooks/shell-commands.js +74 -10
- package/lib/hooks/shell.d.ts +3 -2
- package/lib/hooks/shell.js +5 -2
- package/lib/hooks/vocabulary.js +3 -1
- package/lib/mcp/catalog.d.ts +5 -2
- package/lib/mcp/catalog.js +18 -10
- package/lib/mcp/mount.d.ts +40 -2
- package/lib/mcp/mount.js +131 -31
- package/lib/mcp/policy.d.ts +42 -0
- package/lib/mcp/policy.js +43 -0
- package/lib/mcp/remote.js +5 -15
- package/lib/mcp/row.js +111 -17
- package/lib/mods/loader.js +4 -0
- package/lib/mods/service/turns.d.ts +8 -7
- package/lib/mods/service/turns.js +10 -35
- package/lib/opencode/bun.js +14 -2
- package/lib/opencode/row.d.ts +14 -1
- package/lib/opencode/row.js +38 -20
- package/lib/opencode/runtime/server.js +2 -1
- package/lib/porting/adapter-paths.d.ts +13 -0
- package/lib/porting/adapter-paths.js +120 -0
- package/lib/porting/port-gap.d.ts +10 -4
- package/lib/porting/port-gap.js +43 -7
- package/lib/porting/prompt.js +9 -7
- package/lib/porting/row.js +7 -5
- package/lib/porting/verify-port.d.ts +3 -10
- package/lib/porting/verify-port.js +12 -34
- package/lib/sessions/chat-import.d.ts +48 -0
- package/lib/sessions/chat-import.js +44 -0
- package/lib/sessions/claude.d.ts +16 -10
- package/lib/sessions/claude.js +76 -55
- package/lib/sessions/codex-discover.d.ts +34 -0
- package/lib/sessions/codex-discover.js +205 -0
- package/lib/sessions/codex-meta.d.ts +63 -0
- package/lib/sessions/codex-meta.js +148 -0
- package/lib/sessions/codex-text.d.ts +9 -0
- package/lib/sessions/codex-text.js +44 -0
- package/lib/sessions/codex.d.ts +34 -22
- package/lib/sessions/codex.js +150 -183
- package/lib/sessions/opencode.d.ts +15 -9
- package/lib/sessions/opencode.js +77 -58
- package/lib/sessions/persist.d.ts +162 -0
- package/lib/sessions/persist.js +377 -0
- package/lib/sessions/row.d.ts +2 -1
- package/lib/sessions/row.js +75 -9
- package/lib/sessions/turns.d.ts +31 -0
- package/lib/sessions/turns.js +63 -0
- package/lib/sessions/zstd.d.ts +15 -0
- package/lib/sessions/zstd.js +152 -0
- package/lib/shared/render.d.ts +30 -1
- package/lib/shared/render.js +813 -48
- package/lib/skills/provider.d.ts +2 -0
- package/lib/skills/provider.js +8 -2
- package/lib/skills/row.js +1 -1
- package/lib/workbench/adapter-coverage.d.ts +20 -2
- package/lib/workbench/adapter-coverage.js +46 -7
- package/lib/workbench/overview.d.ts +77 -27
- package/lib/workbench/overview.js +99 -12
- package/lib/workbench/remote.d.ts +64 -21
- package/lib/workbench/remote.js +181 -42
- package/lib/workbench/settings.d.ts +5 -1
- package/lib/workbench/settings.js +6 -2
- package/lib/workbench/workbench.d.ts +34 -4
- package/lib/workbench/workbench.js +147 -46
- package/locale/zh.json +2 -1
- package/package.json +3 -2
- package/lib/forge/marketplace-install.d.ts +0 -3
- package/lib/forge/marketplace-install.js +0 -64
package/lib/sessions/codex.js
CHANGED
|
@@ -1,56 +1,72 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Codex CLI rollout migration. Codex stores one JSONL rollout per session with
|
|
3
|
-
* `session_meta`, `response_item` messages/tool calls, and event markers. This
|
|
4
|
-
* adapter reduces that vocabulary to the shared NormalizedSession model, then
|
|
5
|
-
* the shared session synthesizer emits DSH v4 events.
|
|
6
|
-
* @module @kirkchinese/harness-forge
|
|
7
|
-
*/
|
|
8
|
-
import { readdir } from 'node:fs/promises';
|
|
9
1
|
import { homedir } from 'node:os';
|
|
10
|
-
import { join } from 'node:path';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { assertFileImportable, fileLines, limitBytes, MAX_LINE_BYTES, splitLines } from '@kirkchinese/harness-forge-core';
|
|
4
|
+
import { zstdChunks } from './zstd.js';
|
|
5
|
+
import { stringField, textOf, timestamp, usablePrompt } from './codex-text.js';
|
|
6
|
+
import { codexHomeOf, codexIdentity, codexSessionId, CodexTitle, rolloutCreatedAt, rolloutThread, threadNames } from './codex-meta.js';
|
|
7
|
+
import { importReport, persistImported, targetIdentity } from './persist.js';
|
|
8
|
+
import { replyText, turnReader, turnText } from './turns.js';
|
|
9
|
+
import { codexThreads } from './codex-discover.js';
|
|
10
|
+
export { discoverCodexSessions } from './codex-discover.js';
|
|
11
|
+
export { codexSessionId } from './codex-meta.js';
|
|
13
12
|
/** Default Codex rollout directory. */
|
|
14
13
|
export function defaultCodexSessionsRoot(home = homedir()) {
|
|
15
14
|
return join(home, '.codex', 'sessions');
|
|
16
15
|
}
|
|
17
|
-
/** Discover `rollout-*.jsonl` files newest first. */
|
|
18
|
-
export async function discoverCodexSessions(root = defaultCodexSessionsRoot(), limit = 200) {
|
|
19
|
-
const files = await listRollouts(root);
|
|
20
|
-
const out = [];
|
|
21
|
-
for (const path of files) {
|
|
22
|
-
const meta = await readMeta(path);
|
|
23
|
-
if (meta === undefined)
|
|
24
|
-
continue;
|
|
25
|
-
out.push(meta);
|
|
26
|
-
if (out.length >= limit)
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
out.sort((a, b) => (b.createdAt ?? 0) - (a.createdAt ?? 0));
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
16
|
/** Parse one Codex rollout into the shared normalized model. */
|
|
33
17
|
export async function readCodexSession(path, targetId) {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
18
|
+
const turns = [];
|
|
19
|
+
const parts = rolloutTurns(path);
|
|
20
|
+
let next = await parts.next();
|
|
21
|
+
for (; next.done !== true; next = await parts.next())
|
|
22
|
+
turns.push(next.value);
|
|
23
|
+
const { meta, firstTimestamp, title } = next.value;
|
|
36
24
|
if (meta === undefined)
|
|
37
25
|
throw new Error(`Codex rollout has no session_meta: ${path}`);
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
26
|
+
const thread = rolloutThread(meta);
|
|
27
|
+
if (thread === undefined)
|
|
40
28
|
throw new Error(`Codex rollout has no session id: ${path}`);
|
|
41
|
-
const
|
|
29
|
+
const id = targetId ?? codexSessionId(thread.id);
|
|
30
|
+
const createdAt = rolloutCreatedAt(meta, firstTimestamp);
|
|
42
31
|
const cwd = stringField(meta['cwd']);
|
|
43
|
-
const
|
|
32
|
+
const named = title?.title;
|
|
33
|
+
return {
|
|
34
|
+
session: {
|
|
35
|
+
id,
|
|
36
|
+
source: { tool: 'codex', path, sessionId: id },
|
|
37
|
+
createdAt,
|
|
38
|
+
...(cwd !== undefined ? { cwd } : {}),
|
|
39
|
+
...(named !== undefined ? { title: named } : {}),
|
|
40
|
+
turns: turns,
|
|
41
|
+
},
|
|
42
|
+
...(named !== undefined ? { title: named } : {}),
|
|
43
|
+
thread,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The turns of a rollout, each as soon as the next one starts (what is said in a turn is then complete; a tool
|
|
48
|
+
* result may still reach one of its steps), and then what else the rollout says. Read only as far as it is asked.
|
|
49
|
+
*/
|
|
50
|
+
async function* rolloutTurns(path) {
|
|
51
|
+
/** Turns the record just read completed, to hand out before the next one is read. */
|
|
52
|
+
const closed = [];
|
|
53
|
+
let count = 0;
|
|
54
|
+
let meta;
|
|
55
|
+
let firstTimestamp;
|
|
56
|
+
let seen = false;
|
|
57
|
+
/** The first thing the person said, when no `user_message` event carries it (used only if no turn starts). */
|
|
58
|
+
let fallback;
|
|
44
59
|
let turn;
|
|
45
60
|
let step;
|
|
46
61
|
const pending = new Map();
|
|
47
62
|
let title;
|
|
63
|
+
const names = threadNames(codexHomeOf(path));
|
|
48
64
|
const startTurn = (prompt, at) => {
|
|
49
|
-
|
|
50
|
-
|
|
65
|
+
if (turn !== undefined)
|
|
66
|
+
closed.push(turn);
|
|
67
|
+
count += 1;
|
|
68
|
+
turn = { number: count, prompt, ...(at !== undefined ? { timestamp: at } : {}), steps: [] };
|
|
51
69
|
step = undefined;
|
|
52
|
-
if (title === undefined && prompt.trim().length > 0)
|
|
53
|
-
title = prompt.trim().slice(0, 80);
|
|
54
70
|
};
|
|
55
71
|
const ensureTurn = () => {
|
|
56
72
|
if (turn === undefined)
|
|
@@ -65,10 +81,34 @@ export async function readCodexSession(path, targetId) {
|
|
|
65
81
|
}
|
|
66
82
|
return step;
|
|
67
83
|
};
|
|
68
|
-
|
|
84
|
+
// Text after a tool call opens the next step: in one step it would part the call from its result.
|
|
85
|
+
const bodyStep = (at) => {
|
|
86
|
+
if (step !== undefined && step.toolCalls.length > 0)
|
|
87
|
+
step = undefined;
|
|
88
|
+
return ensureStep(at);
|
|
89
|
+
};
|
|
90
|
+
// One record at a time: a rollout is not held, and what a continued session cannot use (reasoning blobs, image
|
|
91
|
+
// data, token counts) is read past and gone as soon as its line is.
|
|
92
|
+
for await (const record of readRecords(path)) {
|
|
93
|
+
yield* closed.splice(0);
|
|
94
|
+
if (!seen) {
|
|
95
|
+
seen = true;
|
|
96
|
+
firstTimestamp = record.timestamp;
|
|
97
|
+
}
|
|
69
98
|
const payload = record.payload;
|
|
70
99
|
if (payload === undefined)
|
|
71
100
|
continue;
|
|
101
|
+
if (record.type === 'session_meta' && meta === undefined) {
|
|
102
|
+
meta = payload;
|
|
103
|
+
const thread = rolloutThread(payload);
|
|
104
|
+
title = new CodexTitle(thread === undefined ? undefined : (await names).get(thread.id));
|
|
105
|
+
}
|
|
106
|
+
title?.observe(record);
|
|
107
|
+
if (fallback === undefined && record.type === 'response_item' && payload['type'] === 'message' && payload['role'] === 'user') {
|
|
108
|
+
const text = textOf(payload['content']);
|
|
109
|
+
if (text.trim().length > 0 && !text.trimStart().startsWith('<'))
|
|
110
|
+
fallback = text;
|
|
111
|
+
}
|
|
72
112
|
const at = timestamp(record.timestamp) ?? timestamp(payload['timestamp']);
|
|
73
113
|
if (record.type === 'event_msg' && payload['type'] === 'user_message') {
|
|
74
114
|
const prompt = stringField(payload['message']);
|
|
@@ -83,7 +123,7 @@ export async function readCodexSession(path, targetId) {
|
|
|
83
123
|
const role = payload['role'];
|
|
84
124
|
const text = textOf(payload['content']);
|
|
85
125
|
if (role === 'assistant') {
|
|
86
|
-
const current = ensureStep(at);
|
|
126
|
+
const current = text.length > 0 ? bodyStep(at) : ensureStep(at);
|
|
87
127
|
if (text.length > 0)
|
|
88
128
|
current.content = [...current.content, { type: 'text', text }];
|
|
89
129
|
}
|
|
@@ -96,7 +136,7 @@ export async function readCodexSession(path, targetId) {
|
|
|
96
136
|
if (kind === 'reasoning') {
|
|
97
137
|
const text = textOf(payload['summary']) || textOf(payload['content']);
|
|
98
138
|
if (text.length > 0) {
|
|
99
|
-
const current =
|
|
139
|
+
const current = bodyStep(at);
|
|
100
140
|
current.content = [...current.content, { type: 'reasoning', text }];
|
|
101
141
|
}
|
|
102
142
|
continue;
|
|
@@ -122,163 +162,101 @@ export async function readCodexSession(path, targetId) {
|
|
|
122
162
|
continue;
|
|
123
163
|
const result = {
|
|
124
164
|
toolCallId: callId,
|
|
125
|
-
content: [{ type: 'text', text:
|
|
165
|
+
content: [{ type: 'text', text: outputText(payload['output']) }],
|
|
126
166
|
...(at !== undefined ? { timestamp: at } : {}),
|
|
127
167
|
};
|
|
128
168
|
owner.step.toolResults = [...owner.step.toolResults, result];
|
|
129
169
|
pending.delete(callId);
|
|
130
170
|
}
|
|
131
171
|
}
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
startTurn(fallback);
|
|
139
|
-
}
|
|
140
|
-
return {
|
|
141
|
-
session: {
|
|
142
|
-
id,
|
|
143
|
-
source: { tool: 'codex', path, sessionId: id },
|
|
144
|
-
createdAt,
|
|
145
|
-
...(cwd !== undefined ? { cwd } : {}),
|
|
146
|
-
...(title !== undefined ? { title } : {}),
|
|
147
|
-
turns: turns,
|
|
148
|
-
},
|
|
149
|
-
...(title !== undefined ? { title } : {}),
|
|
150
|
-
};
|
|
172
|
+
if (count === 0 && fallback !== undefined)
|
|
173
|
+
startTurn(fallback);
|
|
174
|
+
yield* closed.splice(0);
|
|
175
|
+
if (turn !== undefined)
|
|
176
|
+
yield turn;
|
|
177
|
+
return { meta, firstTimestamp, title };
|
|
151
178
|
}
|
|
152
|
-
/**
|
|
179
|
+
/**
|
|
180
|
+
* Import one Codex rollout into DSH session persistence: into the session that already holds its thread, else a new
|
|
181
|
+
* one. A stored session that may or may not hold it (nothing tells) is not guessed at: the import is refused, and
|
|
182
|
+
* the list offers both. `targetId` imports into that session, the way "Import as new" does.
|
|
183
|
+
*/
|
|
153
184
|
export async function importCodexSession(ctx, sourcePath, options = {}) {
|
|
154
|
-
const persistence = dshService(ctx, 'sessionPersistence');
|
|
155
|
-
if (persistence === undefined)
|
|
156
|
-
throw new Error('sessionPersistence service is not available');
|
|
157
185
|
const parsed = await readCodexSession(sourcePath, options.targetId);
|
|
158
186
|
if (parsed.session.turns.length === 0)
|
|
159
187
|
throw new Error(`nothing to import from ${sourcePath}: no conversation in the rollout`);
|
|
160
|
-
const
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
188
|
+
const identity = options.targetId !== undefined
|
|
189
|
+
? targetIdentity(options.targetId)
|
|
190
|
+
: rolloutIdentity(sourcePath, parsed.thread, parsed.session.createdAt, { session: parsed.session });
|
|
191
|
+
return importReport(sourcePath, parsed.title, await persistImported(ctx, parsed.session, identity));
|
|
192
|
+
}
|
|
193
|
+
/** The identity of the thread a rollout holds: the one the list shows and the import uses. */
|
|
194
|
+
export function rolloutIdentity(path, thread, createdAt, known = {}) {
|
|
195
|
+
const home = codexHomeOf(path);
|
|
196
|
+
const root = home !== undefined ? join(home, 'sessions') : dirname(path);
|
|
197
|
+
const session = known.session;
|
|
198
|
+
return codexIdentity(thread, createdAt, {
|
|
199
|
+
threads: () => (known.threads ?? codexThreads)(root),
|
|
200
|
+
turns: () => session !== undefined ? turnReader(sessionTurns(session.turns)) : rolloutTurnReader(path),
|
|
201
|
+
turnsOf: rolloutTurnReader,
|
|
171
202
|
});
|
|
172
|
-
try {
|
|
173
|
-
await handle.append(events);
|
|
174
|
-
await handle.flush();
|
|
175
|
-
}
|
|
176
|
-
finally {
|
|
177
|
-
await handle.close();
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
id: synthesized.meta.id,
|
|
181
|
-
sourcePath,
|
|
182
|
-
...(parsed.title !== undefined ? { title: parsed.title } : {}),
|
|
183
|
-
turns: synthesized.stats.turns,
|
|
184
|
-
events: events.length,
|
|
185
|
-
stats: {
|
|
186
|
-
steps: synthesized.stats.steps,
|
|
187
|
-
messages: synthesized.stats.messages,
|
|
188
|
-
toolCalls: synthesized.stats.toolCalls,
|
|
189
|
-
toolResults: synthesized.stats.toolResults,
|
|
190
|
-
synthesizedToolResults: synthesized.stats.synthesizedToolResults,
|
|
191
|
-
},
|
|
192
|
-
};
|
|
193
203
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
let entries;
|
|
198
|
-
try {
|
|
199
|
-
entries = await readdir(dir, { withFileTypes: true });
|
|
200
|
-
}
|
|
201
|
-
catch {
|
|
202
|
-
return;
|
|
203
|
-
}
|
|
204
|
-
for (const entry of entries) {
|
|
205
|
-
const path = join(dir, entry.name);
|
|
206
|
-
if (entry.isDirectory())
|
|
207
|
-
await walk(path);
|
|
208
|
-
else if (entry.isFile() && /^rollout-.*\.jsonl$/u.test(entry.name))
|
|
209
|
-
out.push(path);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
await walk(root);
|
|
213
|
-
return out;
|
|
204
|
+
/** A reader of a rollout's turns: the rollout is read as far as the turns asked for. */
|
|
205
|
+
function rolloutTurnReader(path) {
|
|
206
|
+
return turnReader(sessionTurns(rolloutTurns(path)));
|
|
214
207
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
path,
|
|
231
|
-
sourceId,
|
|
232
|
-
...(title !== undefined ? { title } : {}),
|
|
233
|
-
...(cwd !== undefined ? { cwd } : {}),
|
|
234
|
-
...(createdAt !== undefined ? { createdAt } : {}),
|
|
235
|
-
};
|
|
208
|
+
/** Turns as compared ({@link turnText}): the same for a rollout being read and one already read. */
|
|
209
|
+
async function* sessionTurns(turns) {
|
|
210
|
+
for await (const turn of turns)
|
|
211
|
+
yield turnText(turn.prompt, turn.steps.flatMap(step => replyText(step.content)));
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* The lines of a rollout, plain or compressed, streamed: what the import reads. The size is checked before the file
|
|
215
|
+
* is read (a compressed one, as its decoded bytes stream by), so a rollout that is too large costs nothing.
|
|
216
|
+
* `observer` sees how much the line splitter holds at once.
|
|
217
|
+
*/
|
|
218
|
+
export async function* rolloutLines(path, observer) {
|
|
219
|
+
await assertFileImportable(path);
|
|
220
|
+
yield* path.endsWith('.zst')
|
|
221
|
+
? splitLines(limitBytes(zstdChunks(path)), MAX_LINE_BYTES, observer)
|
|
222
|
+
: fileLines(path, observer !== undefined ? { observer } : {});
|
|
236
223
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
for (const line of text.split(/\r?\n/u)) {
|
|
242
|
-
if (line.trim().length === 0)
|
|
224
|
+
/** The records of a rollout, one at a time. */
|
|
225
|
+
async function* readRecords(path) {
|
|
226
|
+
for await (const line of rolloutLines(path)) {
|
|
227
|
+
if (line.oversized || line.text.trim().length === 0)
|
|
243
228
|
continue;
|
|
244
229
|
try {
|
|
245
|
-
const value = JSON.parse(line);
|
|
230
|
+
const value = JSON.parse(line.text);
|
|
246
231
|
if (typeof value === 'object' && value !== null)
|
|
247
|
-
|
|
232
|
+
yield value;
|
|
248
233
|
}
|
|
249
234
|
catch {
|
|
250
235
|
// A partially written rollout line is ignored; the rest remains readable.
|
|
251
236
|
}
|
|
252
237
|
}
|
|
253
|
-
return records;
|
|
254
238
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
return '';
|
|
277
|
-
const record = item;
|
|
278
|
-
return typeof record['text'] === 'string' ? record['text'] : '';
|
|
279
|
-
})
|
|
280
|
-
.filter(Boolean)
|
|
281
|
-
.join('\n');
|
|
239
|
+
/**
|
|
240
|
+
* A function call's output text. Codex wraps the output of its shell tools as `{"output": …, "metadata": …}`
|
|
241
|
+
* (exit code, duration); the model saw the output, so that is what the result holds.
|
|
242
|
+
*/
|
|
243
|
+
function outputText(value) {
|
|
244
|
+
const text = textOf(value) || stringField(value) || '';
|
|
245
|
+
const trimmed = text.trimStart();
|
|
246
|
+
if (!trimmed.startsWith('{'))
|
|
247
|
+
return text;
|
|
248
|
+
try {
|
|
249
|
+
const parsed = JSON.parse(trimmed);
|
|
250
|
+
if (typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed)) {
|
|
251
|
+
const output = parsed['output'];
|
|
252
|
+
if (typeof output === 'string')
|
|
253
|
+
return output;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
catch {
|
|
257
|
+
// Not the wrapper: the output itself is JSON or starts like it.
|
|
258
|
+
}
|
|
259
|
+
return text;
|
|
282
260
|
}
|
|
283
261
|
function parseJson(value) {
|
|
284
262
|
if (value === undefined)
|
|
@@ -290,14 +268,3 @@ function parseJson(value) {
|
|
|
290
268
|
return value;
|
|
291
269
|
}
|
|
292
270
|
}
|
|
293
|
-
function stringField(value) {
|
|
294
|
-
return typeof value === 'string' && value.length > 0 ? value : undefined;
|
|
295
|
-
}
|
|
296
|
-
function timestamp(value) {
|
|
297
|
-
if (typeof value === 'string') {
|
|
298
|
-
const parsed = Date.parse(value);
|
|
299
|
-
if (Number.isFinite(parsed))
|
|
300
|
-
return parsed;
|
|
301
|
-
}
|
|
302
|
-
return undefined;
|
|
303
|
-
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { Context } from '@deepseek-ai/cordis';
|
|
2
2
|
import type { NormalizedSession } from '@kirkchinese/harness-forge-core';
|
|
3
|
+
import { type SessionPage, type SessionPageRequest } from '../forge/contract.js';
|
|
4
|
+
import { type ImportIdentity, type ImportReport } from './persist.js';
|
|
3
5
|
/** One discoverable OpenCode session in its shared database. */
|
|
4
6
|
export interface OpenCodeSessionCandidate {
|
|
5
7
|
readonly path: string;
|
|
@@ -8,24 +10,28 @@ export interface OpenCodeSessionCandidate {
|
|
|
8
10
|
readonly title?: string;
|
|
9
11
|
readonly cwd?: string;
|
|
10
12
|
readonly createdAt?: number;
|
|
13
|
+
readonly updatedAt?: number;
|
|
14
|
+
/** The size of the session's messages and parts, in bytes; absent when the database does not say. */
|
|
15
|
+
readonly bytes?: number;
|
|
11
16
|
}
|
|
12
|
-
export
|
|
13
|
-
readonly id: string;
|
|
14
|
-
readonly sourcePath: string;
|
|
15
|
-
readonly title?: string;
|
|
16
|
-
readonly turns: number;
|
|
17
|
-
readonly events: number;
|
|
18
|
-
readonly stats: Record<string, number>;
|
|
19
|
-
}
|
|
17
|
+
export type OpenCodeImportReport = ImportReport;
|
|
20
18
|
/** Default OpenCode database path (the desktop build uses ~/.local/share). */
|
|
21
19
|
export declare function defaultOpenCodeDatabase(home?: string): string;
|
|
22
20
|
/** Discover top-level OpenCode sessions (subagent sessions are excluded). */
|
|
23
|
-
export declare function discoverOpenCodeSessions(path?: string,
|
|
21
|
+
export declare function discoverOpenCodeSessions(path?: string, page?: SessionPageRequest): Promise<SessionPage<OpenCodeSessionCandidate>>;
|
|
24
22
|
/** Read one OpenCode session into the shared normalized model. */
|
|
25
23
|
export declare function readOpenCodeSession(path: string, sourceId: string, targetId?: string): Promise<{
|
|
26
24
|
session: NormalizedSession;
|
|
27
25
|
title?: string;
|
|
28
26
|
}>;
|
|
27
|
+
/**
|
|
28
|
+
* The DSH id of an imported OpenCode session. Prefixed, so it never equals the OpenCode id: a session under the
|
|
29
|
+
* source's own id reads as native to other importers (dsh-chat-import hides those sources). Imports by earlier
|
|
30
|
+
* versions used the bare id; they are still found and reused.
|
|
31
|
+
*/
|
|
32
|
+
export declare function openCodeSessionId(sourceId: string): string;
|
|
33
|
+
/** How an import finds the DSH session holding an OpenCode session: earlier versions used the bare id. */
|
|
34
|
+
export declare function openCodeIdentity(sourceId: string): ImportIdentity;
|
|
29
35
|
/** Import one OpenCode session into DSH session persistence. */
|
|
30
36
|
export declare function importOpenCodeSession(ctx: Context, path: string, sourceId: string, options?: {
|
|
31
37
|
readonly targetId?: string;
|