@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/opencode.js
CHANGED
|
@@ -8,8 +8,9 @@
|
|
|
8
8
|
import { existsSync } from 'node:fs';
|
|
9
9
|
import { homedir } from 'node:os';
|
|
10
10
|
import { join } from 'node:path';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
11
|
+
import { assertSessionSize } from '@kirkchinese/harness-forge-core';
|
|
12
|
+
import { SESSION_PAGE_SIZE } from '../forge/contract.js';
|
|
13
|
+
import { importReport, persistImported, targetIdentity } from './persist.js';
|
|
13
14
|
/** Default OpenCode database path (the desktop build uses ~/.local/share). */
|
|
14
15
|
export function defaultOpenCodeDatabase(home = homedir()) {
|
|
15
16
|
const xdg = join(home, '.local', 'share', 'opencode', 'opencode.db');
|
|
@@ -19,17 +20,20 @@ export function defaultOpenCodeDatabase(home = homedir()) {
|
|
|
19
20
|
return local ?? xdg;
|
|
20
21
|
}
|
|
21
22
|
/** Discover top-level OpenCode sessions (subagent sessions are excluded). */
|
|
22
|
-
export async function discoverOpenCodeSessions(path = defaultOpenCodeDatabase(),
|
|
23
|
+
export async function discoverOpenCodeSessions(path = defaultOpenCodeDatabase(), page = {}) {
|
|
24
|
+
const limit = Math.max(1, page.limit ?? SESSION_PAGE_SIZE);
|
|
25
|
+
const offset = Math.max(0, page.cursor ?? 0);
|
|
23
26
|
const db = await openDatabase(path);
|
|
24
27
|
try {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return rows.map((row) => {
|
|
28
|
+
const table = schemaKind(db) === 'v2' ? 'session_v2' : 'session';
|
|
29
|
+
// One more than a page, to know whether another page follows.
|
|
30
|
+
const rows = db.prepare(`select id, title, directory, time_created, time_updated from ${table} where parent_id is null order by time_updated desc limit ? offset ?`).all(limit + 1, offset);
|
|
31
|
+
const sessions = rows.slice(0, limit).map((row) => {
|
|
30
32
|
const title = stringField(row['title']);
|
|
31
33
|
const cwd = stringField(row['directory']);
|
|
32
34
|
const createdAt = numberField(row['time_created']);
|
|
35
|
+
const updatedAt = numberField(row['time_updated']);
|
|
36
|
+
const bytes = sessionBytes(db, String(row['id']));
|
|
33
37
|
return {
|
|
34
38
|
path,
|
|
35
39
|
sourceId: String(row['id']),
|
|
@@ -37,8 +41,11 @@ export async function discoverOpenCodeSessions(path = defaultOpenCodeDatabase(),
|
|
|
37
41
|
...(title !== undefined ? { title } : {}),
|
|
38
42
|
...(cwd !== undefined ? { cwd } : {}),
|
|
39
43
|
...(createdAt !== undefined ? { createdAt } : {}),
|
|
44
|
+
...(updatedAt !== undefined ? { updatedAt } : {}),
|
|
45
|
+
...(bytes !== undefined ? { bytes } : {}),
|
|
40
46
|
};
|
|
41
47
|
});
|
|
48
|
+
return { sessions, ...(rows.length > limit ? { next: offset + limit } : {}) };
|
|
42
49
|
}
|
|
43
50
|
finally {
|
|
44
51
|
db.close();
|
|
@@ -48,12 +55,17 @@ export async function discoverOpenCodeSessions(path = defaultOpenCodeDatabase(),
|
|
|
48
55
|
export async function readOpenCodeSession(path, sourceId, targetId) {
|
|
49
56
|
const db = await openDatabase(path);
|
|
50
57
|
try {
|
|
58
|
+
// Before any message is read: a session is rows, not a file, and its size is what they add up to.
|
|
59
|
+
const bytes = sessionBytes(db, sourceId);
|
|
60
|
+
if (bytes !== undefined)
|
|
61
|
+
assertSessionSize(bytes);
|
|
51
62
|
if (schemaKind(db) === 'v2')
|
|
52
63
|
return readOpenCodeV2(db, path, sourceId, targetId);
|
|
53
64
|
const row = db.prepare('select id, title, directory, time_created from session where id = ?').get(sourceId);
|
|
54
65
|
if (row === undefined)
|
|
55
66
|
throw new Error(`OpenCode session not found: ${sourceId}`);
|
|
56
|
-
const messages = db.prepare('select id, data from message where session_id = ? order by time_created').
|
|
67
|
+
const messages = db.prepare('select id, data from message where session_id = ? order by time_created').iterate(sourceId);
|
|
68
|
+
const parts = db.prepare('select data from part where message_id = ? order by time_created');
|
|
57
69
|
const turns = [];
|
|
58
70
|
let current;
|
|
59
71
|
let step;
|
|
@@ -71,34 +83,45 @@ export async function readOpenCodeSession(path, sourceId, targetId) {
|
|
|
71
83
|
}
|
|
72
84
|
return step;
|
|
73
85
|
};
|
|
86
|
+
// Text after a tool call opens the next step: in one step it would part the call from its result.
|
|
87
|
+
const bodyStep = (at) => {
|
|
88
|
+
if (step !== undefined && step.toolCalls.length > 0)
|
|
89
|
+
step = undefined;
|
|
90
|
+
return ensureStep(at);
|
|
91
|
+
};
|
|
74
92
|
for (const message of messages) {
|
|
75
93
|
const data = parseRecord(message['data']);
|
|
76
94
|
if (data === undefined)
|
|
77
95
|
continue;
|
|
78
96
|
const created = numberField(asRecord(data['time'])?.['created']);
|
|
79
97
|
const role = data['role'];
|
|
80
|
-
|
|
98
|
+
if (role !== 'user' && role !== 'assistant')
|
|
99
|
+
continue;
|
|
100
|
+
const rows = parts.iterate(String(message['id']));
|
|
81
101
|
if (role === 'user') {
|
|
82
|
-
const
|
|
83
|
-
|
|
102
|
+
const texts = [];
|
|
103
|
+
for (const part of rows) {
|
|
104
|
+
const data = parseRecord(part['data']);
|
|
105
|
+
if (isTextPart(data))
|
|
106
|
+
texts.push(data['text']);
|
|
107
|
+
}
|
|
108
|
+
startTurn(texts.join('\n'), created);
|
|
84
109
|
continue;
|
|
85
110
|
}
|
|
86
|
-
|
|
87
|
-
continue;
|
|
88
|
-
for (const partRow of parts) {
|
|
111
|
+
for (const partRow of rows) {
|
|
89
112
|
const part = parseRecord(partRow['data']);
|
|
90
113
|
if (part === undefined)
|
|
91
114
|
continue;
|
|
92
115
|
if (part['type'] === 'text') {
|
|
93
116
|
const text = stringField(part['text']);
|
|
94
117
|
if (text !== undefined)
|
|
95
|
-
|
|
118
|
+
bodyStep(created).content.push({ type: 'text', text });
|
|
96
119
|
continue;
|
|
97
120
|
}
|
|
98
121
|
if (part['type'] === 'reasoning') {
|
|
99
122
|
const text = stringField(part['text']);
|
|
100
123
|
if (text !== undefined)
|
|
101
|
-
|
|
124
|
+
bodyStep(created).content.push({ type: 'reasoning', text });
|
|
102
125
|
continue;
|
|
103
126
|
}
|
|
104
127
|
if (part['type'] !== 'tool')
|
|
@@ -129,7 +152,7 @@ export async function readOpenCodeSession(path, sourceId, targetId) {
|
|
|
129
152
|
const createdAt = numberField(row['time_created']) ?? 0;
|
|
130
153
|
return {
|
|
131
154
|
session: {
|
|
132
|
-
id: targetId ?? sourceId,
|
|
155
|
+
id: targetId ?? openCodeSessionId(sourceId),
|
|
133
156
|
source: { tool: 'opencode', path, sessionId: sourceId },
|
|
134
157
|
createdAt,
|
|
135
158
|
...(cwd !== undefined ? { cwd } : {}),
|
|
@@ -143,52 +166,43 @@ export async function readOpenCodeSession(path, sourceId, targetId) {
|
|
|
143
166
|
db.close();
|
|
144
167
|
}
|
|
145
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* The DSH id of an imported OpenCode session. Prefixed, so it never equals the OpenCode id: a session under the
|
|
171
|
+
* source's own id reads as native to other importers (dsh-chat-import hides those sources). Imports by earlier
|
|
172
|
+
* versions used the bare id; they are still found and reused.
|
|
173
|
+
*/
|
|
174
|
+
export function openCodeSessionId(sourceId) {
|
|
175
|
+
return `opencode-${sourceId}`;
|
|
176
|
+
}
|
|
177
|
+
/** How an import finds the DSH session holding an OpenCode session: earlier versions used the bare id. */
|
|
178
|
+
export function openCodeIdentity(sourceId) {
|
|
179
|
+
return { id: openCodeSessionId(sourceId), legacyIds: [sourceId] };
|
|
180
|
+
}
|
|
146
181
|
/** Import one OpenCode session into DSH session persistence. */
|
|
147
182
|
export async function importOpenCodeSession(ctx, path, sourceId, options = {}) {
|
|
148
|
-
const persistence = dshService(ctx, 'sessionPersistence');
|
|
149
|
-
if (persistence === undefined)
|
|
150
|
-
throw new Error('sessionPersistence service is not available');
|
|
151
183
|
const parsed = await readOpenCodeSession(path, sourceId, options.targetId);
|
|
152
184
|
if (parsed.session.turns.length === 0)
|
|
153
185
|
throw new Error(`nothing to import from OpenCode session ${sourceId}: it has no conversation`);
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
const handle = await persistence.create({
|
|
157
|
-
version: 4,
|
|
158
|
-
id: synthesized.meta.id,
|
|
159
|
-
createdAt: synthesized.meta.createdAt,
|
|
160
|
-
isSeeded: false,
|
|
161
|
-
...(synthesized.meta.cwd !== undefined ? { cwd: synthesized.meta.cwd } : {}),
|
|
162
|
-
delegationDepth: synthesized.meta.delegationDepth,
|
|
163
|
-
...(synthesized.meta.origin !== undefined ? { origin: synthesized.meta.origin } : {}),
|
|
164
|
-
...(synthesized.meta.parentSession !== undefined ? { parentSession: synthesized.meta.parentSession } : {}),
|
|
165
|
-
});
|
|
166
|
-
try {
|
|
167
|
-
await handle.append(events);
|
|
168
|
-
await handle.flush();
|
|
169
|
-
}
|
|
170
|
-
finally {
|
|
171
|
-
await handle.close();
|
|
172
|
-
}
|
|
173
|
-
return {
|
|
174
|
-
id: synthesized.meta.id,
|
|
175
|
-
sourcePath: path,
|
|
176
|
-
...(parsed.title !== undefined ? { title: parsed.title } : {}),
|
|
177
|
-
turns: synthesized.stats.turns,
|
|
178
|
-
events: events.length,
|
|
179
|
-
stats: {
|
|
180
|
-
steps: synthesized.stats.steps,
|
|
181
|
-
messages: synthesized.stats.messages,
|
|
182
|
-
toolCalls: synthesized.stats.toolCalls,
|
|
183
|
-
toolResults: synthesized.stats.toolResults,
|
|
184
|
-
synthesizedToolResults: synthesized.stats.synthesizedToolResults,
|
|
185
|
-
},
|
|
186
|
-
};
|
|
186
|
+
const identity = options.targetId !== undefined ? targetIdentity(options.targetId) : openCodeIdentity(sourceId);
|
|
187
|
+
return importReport(path, parsed.title, await persistImported(ctx, parsed.session, identity));
|
|
187
188
|
}
|
|
188
189
|
async function openDatabase(path) {
|
|
189
190
|
const { DatabaseSync } = await import('node:sqlite');
|
|
190
191
|
return new DatabaseSync(path, { readOnly: true });
|
|
191
192
|
}
|
|
193
|
+
/** What one session's message and part rows add up to, in bytes; `undefined` when the schema is not one this knows. */
|
|
194
|
+
function sessionBytes(db, sourceId) {
|
|
195
|
+
const sum = (sql) => Number(db.prepare(sql).get(sourceId)?.['bytes'] ?? 0);
|
|
196
|
+
try {
|
|
197
|
+
if (schemaKind(db) === 'v2')
|
|
198
|
+
return sum('select coalesce(sum(length(cast(data as blob))), 0) as bytes from session_message where session_id = ?');
|
|
199
|
+
return sum('select coalesce(sum(length(cast(data as blob))), 0) as bytes from message where session_id = ?')
|
|
200
|
+
+ sum('select coalesce(sum(length(cast(p.data as blob))), 0) as bytes from part p join message m on m.id = p.message_id where m.session_id = ?');
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
192
206
|
function schemaKind(db) {
|
|
193
207
|
const names = new Set(db.prepare("select name from sqlite_master where type='table'").all().map(row => String(row['name'])));
|
|
194
208
|
return names.has('session_v2') ? 'v2' : 'v1';
|
|
@@ -197,7 +211,7 @@ function readOpenCodeV2(db, path, sourceId, targetId) {
|
|
|
197
211
|
const row = db.prepare('select id, title, directory, time_created from session_v2 where id = ?').get(sourceId);
|
|
198
212
|
if (row === undefined)
|
|
199
213
|
throw new Error(`OpenCode session not found: ${sourceId}`);
|
|
200
|
-
const messages = db.prepare('select id, type, data, time_created from session_message where session_id = ? order by seq, time_created').
|
|
214
|
+
const messages = db.prepare('select id, type, data, time_created from session_message where session_id = ? order by seq, time_created').iterate(sourceId);
|
|
201
215
|
const turns = [];
|
|
202
216
|
let current;
|
|
203
217
|
let step;
|
|
@@ -215,6 +229,11 @@ function readOpenCodeV2(db, path, sourceId, targetId) {
|
|
|
215
229
|
}
|
|
216
230
|
return step;
|
|
217
231
|
};
|
|
232
|
+
const bodyStep = (at) => {
|
|
233
|
+
if (step !== undefined && step.toolCalls.length > 0)
|
|
234
|
+
step = undefined;
|
|
235
|
+
return ensureStep(at);
|
|
236
|
+
};
|
|
218
237
|
for (const message of messages) {
|
|
219
238
|
const data = parseRecord(message['data']);
|
|
220
239
|
if (data === undefined)
|
|
@@ -236,13 +255,13 @@ function readOpenCodeV2(db, path, sourceId, targetId) {
|
|
|
236
255
|
if (block['type'] === 'text') {
|
|
237
256
|
const text = stringField(block['text']);
|
|
238
257
|
if (text !== undefined)
|
|
239
|
-
|
|
258
|
+
bodyStep(created).content.push({ type: 'text', text });
|
|
240
259
|
continue;
|
|
241
260
|
}
|
|
242
261
|
if (block['type'] === 'reasoning') {
|
|
243
262
|
const text = stringField(block['text']);
|
|
244
263
|
if (text !== undefined)
|
|
245
|
-
|
|
264
|
+
bodyStep(created).content.push({ type: 'reasoning', text });
|
|
246
265
|
continue;
|
|
247
266
|
}
|
|
248
267
|
if (block['type'] !== 'tool')
|
|
@@ -272,7 +291,7 @@ function readOpenCodeV2(db, path, sourceId, targetId) {
|
|
|
272
291
|
const createdAt = numberField(row['time_created']) ?? 0;
|
|
273
292
|
return {
|
|
274
293
|
session: {
|
|
275
|
-
id: targetId ?? sourceId,
|
|
294
|
+
id: targetId ?? openCodeSessionId(sourceId),
|
|
276
295
|
source: { tool: 'opencode', path, sessionId: sourceId },
|
|
277
296
|
createdAt,
|
|
278
297
|
...(cwd !== undefined ? { cwd } : {}),
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import { type NormalizedSession, type SynthesizedSession } from '@kirkchinese/harness-forge-core';
|
|
3
|
+
import { type TurnReader } from './turns.js';
|
|
4
|
+
interface PersistenceHandle {
|
|
5
|
+
append(events: readonly unknown[]): Promise<void>;
|
|
6
|
+
flush(): Promise<void>;
|
|
7
|
+
close(): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
interface ReadHandle {
|
|
10
|
+
/** `length` events from `offset`: fewer at the end of the log. */
|
|
11
|
+
read(offset?: number, length?: number): Promise<{
|
|
12
|
+
readonly events: readonly unknown[];
|
|
13
|
+
}>;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
interface SessionPersistence {
|
|
17
|
+
create(header: Record<string, unknown>): Promise<PersistenceHandle>;
|
|
18
|
+
list?(): Promise<readonly unknown[]>;
|
|
19
|
+
open?(id: string, access: 'read'): Promise<ReadHandle>;
|
|
20
|
+
}
|
|
21
|
+
/** Where an imported session ended up. */
|
|
22
|
+
export interface PersistedSession {
|
|
23
|
+
readonly id: string;
|
|
24
|
+
/** The session was already in DSH (imported before): it was opened, not written again. */
|
|
25
|
+
readonly reused: boolean;
|
|
26
|
+
/** The session is live in this DSH, so the browser can open it now. */
|
|
27
|
+
readonly live: boolean;
|
|
28
|
+
/** The workspace the session is grouped under, when its directory is one. */
|
|
29
|
+
readonly workspace?: string;
|
|
30
|
+
}
|
|
31
|
+
/** What DSH stores of a session that says which source session it holds. */
|
|
32
|
+
export interface StoredSession {
|
|
33
|
+
readonly id: string;
|
|
34
|
+
/** The header's creation time; importers write the source session's own. */
|
|
35
|
+
readonly createdAt?: number;
|
|
36
|
+
/** The directory the session was in: its workspace. */
|
|
37
|
+
readonly cwd?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What tells which source session a stored one holds, when an id may have been given to several: Harness Forge
|
|
41
|
+
* 0.4.0 gave a Codex thread and its forks one id, the bare `session_id` they share.
|
|
42
|
+
*/
|
|
43
|
+
export interface Provenance {
|
|
44
|
+
/** When the source session was created; every version stored it as the DSH session's `createdAt`. */
|
|
45
|
+
readonly createdAt: number;
|
|
46
|
+
/** Written under when `id` holds another session. */
|
|
47
|
+
readonly alternateId: string;
|
|
48
|
+
/**
|
|
49
|
+
* The other source sessions created at the same time that an earlier version may have stored under `legacyId`
|
|
50
|
+
* (forks can be created in one millisecond): a reader of each one's turns, opened when called.
|
|
51
|
+
*/
|
|
52
|
+
rivals(legacyId: string): Promise<ReadonlyArray<() => TurnReader>>;
|
|
53
|
+
/** A reader of this source session's turns. */
|
|
54
|
+
turns(): TurnReader;
|
|
55
|
+
}
|
|
56
|
+
/** How an import finds the DSH session that already holds its source session, and the id it writes under. */
|
|
57
|
+
export interface ImportIdentity {
|
|
58
|
+
/** The id this version gives the session. */
|
|
59
|
+
readonly id: string;
|
|
60
|
+
/** Ids earlier versions gave it; one stored is reused. */
|
|
61
|
+
readonly legacyIds: readonly string[];
|
|
62
|
+
/**
|
|
63
|
+
* Set when an earlier version's id may have been given to another source session too: see {@link matchStored}.
|
|
64
|
+
* Without it, a session stored under any of the ids holds this one.
|
|
65
|
+
*/
|
|
66
|
+
readonly provenance?: Provenance;
|
|
67
|
+
}
|
|
68
|
+
/** Whether DSH already holds a source session. */
|
|
69
|
+
export type StoredMatch =
|
|
70
|
+
/** It does, as `id`. */
|
|
71
|
+
{
|
|
72
|
+
readonly kind: 'imported';
|
|
73
|
+
readonly id: string;
|
|
74
|
+
}
|
|
75
|
+
/** `id` may hold it, and nothing says whether it does; importing it as new writes `newId`. */
|
|
76
|
+
| {
|
|
77
|
+
readonly kind: 'maybe';
|
|
78
|
+
readonly id: string;
|
|
79
|
+
readonly newId: string;
|
|
80
|
+
}
|
|
81
|
+
/** It does not; an import writes `id`. */
|
|
82
|
+
| {
|
|
83
|
+
readonly kind: 'new';
|
|
84
|
+
readonly id: string;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* The same for listing and import: find the stored session that holds the source session, by id and provenance.
|
|
88
|
+
*
|
|
89
|
+
* With provenance, a session under this version's own ids holds the source unless its creation time says otherwise.
|
|
90
|
+
* One under an earlier version's id holds it when it was created when the source was, and no other source session
|
|
91
|
+
* created then may be stored under that id; else only when, of all those source sessions, this is the one whose
|
|
92
|
+
* every turn (prompt and answer) is the stored session's ({@link uniqueFullMatch}). A session whose time is unknown,
|
|
93
|
+
* or that more than one or none of them match in full, is left to the person.
|
|
94
|
+
*/
|
|
95
|
+
export declare function matchStored(identity: ImportIdentity, stored: StoredSessions): Promise<StoredMatch>;
|
|
96
|
+
/** A session stored under an id that may or may not hold the one being imported; the person decides. */
|
|
97
|
+
export declare class SessionMaybeImportedError extends Error {
|
|
98
|
+
readonly existingId: string;
|
|
99
|
+
readonly code = "session-maybe-imported";
|
|
100
|
+
constructor(existingId: string);
|
|
101
|
+
}
|
|
102
|
+
/** The identity of an import into a named session: that one, reused when it is stored. */
|
|
103
|
+
export declare function targetIdentity(targetId: string): ImportIdentity;
|
|
104
|
+
/**
|
|
105
|
+
* Persist a normalized session, or reuse the one an earlier import wrote, and make it live. The session is written
|
|
106
|
+
* under the id `identity` resolves to, whatever id it carries.
|
|
107
|
+
*/
|
|
108
|
+
export declare function persistImported(ctx: Context, session: NormalizedSession, identity: ImportIdentity): Promise<{
|
|
109
|
+
readonly persisted: PersistedSession;
|
|
110
|
+
readonly synthesized: SynthesizedSession;
|
|
111
|
+
}>;
|
|
112
|
+
/** What opening a stored session did. */
|
|
113
|
+
export interface OpenedSession {
|
|
114
|
+
readonly id: string;
|
|
115
|
+
/** The session is live in this DSH, so the browser can open it now. */
|
|
116
|
+
readonly live: boolean;
|
|
117
|
+
/** The person had archived it in DSH, and opening took it out of the archive. */
|
|
118
|
+
readonly unarchived: boolean;
|
|
119
|
+
/** It is archived in DSH and stays so (DSH offers no way to unarchive): it is under the archive, not in the list. */
|
|
120
|
+
readonly archived: boolean;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Make a session an import stored known to DSH again, so opening it shows it: placed in the workspace of its
|
|
124
|
+
* directory and live, as a new import does, and out of the archive when the person archived it (an archived
|
|
125
|
+
* session is hidden from every grouping, and opening it lands on an empty new-session page).
|
|
126
|
+
*/
|
|
127
|
+
export declare function openStored(ctx: Context, id: string): Promise<OpenedSession>;
|
|
128
|
+
/** What one import did, as every importer reports it. */
|
|
129
|
+
export interface ImportReport extends PersistedSession {
|
|
130
|
+
readonly sourcePath: string;
|
|
131
|
+
readonly title?: string;
|
|
132
|
+
readonly turns: number;
|
|
133
|
+
readonly events: number;
|
|
134
|
+
readonly stats: Record<string, number>;
|
|
135
|
+
}
|
|
136
|
+
/** The report of an import that {@link persistImported} carried out. */
|
|
137
|
+
export declare function importReport(sourcePath: string, title: string | undefined, result: Awaited<ReturnType<typeof persistImported>>): ImportReport;
|
|
138
|
+
/** The sessions DSH stores, by id; none when it cannot list them. */
|
|
139
|
+
export declare function storedSessions(ctx: Context): Promise<StoredSessions>;
|
|
140
|
+
/** The sessions DSH stores: their headers, listed once, and what was said in them, read when asked. */
|
|
141
|
+
export declare class StoredSessions {
|
|
142
|
+
private readonly persistence;
|
|
143
|
+
private readonly headers;
|
|
144
|
+
private readonly readers;
|
|
145
|
+
private constructor();
|
|
146
|
+
static of(persistence: SessionPersistence | undefined): Promise<StoredSessions>;
|
|
147
|
+
get(id: string): StoredSession | undefined;
|
|
148
|
+
has(id: string): boolean;
|
|
149
|
+
/** A reader of a stored session's turns, shared by every comparison until {@link close}; its log is read in pages. */
|
|
150
|
+
turns(id: string): TurnReader;
|
|
151
|
+
/** Let go of the stored sessions read. */
|
|
152
|
+
close(): Promise<void>;
|
|
153
|
+
/** The turns of a stored session's log (`turn/start`, its first user message, the assistant's messages), as they are read. */
|
|
154
|
+
private storedTurns;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* The home folder and the system's temporary folders (`os.tmpdir()`, `/tmp`, `/var/tmp`, macOS's per-user
|
|
158
|
+
* `/var/folders/…/T`), which hold everyone's odds and ends and are no project: a session there gets no workspace.
|
|
159
|
+
* A folder inside one is a project of its own.
|
|
160
|
+
*/
|
|
161
|
+
export declare function isSharedFolder(path: string): boolean;
|
|
162
|
+
export {};
|