opencode-acp-client 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +220 -2
- package/README.zh.md +199 -0
- package/dist/acp/capabilities.d.ts +168 -0
- package/dist/acp/capabilities.js +240 -0
- package/dist/acp/capabilities.js.map +1 -0
- package/dist/acp/client.d.ts +241 -0
- package/dist/acp/client.js +767 -0
- package/dist/acp/client.js.map +1 -0
- package/dist/acp/types.d.ts +228 -0
- package/dist/acp/types.js +23 -0
- package/dist/acp/types.js.map +1 -0
- package/dist/acp-replay.d.ts +60 -0
- package/dist/acp-replay.js +188 -0
- package/dist/acp-replay.js.map +1 -0
- package/dist/contract.d.ts +435 -0
- package/dist/contract.js +126 -0
- package/dist/contract.js.map +1 -0
- package/dist/daemons.d.ts +39 -0
- package/dist/daemons.js +112 -0
- package/dist/daemons.js.map +1 -0
- package/dist/index.d.ts +268 -0
- package/dist/index.js +1882 -0
- package/dist/index.js.map +1 -0
- package/dist/opencode-bin.d.ts +73 -0
- package/dist/opencode-bin.js +109 -0
- package/dist/opencode-bin.js.map +1 -0
- package/dist/project.d.ts +81 -0
- package/dist/project.js +230 -0
- package/dist/project.js.map +1 -0
- package/dist/server.d.ts +743 -0
- package/dist/server.js +5029 -0
- package/dist/server.js.map +1 -0
- package/dist/session-map.d.ts +89 -0
- package/dist/session-map.js +305 -0
- package/dist/session-map.js.map +1 -0
- package/dist/sessions-command.d.ts +70 -0
- package/dist/sessions-command.js +188 -0
- package/dist/sessions-command.js.map +1 -0
- package/dist/sse.d.ts +40 -0
- package/dist/sse.js +147 -0
- package/dist/sse.js.map +1 -0
- package/dist/state.d.ts +161 -0
- package/dist/state.js +135 -0
- package/dist/state.js.map +1 -0
- package/dist/subagent-sessions.d.ts +71 -0
- package/dist/subagent-sessions.js +107 -0
- package/dist/subagent-sessions.js.map +1 -0
- package/dist/translate/events.d.ts +231 -0
- package/dist/translate/events.js +1244 -0
- package/dist/translate/events.js.map +1 -0
- package/dist/upgrade.d.ts +56 -0
- package/dist/upgrade.js +162 -0
- package/dist/upgrade.js.map +1 -0
- package/package.json +66 -4
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one file this bridge writes, and why.
|
|
3
|
+
*
|
|
4
|
+
* ACP does not let a client name a new session: `session/new` has no id field — its
|
|
5
|
+
* properties are `{_meta, additionalDirectories, cwd, mcpServers}` — and the id arrives in
|
|
6
|
+
* the response, chosen by the agent. A probe against dsh confirms `_meta.sessionId` is not
|
|
7
|
+
* honoured either. A client that owns its backend can choose the id while creating a session;
|
|
8
|
+
* a generic ACP client has no such call.
|
|
9
|
+
*
|
|
10
|
+
* So a session here has two ids: the one the client is shown and remembers, and the agent's
|
|
11
|
+
* own. Resuming a remembered tab — `session/load` — needs the agent's, and without a record
|
|
12
|
+
* of the pair the client's id is unknown to the agent and the tab comes back empty.
|
|
13
|
+
*
|
|
14
|
+
* Hence this map: ids, directories and optional agent titles only; never message content or
|
|
15
|
+
* credentials. It is read once and rewritten on change. `OPENCODE_ACP_CLIENT_SESSION_MAP` relocates it.
|
|
16
|
+
*/
|
|
17
|
+
import { mkdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { homedir } from 'node:os';
|
|
19
|
+
import { basename, dirname, join } from 'node:path';
|
|
20
|
+
/** `dsh --profile acp`: the human-readable form of a binding, used for logs and comparisons. */
|
|
21
|
+
export function agentBindingLabel(binding) {
|
|
22
|
+
return [basename(binding.command), ...binding.args].join(' ');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Read a stored binding. Older entries (and the first version of this field) held a
|
|
26
|
+
* space-separated string; split it on whitespace as a best effort — arguments with
|
|
27
|
+
* spaces were never representable in that shape anyway.
|
|
28
|
+
*/
|
|
29
|
+
function parseBinding(value) {
|
|
30
|
+
if (typeof value === 'string' && value.trim()) {
|
|
31
|
+
const [command, ...args] = value.trim().split(/\s+/);
|
|
32
|
+
return command ? { command, args } : undefined;
|
|
33
|
+
}
|
|
34
|
+
if (value && typeof value === 'object') {
|
|
35
|
+
const raw = value;
|
|
36
|
+
if (typeof raw.command === 'string' && raw.command.length > 0) {
|
|
37
|
+
return {
|
|
38
|
+
command: raw.command,
|
|
39
|
+
args: Array.isArray(raw.args) ? raw.args.filter((a) => typeof a === 'string') : [],
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
const TOMBSTONE_KEY = '__tombstones';
|
|
46
|
+
const TOMBSTONE_TTL_MS = 30 * 24 * 60 * 60 * 1000;
|
|
47
|
+
const MAX_ENTRIES = 500;
|
|
48
|
+
export function sessionMapPath() {
|
|
49
|
+
const override = process.env['OPENCODE_ACP_CLIENT_SESSION_MAP'];
|
|
50
|
+
if (override && override.length > 0)
|
|
51
|
+
return override;
|
|
52
|
+
// `~/.opencode-acp-client/sessions.json`. It began under `XDG_STATE_HOME`, which is the
|
|
53
|
+
// Linux convention for state rather than configuration — but that variable is unset on
|
|
54
|
+
// macOS, so it landed in `~/.local/state/...`, deeper and less discoverable than anything
|
|
55
|
+
// around it. opencode itself keeps `~/.config/opencode/` and `~/.opencode/`; one dotdir in
|
|
56
|
+
// the home directory is easier to find, back up and delete, and needs no convention.
|
|
57
|
+
return join(homedir(), '.opencode-acp-client', 'sessions.json');
|
|
58
|
+
}
|
|
59
|
+
export class SessionMap {
|
|
60
|
+
log;
|
|
61
|
+
data;
|
|
62
|
+
tombstones = new Map();
|
|
63
|
+
dirty = false;
|
|
64
|
+
constructor(log) {
|
|
65
|
+
this.log = log;
|
|
66
|
+
}
|
|
67
|
+
readFromDisk(path) {
|
|
68
|
+
const data = {};
|
|
69
|
+
const tombstones = {};
|
|
70
|
+
try {
|
|
71
|
+
const raw = readFileSync(path, 'utf8');
|
|
72
|
+
const parsed = JSON.parse(raw);
|
|
73
|
+
if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
|
74
|
+
const record = parsed;
|
|
75
|
+
const deleted = record[TOMBSTONE_KEY];
|
|
76
|
+
if (deleted && typeof deleted === 'object' && !Array.isArray(deleted)) {
|
|
77
|
+
for (const [id, at] of Object.entries(deleted)) {
|
|
78
|
+
if (typeof at === 'number')
|
|
79
|
+
tombstones[id] = at;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
for (const [id, value] of Object.entries(record)) {
|
|
83
|
+
if (id === TOMBSTONE_KEY)
|
|
84
|
+
continue;
|
|
85
|
+
const entry = value;
|
|
86
|
+
if (entry && typeof entry.acpSessionId === 'string') {
|
|
87
|
+
const updatedAt = typeof entry.updatedAt === 'number' ? entry.updatedAt : 0;
|
|
88
|
+
// A tombstone at least as new as the entry means it was forgotten after it was
|
|
89
|
+
// written: `forget` is used by the adoption path too, so a stale copy of the
|
|
90
|
+
// file must not bring a renamed-away shell id back.
|
|
91
|
+
if (tombstones[id] !== undefined && tombstones[id] >= updatedAt)
|
|
92
|
+
continue;
|
|
93
|
+
data[id] = {
|
|
94
|
+
acpSessionId: entry.acpSessionId,
|
|
95
|
+
...(typeof entry.createdAt === 'number' ? { createdAt: entry.createdAt } : {}),
|
|
96
|
+
...(typeof entry.directory === 'string' ? { directory: entry.directory } : {}),
|
|
97
|
+
...(typeof entry.title === 'string' && entry.title.trim() ? { title: entry.title } : {}),
|
|
98
|
+
...(parseBinding(entry.agent) ? { agent: parseBinding(entry.agent) } : {}),
|
|
99
|
+
updatedAt,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
const code = error.code;
|
|
107
|
+
if (code !== 'ENOENT')
|
|
108
|
+
this.log(`[bridge] session map unreadable (${String(error)}); starting empty`);
|
|
109
|
+
}
|
|
110
|
+
return { data, tombstones };
|
|
111
|
+
}
|
|
112
|
+
load() {
|
|
113
|
+
if (this.data)
|
|
114
|
+
return this.data;
|
|
115
|
+
const read = this.readFromDisk(sessionMapPath());
|
|
116
|
+
this.data = read.data;
|
|
117
|
+
this.tombstones = new Map(Object.entries(read.tombstones));
|
|
118
|
+
if (Object.keys(this.data).length > 0) {
|
|
119
|
+
this.log(`[bridge] session map: ${Object.keys(this.data).length} remembered id(s) from ${sessionMapPath()}`);
|
|
120
|
+
}
|
|
121
|
+
return this.data;
|
|
122
|
+
}
|
|
123
|
+
/** The agent's id for a session the client remembers, if we have ever learned it. */
|
|
124
|
+
acpIdFor(visibleId) {
|
|
125
|
+
return this.load()[visibleId]?.acpSessionId;
|
|
126
|
+
}
|
|
127
|
+
/** Every remembered visible id and its entry (callers sort/filter as needed). */
|
|
128
|
+
entries() {
|
|
129
|
+
return Object.entries(this.load());
|
|
130
|
+
}
|
|
131
|
+
/** A bridge-visible `ses_…` alias already associated with this agent id, if any. */
|
|
132
|
+
visibleIdFor(acpSessionId, directory) {
|
|
133
|
+
// When a directory is given, an entry WITHOUT one must not match: a session
|
|
134
|
+
// the agent reports under workspace A once picked up a stale map entry
|
|
135
|
+
// written under workspace B (the same agent session had been used in both),
|
|
136
|
+
// and the imported tab then adopted B's visible id — whose map entry named
|
|
137
|
+
// directory B, so resuming it loaded nothing under A. Match the requested
|
|
138
|
+
// directory exactly, or fall back to an entry that truly has none.
|
|
139
|
+
const entries = Object.entries(this.load());
|
|
140
|
+
const strict = directory === undefined ? undefined : entries.filter(([id, e]) => e.directory === directory);
|
|
141
|
+
for (const [visibleId, entry] of strict ?? entries) {
|
|
142
|
+
if (visibleId.startsWith('ses_') && entry.acpSessionId === acpSessionId) {
|
|
143
|
+
return visibleId;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (directory === undefined)
|
|
147
|
+
return undefined;
|
|
148
|
+
// Legacy entries may predate per-entry directories; a directoryless match
|
|
149
|
+
// is still better than inventing a second visible id for one conversation.
|
|
150
|
+
for (const [visibleId, entry] of entries) {
|
|
151
|
+
if (visibleId.startsWith('ses_') &&
|
|
152
|
+
entry.acpSessionId === acpSessionId &&
|
|
153
|
+
entry.directory === undefined) {
|
|
154
|
+
return visibleId;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
titleFor(visibleId) {
|
|
160
|
+
return this.load()[visibleId]?.title;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* The agent binding that created a remembered session, when it was recorded. `undefined`
|
|
164
|
+
* for entries written before the field existed — those keep the launching agent.
|
|
165
|
+
*/
|
|
166
|
+
agentFor(visibleId) {
|
|
167
|
+
return this.load()[visibleId]?.agent;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* The directory a remembered session lives in — the last one the bridge itself recorded,
|
|
171
|
+
* which a `/cd` move re-pointed. The adoption path needs it: a restarted bridge is launched
|
|
172
|
+
* in its own directory, and without this lookup it would adopt a moved session back into
|
|
173
|
+
* the launch directory, silently un-doing the move (and re-loading the agent there).
|
|
174
|
+
*/
|
|
175
|
+
directoryFor(visibleId) {
|
|
176
|
+
const directory = this.load()[visibleId]?.directory;
|
|
177
|
+
return typeof directory === 'string' && directory.length > 0 ? directory : undefined;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Remember a visible id → agent id pair.
|
|
181
|
+
*
|
|
182
|
+
* `used` says whether the CONVERSATION was advanced (a prompt the turn path accepted), as
|
|
183
|
+
* opposed to the bridge merely writing metadata about it. Only `used` moves `updatedAt`,
|
|
184
|
+
* because that field is what `-c` ranks by ("the most recent conversation"): metadata
|
|
185
|
+
* writes — a `session/list` import, a `/cd` move, a restored title — used to re-stamp every
|
|
186
|
+
* row in the directory with the same instant, so `-c` picked whichever the import happened
|
|
187
|
+
* to walk first instead of the conversation the user last worked in (measured 2026-10-27).
|
|
188
|
+
*/
|
|
189
|
+
remember(visibleId, acpSessionId, directory, title, agent, used = false) {
|
|
190
|
+
const data = this.load();
|
|
191
|
+
const existing = data[visibleId];
|
|
192
|
+
const nextTitle = title?.trim() || existing?.title;
|
|
193
|
+
const nextAgent = agent || existing?.agent;
|
|
194
|
+
const sameAgent = existing?.agent === nextAgent ||
|
|
195
|
+
(existing?.agent !== undefined &&
|
|
196
|
+
nextAgent !== undefined &&
|
|
197
|
+
agentBindingLabel(existing.agent) === agentBindingLabel(nextAgent));
|
|
198
|
+
if (existing &&
|
|
199
|
+
existing.acpSessionId === acpSessionId &&
|
|
200
|
+
existing.directory === directory &&
|
|
201
|
+
existing.title === nextTitle &&
|
|
202
|
+
sameAgent) {
|
|
203
|
+
// Nothing to write but recency: a prompt still means "this is the conversation I am
|
|
204
|
+
// working in", so it must move the row to the top of `-c`'s ranking.
|
|
205
|
+
if (used) {
|
|
206
|
+
existing.updatedAt = Date.now();
|
|
207
|
+
this.dirty = true;
|
|
208
|
+
}
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
data[visibleId] = {
|
|
212
|
+
acpSessionId,
|
|
213
|
+
// First sighting only: a later metadata write must not restamp it.
|
|
214
|
+
createdAt: existing?.createdAt ?? Date.now(),
|
|
215
|
+
...(directory ? { directory } : {}),
|
|
216
|
+
...(nextTitle ? { title: nextTitle } : {}),
|
|
217
|
+
...(nextAgent ? { agent: nextAgent } : {}),
|
|
218
|
+
// A NEW row has no earlier stamp to keep, so it takes one even for metadata: the cap
|
|
219
|
+
// (`MAX_ENTRIES`, sorted by `updatedAt`) needs every row dated.
|
|
220
|
+
updatedAt: used || existing === undefined ? Date.now() : existing.updatedAt,
|
|
221
|
+
};
|
|
222
|
+
// Remembering an id cancels its tombstone (an adopted session can be re-added).
|
|
223
|
+
this.tombstones.delete(visibleId);
|
|
224
|
+
this.dirty = true;
|
|
225
|
+
}
|
|
226
|
+
/** Forget a session the user deleted, so nothing can hand it back later. */
|
|
227
|
+
forget(...ids) {
|
|
228
|
+
const data = this.load();
|
|
229
|
+
for (const id of ids) {
|
|
230
|
+
if (id in data)
|
|
231
|
+
delete data[id];
|
|
232
|
+
// Record the deletion, not just the absence: another bridge may still hold a copy
|
|
233
|
+
// that was loaded before this call, and its flush must not resurrect the id.
|
|
234
|
+
this.tombstones.set(id, Date.now());
|
|
235
|
+
this.dirty = true;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/** Also file the agent's own id as a key, so a tab that names it resolves too. */
|
|
239
|
+
/**
|
|
240
|
+
* Remember a visible id → agent id pair.
|
|
241
|
+
*
|
|
242
|
+
* Earlier this also stored the agent id mapped to itself, so a client that asked for the agent's
|
|
243
|
+
* own id would resolve. Nothing asks: every id the client requests comes from the `ses_…` alias
|
|
244
|
+
* the bridge showed it (measured — the TUI requests `ses_ec3718af…` and `ses_acp_…`, never a bare
|
|
245
|
+
* UUID), and the only reverse lookup, `visibleIdFor`, requires `visibleId.startsWith('ses_')`, so
|
|
246
|
+
* a self-mapping could never match it either. The entries were therefore dead weight: they were
|
|
247
|
+
* 79 of 153 rows in the owner's real file (52%), and because `flush()` sorts by `updatedAt` and
|
|
248
|
+
* truncates at `MAX_ENTRIES`, they could push real mappings out of the cap.
|
|
249
|
+
*/
|
|
250
|
+
rememberBoth(visibleId, acpSessionId, directory, title, agent, used = false) {
|
|
251
|
+
this.remember(visibleId, acpSessionId, directory, title, agent, used);
|
|
252
|
+
}
|
|
253
|
+
/** Write if anything changed. Failures are logged, never fatal: the map is an optimisation. */
|
|
254
|
+
flush() {
|
|
255
|
+
if (!this.dirty || !this.data)
|
|
256
|
+
return;
|
|
257
|
+
try {
|
|
258
|
+
const path = sessionMapPath();
|
|
259
|
+
// Merge what other bridges wrote since this one loaded. The file is shared by
|
|
260
|
+
// every running client, and writing our in-memory copy outright dropped their
|
|
261
|
+
// new sessions — measured: a live tab disappeared from the map when another
|
|
262
|
+
// bridge flushed, and `-s <its id>` then answered "unknown session id". Merging
|
|
263
|
+
// without tombstones also undid `forget`, which the adoption path uses.
|
|
264
|
+
const disk = this.readFromDisk(path);
|
|
265
|
+
for (const [id, at] of Object.entries(disk.tombstones)) {
|
|
266
|
+
const mine = this.tombstones.get(id);
|
|
267
|
+
if (mine === undefined || at > mine)
|
|
268
|
+
this.tombstones.set(id, at);
|
|
269
|
+
}
|
|
270
|
+
const cutoff = Date.now() - TOMBSTONE_TTL_MS;
|
|
271
|
+
for (const [id, at] of this.tombstones)
|
|
272
|
+
if (at < cutoff)
|
|
273
|
+
this.tombstones.delete(id);
|
|
274
|
+
for (const [id, entry] of Object.entries(disk.data)) {
|
|
275
|
+
const tombstone = this.tombstones.get(id);
|
|
276
|
+
if (tombstone !== undefined && tombstone >= entry.updatedAt)
|
|
277
|
+
continue;
|
|
278
|
+
const mine = this.data[id];
|
|
279
|
+
if (!mine || entry.updatedAt > mine.updatedAt)
|
|
280
|
+
this.data[id] = entry;
|
|
281
|
+
}
|
|
282
|
+
const entries = Object.entries(this.data)
|
|
283
|
+
.filter(([id, entry]) => {
|
|
284
|
+
const tombstone = this.tombstones.get(id);
|
|
285
|
+
return tombstone === undefined || tombstone < entry.updatedAt;
|
|
286
|
+
})
|
|
287
|
+
.sort((a, b) => b[1].updatedAt - a[1].updatedAt)
|
|
288
|
+
.slice(0, MAX_ENTRIES);
|
|
289
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
290
|
+
// Write-then-rename: a reader (another bridge loading, or `-s`) must never see
|
|
291
|
+
// a half-written map, and a crash mid-write must not truncate it.
|
|
292
|
+
const temporary = `${path}.${process.pid}.tmp`;
|
|
293
|
+
const payload = this.tombstones.size > 0
|
|
294
|
+
? { ...Object.fromEntries(entries), [TOMBSTONE_KEY]: Object.fromEntries(this.tombstones) }
|
|
295
|
+
: Object.fromEntries(entries);
|
|
296
|
+
writeFileSync(temporary, JSON.stringify(payload, null, 2), 'utf8');
|
|
297
|
+
renameSync(temporary, path);
|
|
298
|
+
this.dirty = false;
|
|
299
|
+
}
|
|
300
|
+
catch (error) {
|
|
301
|
+
this.log(`[bridge] session map not written: ${String(error)}`);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|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C;YACzB,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC9C,+EAA+E;YAC/E,kEAAkE;YAClE,MAAM,SAAS,GAAG,GAAG,IAAI,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;YAC/C,MAAM,OAAO,GACX,IAAI,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC;gBACtB,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;gBAC1F,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;YAClC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;YACnE,UAAU,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACrB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,GAAG,CAAC,qCAAqC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `oc-acp-client sessions` — every conversation this tool remembers, newest first.
|
|
3
|
+
*
|
|
4
|
+
* The map file is the only place a session outlives a run (`sessions.json`: visible id →
|
|
5
|
+
* the agent's own id, its directory, its title and the command that created it). Until
|
|
6
|
+
* now the only way to read it was to open the file, and the TUI's own session list shows
|
|
7
|
+
* one directory at a time. This prints the whole thing.
|
|
8
|
+
*
|
|
9
|
+
* Paging rather than a pager: the output is a table that should survive being piped or
|
|
10
|
+
* captured, and a program that takes over the terminal cannot be asserted on in a test.
|
|
11
|
+
* `--limit`/`--offset` page it; `--json` gives the raw rows.
|
|
12
|
+
*/
|
|
13
|
+
import { SessionMap } from './session-map.js';
|
|
14
|
+
export interface SessionRow {
|
|
15
|
+
/** The id a client (the TUI) knows this conversation by. */
|
|
16
|
+
id: string;
|
|
17
|
+
/** The agent's own session id. */
|
|
18
|
+
acpSessionId: string;
|
|
19
|
+
directory?: string;
|
|
20
|
+
title?: string;
|
|
21
|
+
/** The agent command that created it (`dsh --profile acp`, `opencode acp`, …). */
|
|
22
|
+
agent?: string;
|
|
23
|
+
/** Last advanced (a prompt that ran). */
|
|
24
|
+
updatedAt: number;
|
|
25
|
+
/** First remembered; absent on rows written before the field existed. */
|
|
26
|
+
createdAt?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface SessionListOptions {
|
|
29
|
+
limit?: number;
|
|
30
|
+
offset?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Only sessions in this directory. Accepted as an absolute path, a path relative to the
|
|
33
|
+
* current directory, a `~`-prefixed one, or a bare fragment (`webapp`) — see
|
|
34
|
+
* `matchesDirectory`.
|
|
35
|
+
*/
|
|
36
|
+
directory?: string;
|
|
37
|
+
/** Only sessions created by this agent command; a bare fragment matches too. */
|
|
38
|
+
agent?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Does a session's directory match what the user typed?
|
|
42
|
+
*
|
|
43
|
+
* A person typing `--directory webapp` means "the one I work in", not "a path ending in
|
|
44
|
+
* webapp", and they type `~/projects/webapp` or `./webapp` just as readily as
|
|
45
|
+
* the full path. So three forms are accepted:
|
|
46
|
+
*
|
|
47
|
+
* 1. a path (absolute, relative, or `~`-prefixed) is resolved and compared for EQUALITY;
|
|
48
|
+
* 2. a bare word that cannot be a path (no separator, not `.`/`..`) is a substring match,
|
|
49
|
+
* which is what makes `--directory webapp` work from anywhere;
|
|
50
|
+
* 3. `~` expands first, so `~/x` and `/Users/me/x` are the same answer.
|
|
51
|
+
*/
|
|
52
|
+
export declare function matchesDirectory(sessionDirectory: string | undefined, wanted: string): boolean;
|
|
53
|
+
/** Same shape for the agent: a path-like query matches exactly, a word matches anywhere. */
|
|
54
|
+
export declare function matchesAgent(agent: string | undefined, wanted: string): boolean;
|
|
55
|
+
export declare const DEFAULT_PAGE = 20;
|
|
56
|
+
/** Newest first. Ties break on id so the order is stable across runs. */
|
|
57
|
+
export declare function listSessions(map: SessionMap, options?: SessionListOptions): SessionRow[];
|
|
58
|
+
/** How many sessions the map holds (after the `--directory` filter). */
|
|
59
|
+
export declare function countSessions(map: SessionMap, options?: SessionListOptions): number;
|
|
60
|
+
/** `2h ago`, `3d ago` — a relative stamp reads faster than an absolute one in a list. */
|
|
61
|
+
export declare function relativeTime(updatedAt: number, now?: number): string;
|
|
62
|
+
/** Truncate in the MIDDLE: the tail of a directory is what tells two of them apart. */
|
|
63
|
+
export declare function truncateMiddle(text: string, width: number): string;
|
|
64
|
+
export interface RenderOptions {
|
|
65
|
+
/** Terminal width, default 100. */
|
|
66
|
+
width?: number;
|
|
67
|
+
now?: number;
|
|
68
|
+
}
|
|
69
|
+
/** The table. One row per session, columns identical to the header. */
|
|
70
|
+
export declare function renderSessions(rows: SessionRow[], options?: RenderOptions): string;
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `oc-acp-client sessions` — every conversation this tool remembers, newest first.
|
|
3
|
+
*
|
|
4
|
+
* The map file is the only place a session outlives a run (`sessions.json`: visible id →
|
|
5
|
+
* the agent's own id, its directory, its title and the command that created it). Until
|
|
6
|
+
* now the only way to read it was to open the file, and the TUI's own session list shows
|
|
7
|
+
* one directory at a time. This prints the whole thing.
|
|
8
|
+
*
|
|
9
|
+
* Paging rather than a pager: the output is a table that should survive being piped or
|
|
10
|
+
* captured, and a program that takes over the terminal cannot be asserted on in a test.
|
|
11
|
+
* `--limit`/`--offset` page it; `--json` gives the raw rows.
|
|
12
|
+
*/
|
|
13
|
+
import { isAbsolute, resolve, sep } from 'node:path';
|
|
14
|
+
import { agentBindingLabel, SessionMap } from './session-map.js';
|
|
15
|
+
/** The session's agent as one line, which is what both the table and the filter compare. */
|
|
16
|
+
const agentOf = (entry) => entry.agent ? agentBindingLabel(entry.agent) : undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Does a session's directory match what the user typed?
|
|
19
|
+
*
|
|
20
|
+
* A person typing `--directory webapp` means "the one I work in", not "a path ending in
|
|
21
|
+
* webapp", and they type `~/projects/webapp` or `./webapp` just as readily as
|
|
22
|
+
* the full path. So three forms are accepted:
|
|
23
|
+
*
|
|
24
|
+
* 1. a path (absolute, relative, or `~`-prefixed) is resolved and compared for EQUALITY;
|
|
25
|
+
* 2. a bare word that cannot be a path (no separator, not `.`/`..`) is a substring match,
|
|
26
|
+
* which is what makes `--directory webapp` work from anywhere;
|
|
27
|
+
* 3. `~` expands first, so `~/x` and `/Users/me/x` are the same answer.
|
|
28
|
+
*/
|
|
29
|
+
export function matchesDirectory(sessionDirectory, wanted) {
|
|
30
|
+
if (!sessionDirectory)
|
|
31
|
+
return false;
|
|
32
|
+
const query = wanted.trim();
|
|
33
|
+
if (!query)
|
|
34
|
+
return true;
|
|
35
|
+
const home = process.env['HOME'];
|
|
36
|
+
const expand = (value) => value === '~' ? (home ?? value) : value.startsWith('~/') && home ? `${home}${value.slice(1)}` : value;
|
|
37
|
+
const asPath = expand(query);
|
|
38
|
+
const absolute = isAbsolute(asPath) ? asPath : resolve(process.cwd(), asPath);
|
|
39
|
+
// `resolve` also normalises `./x`, `a/../b` and a trailing slash.
|
|
40
|
+
if (resolve(sessionDirectory) === resolve(absolute))
|
|
41
|
+
return true;
|
|
42
|
+
// Not a path at all: a fragment. A query with a separator is a path and must not fall
|
|
43
|
+
// through to substring matching — `--directory a/b` should not match `/x/a/bc`.
|
|
44
|
+
const looksLikePath = asPath.includes(sep) || asPath === '.' || asPath === '..';
|
|
45
|
+
if (looksLikePath)
|
|
46
|
+
return false;
|
|
47
|
+
return sessionDirectory.toLowerCase().includes(asPath.toLowerCase());
|
|
48
|
+
}
|
|
49
|
+
/** Same shape for the agent: a path-like query matches exactly, a word matches anywhere. */
|
|
50
|
+
export function matchesAgent(agent, wanted) {
|
|
51
|
+
const query = wanted.trim().toLowerCase();
|
|
52
|
+
if (!query)
|
|
53
|
+
return true;
|
|
54
|
+
if (!agent)
|
|
55
|
+
return false;
|
|
56
|
+
const label = agent.toLowerCase();
|
|
57
|
+
if (label === query)
|
|
58
|
+
return true;
|
|
59
|
+
// `dsh --profile acp` typed whole, or just `<profile>` — both should find it, and a
|
|
60
|
+
// longer command that merely contains the word is a fragment match by design.
|
|
61
|
+
return label.includes(query);
|
|
62
|
+
}
|
|
63
|
+
export const DEFAULT_PAGE = 20;
|
|
64
|
+
/** Newest first. Ties break on id so the order is stable across runs. */
|
|
65
|
+
export function listSessions(map, options = {}) {
|
|
66
|
+
const rows = [];
|
|
67
|
+
for (const [id, entry] of map.entries()) {
|
|
68
|
+
if (options.directory && !matchesDirectory(entry.directory, options.directory))
|
|
69
|
+
continue;
|
|
70
|
+
if (options.agent && !matchesAgent(agentOf(entry), options.agent))
|
|
71
|
+
continue;
|
|
72
|
+
rows.push({
|
|
73
|
+
id,
|
|
74
|
+
acpSessionId: entry.acpSessionId,
|
|
75
|
+
...(entry.directory ? { directory: entry.directory } : {}),
|
|
76
|
+
...(entry.title ? { title: entry.title } : {}),
|
|
77
|
+
...(entry.agent ? { agent: agentBindingLabel(entry.agent) } : {}),
|
|
78
|
+
updatedAt: entry.updatedAt,
|
|
79
|
+
...(entry.createdAt !== undefined ? { createdAt: entry.createdAt } : {}),
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
rows.sort((a, b) => b.updatedAt - a.updatedAt || a.id.localeCompare(b.id));
|
|
83
|
+
const offset = Math.max(0, options.offset ?? 0);
|
|
84
|
+
const limit = Math.max(1, options.limit ?? DEFAULT_PAGE);
|
|
85
|
+
return rows.slice(offset, offset + limit);
|
|
86
|
+
}
|
|
87
|
+
/** How many sessions the map holds (after the `--directory` filter). */
|
|
88
|
+
export function countSessions(map, options = {}) {
|
|
89
|
+
let total = 0;
|
|
90
|
+
for (const [, entry] of map.entries()) {
|
|
91
|
+
if (options.directory && !matchesDirectory(entry.directory, options.directory))
|
|
92
|
+
continue;
|
|
93
|
+
if (options.agent && !matchesAgent(agentOf(entry), options.agent))
|
|
94
|
+
continue;
|
|
95
|
+
total += 1;
|
|
96
|
+
}
|
|
97
|
+
return total;
|
|
98
|
+
}
|
|
99
|
+
/** `2h ago`, `3d ago` — a relative stamp reads faster than an absolute one in a list. */
|
|
100
|
+
export function relativeTime(updatedAt, now = Date.now()) {
|
|
101
|
+
if (!updatedAt)
|
|
102
|
+
return ' ?';
|
|
103
|
+
const seconds = Math.max(0, Math.round((now - updatedAt) / 1000));
|
|
104
|
+
if (seconds < 60)
|
|
105
|
+
return `${seconds}s ago`;
|
|
106
|
+
const minutes = Math.round(seconds / 60);
|
|
107
|
+
if (minutes < 60)
|
|
108
|
+
return `${minutes}m ago`;
|
|
109
|
+
const hours = Math.round(minutes / 60);
|
|
110
|
+
if (hours < 24)
|
|
111
|
+
return `${hours}h ago`;
|
|
112
|
+
const days = Math.round(hours / 24);
|
|
113
|
+
return `${days}d ago`;
|
|
114
|
+
}
|
|
115
|
+
/** Truncate in the MIDDLE: the tail of a directory is what tells two of them apart. */
|
|
116
|
+
export function truncateMiddle(text, width) {
|
|
117
|
+
if (width <= 1)
|
|
118
|
+
return '…'.slice(0, width);
|
|
119
|
+
if (text.length <= width)
|
|
120
|
+
return text;
|
|
121
|
+
if (width <= 3)
|
|
122
|
+
return `${text.slice(0, width - 1)}…`;
|
|
123
|
+
const keep = width - 1;
|
|
124
|
+
const head = Math.ceil(keep / 2);
|
|
125
|
+
const tail = keep - head;
|
|
126
|
+
return `${text.slice(0, head)}…${text.slice(text.length - tail)}`;
|
|
127
|
+
}
|
|
128
|
+
/** The table. One row per session, columns identical to the header. */
|
|
129
|
+
export function renderSessions(rows, options = {}) {
|
|
130
|
+
const width = Math.max(60, options.width ?? 100);
|
|
131
|
+
const now = options.now ?? Date.now();
|
|
132
|
+
const home = process.env['HOME'] ?? '';
|
|
133
|
+
const short = (path) => {
|
|
134
|
+
if (!path)
|
|
135
|
+
return '-';
|
|
136
|
+
// `~` is what a person types; the full path only adds noise to every row.
|
|
137
|
+
return home && path.startsWith(home) ? `~${path.slice(home.length)}` : path;
|
|
138
|
+
};
|
|
139
|
+
// Column widths: the id and the relative time are fixed-width, so the title takes the
|
|
140
|
+
// slack and the directory the rest. Titles are cut before directories, because a title
|
|
141
|
+
// is the part a person can reconstruct from the directory + the time.
|
|
142
|
+
// Two stamps: when the conversation started, and when it was last advanced. They are
|
|
143
|
+
// different facts — a session created three days ago and used a minute ago is the
|
|
144
|
+
// common case — and only the second is what `-c` ranks by.
|
|
145
|
+
const when = 9;
|
|
146
|
+
// The session id is NEVER truncated: it is the one value a person copies out of this
|
|
147
|
+
// table (`-s <id>`), and an abbreviated id cannot be pasted anywhere. Measured on 197
|
|
148
|
+
// real rows: 13 to 47 characters, and only the `ses_acp_session<uuid>` shape reaches the
|
|
149
|
+
// long end.
|
|
150
|
+
const id = Math.max(13, ...rows.map((row) => row.id.length));
|
|
151
|
+
// The id is fixed and can be 47 wide, so on a narrow terminal something has to give.
|
|
152
|
+
// The directory yields first (its tail still identifies it), then the title; both keep
|
|
153
|
+
// a floor, and a terminal narrower than the floor simply wraps.
|
|
154
|
+
const fixed = when * 2 + id + 26 + 5;
|
|
155
|
+
const slack = width - fixed;
|
|
156
|
+
const dir = Math.max(16, Math.min(36, Math.floor(slack * 0.5)));
|
|
157
|
+
// The agent is a bounded column: a profile-style command is the longest we see, and
|
|
158
|
+
// letting it size itself would push the title — the part a person reads — off the right
|
|
159
|
+
// edge. Everything left over belongs to the title.
|
|
160
|
+
const agent = 26;
|
|
161
|
+
const title = Math.max(10, width - fixed - dir);
|
|
162
|
+
const lines = [];
|
|
163
|
+
// The title is last and takes the slack: it is the column a person reads first, and the
|
|
164
|
+
// one that benefits from whatever the terminal has left over.
|
|
165
|
+
lines.push([
|
|
166
|
+
'CREATED'.padEnd(when),
|
|
167
|
+
'UPDATED'.padEnd(when),
|
|
168
|
+
'SESSION'.padEnd(id),
|
|
169
|
+
'DIRECTORY'.padEnd(dir),
|
|
170
|
+
'AGENT'.padEnd(agent),
|
|
171
|
+
'TITLE',
|
|
172
|
+
].join(' '));
|
|
173
|
+
for (const row of rows) {
|
|
174
|
+
lines.push([
|
|
175
|
+
// Rows written before the field existed have no creation time and get a blank:
|
|
176
|
+
// filling it from `updatedAt` would claim something nobody measured. New sessions
|
|
177
|
+
// are stamped from now on (see `SessionMap.remember`).
|
|
178
|
+
(row.createdAt !== undefined ? relativeTime(row.createdAt, now) : '-').padEnd(when),
|
|
179
|
+
relativeTime(row.updatedAt, now).padEnd(when),
|
|
180
|
+
row.id.padEnd(id),
|
|
181
|
+
truncateMiddle(short(row.directory), dir).padEnd(dir),
|
|
182
|
+
truncateMiddle(row.agent ?? '-', agent).padEnd(agent),
|
|
183
|
+
truncateMiddle(row.title ?? '-', title),
|
|
184
|
+
].join(' '));
|
|
185
|
+
}
|
|
186
|
+
return lines.join('\n');
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=sessions-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessions-command.js","sourceRoot":"","sources":["../src/sessions-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAErD,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAwB,MAAM,kBAAkB,CAAC;AAEvF,4FAA4F;AAC5F,MAAM,OAAO,GAAG,CAAC,KAAsB,EAAsB,EAAE,CAC7D,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AA8B3D;;;;;;;;;;;GAWG;AACH,MAA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C,SAAS,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;YAC7C,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC;YACjB,cAAc,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;YACrD,cAAc,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,EAAE,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;YACrD,cAAc,CAAC,GAAG,CAAC,KAAK,IAAI,GAAG,EAAE,KAAK,CAAC;SACxC,CAAC,IAAI,CAAC,GAAG,CAAC,CACZ,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/sse.d.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `/api/event` SSE hub.
|
|
3
|
+
*
|
|
4
|
+
* Contract (observed, including the handshake the client waits for):
|
|
5
|
+
* frame := `data: ` + JSON + `\n\n`
|
|
6
|
+
* first := {"id":"evt_connected","type":"server.connected","data":{}}
|
|
7
|
+
*
|
|
8
|
+
* A bounded ring is kept so a reconnecting client can replay what it missed —
|
|
9
|
+
* without it, a client that attaches a moment after a session is created never
|
|
10
|
+
* learns the session exists until the next event happens to arrive.
|
|
11
|
+
*/
|
|
12
|
+
import type { BridgeEvent } from './contract.js';
|
|
13
|
+
export interface SseClient {
|
|
14
|
+
send(event: BridgeEvent): void;
|
|
15
|
+
close(): void;
|
|
16
|
+
}
|
|
17
|
+
export interface SseHubOptions {
|
|
18
|
+
/** How many frames to retain for `Last-Event-ID` replay. */
|
|
19
|
+
replayCapacity?: number;
|
|
20
|
+
}
|
|
21
|
+
export declare class SseHub {
|
|
22
|
+
private seq;
|
|
23
|
+
private readonly ring;
|
|
24
|
+
private readonly clients;
|
|
25
|
+
private readonly capacity;
|
|
26
|
+
constructor(options?: SseHubOptions);
|
|
27
|
+
private trace;
|
|
28
|
+
/** Build the Response for `GET /api/event`. */
|
|
29
|
+
connect(opts?: {
|
|
30
|
+
lastEventId?: string;
|
|
31
|
+
}): Response;
|
|
32
|
+
/** Broadcast an event. Returns it with its assigned id. */
|
|
33
|
+
emit(event: Omit<BridgeEvent, 'id' | 'created'> & {
|
|
34
|
+
id?: string;
|
|
35
|
+
created?: number;
|
|
36
|
+
}): BridgeEvent;
|
|
37
|
+
get clientCount(): number;
|
|
38
|
+
closeAll(): void;
|
|
39
|
+
private since;
|
|
40
|
+
}
|