@ours.network/fleet 2.4.0-nightly.2 → 2.4.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/dist/application/model-catalog.d.ts +1 -1
- package/dist/application/model-catalog.js +2 -2
- package/dist/application/task-room-service.d.ts +8 -0
- package/dist/application/task-room-service.js +15 -0
- package/dist/build-info.json +5 -5
- package/dist/docs.d.ts +1 -1
- package/dist/docs.js +22 -0
- package/dist/doctor.js +2 -2
- package/dist/harness/codex-runtime.d.ts +2 -0
- package/dist/harness/codex-runtime.js +7 -1
- package/dist/harness/codex.js +2 -3
- package/dist/ops.js +6 -0
- package/dist/rooms-tasks/cli.js +24 -0
- package/dist/rooms-tasks/deletion.js +4 -0
- package/dist/rooms-tasks/task-review.js +2 -0
- package/dist/rooms-tasks/task-state.d.ts +6 -1
- package/dist/rooms-tasks/task-state.js +20 -1
- package/dist/rooms-tasks/types.d.ts +17 -0
- package/dist/rooms-tasks/workspace-removal.d.ts +85 -0
- package/dist/rooms-tasks/workspace-removal.js +633 -0
- package/dist/rooms-tasks/workspace.d.ts +9 -1
- package/dist/rooms-tasks/workspace.js +13 -1
- package/dist/spawn.js +2 -0
- package/dist/web/resource-views.d.ts +1 -1
- package/dist/web/resource-views.js +1 -7
- package/dist/web/runtime.js +0 -13
- package/dist/web/server.d.ts +0 -3
- package/dist/web/server.js +10 -24
- package/docs/task-workspaces.md +51 -1
- package/package.json +7 -7
- package/presets/brain-catalog.json +5 -2
- package/dist/channels/identity-reads.d.ts +0 -69
- package/dist/channels/identity-reads.js +0 -47
- package/dist/channels/indexer.d.ts +0 -55
- package/dist/channels/indexer.js +0 -214
- package/dist/channels/runtime.d.ts +0 -30
- package/dist/channels/runtime.js +0 -125
- package/dist/channels/service.d.ts +0 -61
- package/dist/channels/service.js +0 -88
- package/dist/channels/sources.d.ts +0 -46
- package/dist/channels/sources.js +0 -68
- package/dist/channels/store.d.ts +0 -103
- package/dist/channels/store.js +0 -204
package/dist/channels/store.d.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import type { PerspectiveSource } from './sources.js';
|
|
2
|
-
/** One local identity's view of one external contact. Metadata only, never bodies. */
|
|
3
|
-
export interface ChannelEdge {
|
|
4
|
-
contactCid: string;
|
|
5
|
-
contactName: string;
|
|
6
|
-
lastActivity: string;
|
|
7
|
-
rootCid?: string;
|
|
8
|
-
rootName?: string;
|
|
9
|
-
roleId?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface ChannelPerspective {
|
|
12
|
-
sourceCid: string;
|
|
13
|
-
sourceName: string;
|
|
14
|
-
kind: 'owner' | 'agent';
|
|
15
|
-
roleId?: string;
|
|
16
|
-
ended: boolean;
|
|
17
|
-
stale: boolean;
|
|
18
|
-
contactName: string;
|
|
19
|
-
lastActivity: string;
|
|
20
|
-
claimedRoot?: {
|
|
21
|
-
rootCid: string;
|
|
22
|
-
rootName: string;
|
|
23
|
-
roleId: string;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
export interface ChannelRow {
|
|
27
|
-
cid: string;
|
|
28
|
-
name: string;
|
|
29
|
-
lastActivity: string;
|
|
30
|
-
/** Present only when every perspective with a claim agrees. Signed claim, not verified. */
|
|
31
|
-
claimedRoot?: {
|
|
32
|
-
rootCid: string;
|
|
33
|
-
rootName: string;
|
|
34
|
-
};
|
|
35
|
-
conflictingRootClaims: boolean;
|
|
36
|
-
perspectives: number;
|
|
37
|
-
ownerConnected: boolean;
|
|
38
|
-
}
|
|
39
|
-
export interface ChannelPage {
|
|
40
|
-
channels: ChannelRow[];
|
|
41
|
-
nextCursor: string | null;
|
|
42
|
-
}
|
|
43
|
-
/** Rows whose perspectives have all ended drop out of Recent after this long. */
|
|
44
|
-
export declare const ENDED_RETENTION_MS: number;
|
|
45
|
-
export declare const CHANNELS_DB = "channels.db";
|
|
46
|
-
/**
|
|
47
|
-
* Durable Channels projection. Edges are keyed (source, contact) and replaced
|
|
48
|
-
* per source in one transaction; the per-contact row is recomputed from its
|
|
49
|
-
* edges, so the same external contact known to several identities is one row
|
|
50
|
-
* with several perspectives, and two contacts sharing a root stay two rows.
|
|
51
|
-
*/
|
|
52
|
-
export declare class ChannelsStore {
|
|
53
|
-
private readonly now;
|
|
54
|
-
private readonly db;
|
|
55
|
-
readonly path: string;
|
|
56
|
-
constructor(dir: string, now?: () => number);
|
|
57
|
-
close(): void;
|
|
58
|
-
private transaction;
|
|
59
|
-
/** Reconcile the source set: unknown sources and their edges are removed, ended ones keep metadata. */
|
|
60
|
-
setSources(sources: PerspectiveSource[]): void;
|
|
61
|
-
/** Replace one source's edges from a fresh observation at the given daemon source position. */
|
|
62
|
-
replaceEdges(sourceCid: string, edges: ChannelEdge[], observed?: {
|
|
63
|
-
producerGeneration: string;
|
|
64
|
-
position: number;
|
|
65
|
-
}): void;
|
|
66
|
-
/**
|
|
67
|
-
* Drop every edge to a now-internal identity, from every source including ended ones,
|
|
68
|
-
* whose cached edges are never re-observed. Local SQL only.
|
|
69
|
-
*/
|
|
70
|
-
excludeContacts(internal: Set<string>): void;
|
|
71
|
-
markStale(sourceCid: string): void;
|
|
72
|
-
private recompute;
|
|
73
|
-
/**
|
|
74
|
-
* Keyset-paginated channel rows, newest activity first. `root` narrows to rows
|
|
75
|
-
* claiming that root; `q` matches contact name, root name or CID prefix.
|
|
76
|
-
*/
|
|
77
|
-
list(options?: {
|
|
78
|
-
cursor?: string;
|
|
79
|
-
limit?: number;
|
|
80
|
-
q?: string;
|
|
81
|
-
root?: string;
|
|
82
|
-
}): ChannelPage;
|
|
83
|
-
/** One channel with every perspective; null when unknown. */
|
|
84
|
-
get(cid: string): {
|
|
85
|
-
channel: ChannelRow;
|
|
86
|
-
perspectives: ChannelPerspective[];
|
|
87
|
-
} | null;
|
|
88
|
-
/** Whether `sourceCid` is a recorded perspective of `contactCid`. */
|
|
89
|
-
hasPerspective(contactCid: string, sourceCid: string): {
|
|
90
|
-
name: string;
|
|
91
|
-
kind: string;
|
|
92
|
-
roleId?: string;
|
|
93
|
-
ended: boolean;
|
|
94
|
-
generation?: string;
|
|
95
|
-
} | null;
|
|
96
|
-
sourcesSummary(): Array<{
|
|
97
|
-
cid: string;
|
|
98
|
-
name: string;
|
|
99
|
-
kind: string;
|
|
100
|
-
ended: boolean;
|
|
101
|
-
stale: boolean;
|
|
102
|
-
}>;
|
|
103
|
-
}
|
package/dist/channels/store.js
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import { chmodSync, mkdirSync } from 'node:fs';
|
|
3
|
-
import { join } from 'node:path';
|
|
4
|
-
/** Rows whose perspectives have all ended drop out of Recent after this long. */
|
|
5
|
-
export const ENDED_RETENTION_MS = 30 * 86_400_000;
|
|
6
|
-
export const CHANNELS_DB = 'channels.db';
|
|
7
|
-
/**
|
|
8
|
-
* Durable Channels projection. Edges are keyed (source, contact) and replaced
|
|
9
|
-
* per source in one transaction; the per-contact row is recomputed from its
|
|
10
|
-
* edges, so the same external contact known to several identities is one row
|
|
11
|
-
* with several perspectives, and two contacts sharing a root stay two rows.
|
|
12
|
-
*/
|
|
13
|
-
export class ChannelsStore {
|
|
14
|
-
now;
|
|
15
|
-
db;
|
|
16
|
-
path;
|
|
17
|
-
constructor(dir, now = Date.now) {
|
|
18
|
-
this.now = now;
|
|
19
|
-
const { DatabaseSync } = createRequire(import.meta.url)('node:sqlite');
|
|
20
|
-
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
21
|
-
chmodSync(dir, 0o700);
|
|
22
|
-
this.path = join(dir, CHANNELS_DB);
|
|
23
|
-
this.db = new DatabaseSync(this.path);
|
|
24
|
-
chmodSync(this.path, 0o600);
|
|
25
|
-
this.db.exec(`PRAGMA journal_mode=WAL; PRAGMA busy_timeout=5000;
|
|
26
|
-
CREATE TABLE IF NOT EXISTS sources(cid TEXT PRIMARY KEY,name TEXT NOT NULL,kind TEXT NOT NULL,role_id TEXT,ended INTEGER NOT NULL DEFAULT 0,stale INTEGER NOT NULL DEFAULT 1,observed_at INTEGER);
|
|
27
|
-
CREATE TABLE IF NOT EXISTS edges(source_cid TEXT NOT NULL,contact_cid TEXT NOT NULL,contact_name TEXT NOT NULL,last_activity TEXT NOT NULL,root_cid TEXT,root_name TEXT,role_id TEXT,PRIMARY KEY(source_cid,contact_cid));
|
|
28
|
-
CREATE INDEX IF NOT EXISTS edges_contact ON edges(contact_cid);
|
|
29
|
-
CREATE TABLE IF NOT EXISTS channels(cid TEXT PRIMARY KEY,name TEXT NOT NULL,last_activity TEXT NOT NULL,root_cid TEXT,root_name TEXT,conflicting INTEGER NOT NULL,perspectives INTEGER NOT NULL,owner_connected INTEGER NOT NULL,live_perspectives INTEGER NOT NULL);
|
|
30
|
-
CREATE INDEX IF NOT EXISTS channels_recent ON channels(last_activity DESC,cid);
|
|
31
|
-
CREATE INDEX IF NOT EXISTS channels_root ON channels(root_cid,last_activity DESC,cid);`);
|
|
32
|
-
// The daemon source lifetime each source was last observed at (pins later history reads).
|
|
33
|
-
const columns = new Set(this.db.prepare('PRAGMA table_info(sources)').all().map(c => c.name));
|
|
34
|
-
if (!columns.has('generation'))
|
|
35
|
-
this.db.exec('ALTER TABLE sources ADD COLUMN generation TEXT');
|
|
36
|
-
if (!columns.has('position'))
|
|
37
|
-
this.db.exec('ALTER TABLE sources ADD COLUMN position INTEGER');
|
|
38
|
-
}
|
|
39
|
-
close() { this.db.close(); }
|
|
40
|
-
transaction(run) {
|
|
41
|
-
this.db.exec('BEGIN IMMEDIATE');
|
|
42
|
-
try {
|
|
43
|
-
const result = run();
|
|
44
|
-
this.db.exec('COMMIT');
|
|
45
|
-
return result;
|
|
46
|
-
}
|
|
47
|
-
catch (error) {
|
|
48
|
-
this.db.exec('ROLLBACK');
|
|
49
|
-
throw error;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/** Reconcile the source set: unknown sources and their edges are removed, ended ones keep metadata. */
|
|
53
|
-
setSources(sources) {
|
|
54
|
-
this.transaction(() => {
|
|
55
|
-
const keep = new Set(sources.map(s => s.cid));
|
|
56
|
-
const touched = new Set();
|
|
57
|
-
for (const row of this.db.prepare('SELECT cid FROM sources').all()) {
|
|
58
|
-
if (keep.has(row.cid))
|
|
59
|
-
continue;
|
|
60
|
-
for (const edge of this.db.prepare('SELECT contact_cid FROM edges WHERE source_cid=?').all(row.cid))
|
|
61
|
-
touched.add(edge.contact_cid);
|
|
62
|
-
this.db.prepare('DELETE FROM edges WHERE source_cid=?').run(row.cid);
|
|
63
|
-
this.db.prepare('DELETE FROM sources WHERE cid=?').run(row.cid);
|
|
64
|
-
}
|
|
65
|
-
for (const s of sources) {
|
|
66
|
-
this.db.prepare(`INSERT INTO sources(cid,name,kind,role_id,ended) VALUES(?,?,?,?,?)
|
|
67
|
-
ON CONFLICT(cid) DO UPDATE SET name=excluded.name,kind=excluded.kind,role_id=excluded.role_id,ended=excluded.ended`)
|
|
68
|
-
.run(s.cid, s.name, s.kind, s.roleId ?? null, s.ended ? 1 : 0);
|
|
69
|
-
for (const edge of this.db.prepare('SELECT contact_cid FROM edges WHERE source_cid=?').all(s.cid))
|
|
70
|
-
touched.add(edge.contact_cid);
|
|
71
|
-
}
|
|
72
|
-
for (const cid of touched)
|
|
73
|
-
this.recompute(cid);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
/** Replace one source's edges from a fresh observation at the given daemon source position. */
|
|
77
|
-
replaceEdges(sourceCid, edges, observed) {
|
|
78
|
-
this.transaction(() => {
|
|
79
|
-
const touched = new Set(edges.map(e => e.contactCid));
|
|
80
|
-
for (const row of this.db.prepare('SELECT contact_cid FROM edges WHERE source_cid=?').all(sourceCid))
|
|
81
|
-
touched.add(row.contact_cid);
|
|
82
|
-
this.db.prepare('DELETE FROM edges WHERE source_cid=?').run(sourceCid);
|
|
83
|
-
const insert = this.db.prepare('INSERT INTO edges(source_cid,contact_cid,contact_name,last_activity,root_cid,root_name,role_id) VALUES(?,?,?,?,?,?,?)');
|
|
84
|
-
for (const e of edges)
|
|
85
|
-
insert.run(sourceCid, e.contactCid, e.contactName, e.lastActivity, e.rootCid ?? null, e.rootName ?? null, e.roleId ?? null);
|
|
86
|
-
this.db.prepare('UPDATE sources SET stale=0,observed_at=?,generation=?,position=? WHERE cid=?')
|
|
87
|
-
.run(this.now(), observed?.producerGeneration ?? null, observed?.position ?? null, sourceCid);
|
|
88
|
-
for (const cid of touched)
|
|
89
|
-
this.recompute(cid);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Drop every edge to a now-internal identity, from every source including ended ones,
|
|
94
|
-
* whose cached edges are never re-observed. Local SQL only.
|
|
95
|
-
*/
|
|
96
|
-
excludeContacts(internal) {
|
|
97
|
-
if (!internal.size)
|
|
98
|
-
return;
|
|
99
|
-
this.transaction(() => {
|
|
100
|
-
const cids = [...internal];
|
|
101
|
-
const marks = cids.map(() => '?').join(',');
|
|
102
|
-
const touched = this.db.prepare(`SELECT DISTINCT contact_cid FROM edges WHERE contact_cid IN (${marks})`).all(...cids).map(r => r.contact_cid);
|
|
103
|
-
if (!touched.length)
|
|
104
|
-
return;
|
|
105
|
-
this.db.prepare(`DELETE FROM edges WHERE contact_cid IN (${marks})`).run(...cids);
|
|
106
|
-
for (const cid of touched)
|
|
107
|
-
this.recompute(cid);
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
markStale(sourceCid) {
|
|
111
|
-
this.db.prepare('UPDATE sources SET stale=1 WHERE cid=?').run(sourceCid);
|
|
112
|
-
}
|
|
113
|
-
recompute(contactCid) {
|
|
114
|
-
const edges = this.db.prepare(`SELECT e.*,s.kind,s.ended FROM edges e JOIN sources s ON s.cid=e.source_cid WHERE e.contact_cid=?`)
|
|
115
|
-
.all(contactCid);
|
|
116
|
-
if (!edges.length) {
|
|
117
|
-
this.db.prepare('DELETE FROM channels WHERE cid=?').run(contactCid);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
const newest = edges.reduce((a, b) => (b.last_activity > a.last_activity ? b : a));
|
|
121
|
-
const claims = new Map();
|
|
122
|
-
for (const e of edges)
|
|
123
|
-
if (e.root_cid)
|
|
124
|
-
claims.set(e.root_cid, e.root_name ?? '');
|
|
125
|
-
const single = claims.size === 1 ? [...claims.entries()][0] : undefined;
|
|
126
|
-
this.db.prepare(`INSERT INTO channels(cid,name,last_activity,root_cid,root_name,conflicting,perspectives,owner_connected,live_perspectives) VALUES(?,?,?,?,?,?,?,?,?)
|
|
127
|
-
ON CONFLICT(cid) DO UPDATE SET name=excluded.name,last_activity=excluded.last_activity,root_cid=excluded.root_cid,root_name=excluded.root_name,
|
|
128
|
-
conflicting=excluded.conflicting,perspectives=excluded.perspectives,owner_connected=excluded.owner_connected,live_perspectives=excluded.live_perspectives`)
|
|
129
|
-
.run(contactCid, newest.contact_name, newest.last_activity, single?.[0] ?? null, single?.[1] ?? null, claims.size > 1 ? 1 : 0, edges.length, edges.some(e => e.kind === 'owner' && !e.ended) ? 1 : 0, edges.filter(e => !e.ended).length);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Keyset-paginated channel rows, newest activity first. `root` narrows to rows
|
|
133
|
-
* claiming that root; `q` matches contact name, root name or CID prefix.
|
|
134
|
-
*/
|
|
135
|
-
list(options = {}) {
|
|
136
|
-
const limit = Math.min(Math.max(Math.trunc(options.limit ?? 50), 1), 200);
|
|
137
|
-
const where = ['(live_perspectives>0 OR last_activity>=?)'];
|
|
138
|
-
const args = [new Date(this.now() - ENDED_RETENTION_MS).toISOString()];
|
|
139
|
-
if (options.root) {
|
|
140
|
-
where.push('root_cid=?');
|
|
141
|
-
args.push(options.root.toUpperCase());
|
|
142
|
-
}
|
|
143
|
-
if (options.q) {
|
|
144
|
-
const q = options.q.trim().toLowerCase();
|
|
145
|
-
where.push(`(instr(lower(name),?)>0 OR instr(lower(coalesce(root_name,'')),?)>0 OR cid LIKE ?)`);
|
|
146
|
-
args.push(q, q, `${q.toUpperCase().replace(/[%_]/g, '')}%`);
|
|
147
|
-
}
|
|
148
|
-
if (options.cursor) {
|
|
149
|
-
const [at, cid] = decodeCursor(options.cursor);
|
|
150
|
-
where.push('(last_activity<? OR (last_activity=? AND cid>?))');
|
|
151
|
-
args.push(at, at, cid);
|
|
152
|
-
}
|
|
153
|
-
const rows = this.db.prepare(`SELECT * FROM channels WHERE ${where.join(' AND ')} ORDER BY last_activity DESC,cid ASC LIMIT ?`)
|
|
154
|
-
.all(...args, limit + 1);
|
|
155
|
-
const more = rows.length > limit;
|
|
156
|
-
if (more)
|
|
157
|
-
rows.pop();
|
|
158
|
-
const last = rows.at(-1);
|
|
159
|
-
return { channels: rows.map(toRow), nextCursor: more && last ? encodeCursor(last.last_activity, last.cid) : null };
|
|
160
|
-
}
|
|
161
|
-
/** One channel with every perspective; null when unknown. */
|
|
162
|
-
get(cid) {
|
|
163
|
-
const row = this.db.prepare('SELECT * FROM channels WHERE cid=?').get(cid.toUpperCase());
|
|
164
|
-
if (!row)
|
|
165
|
-
return null;
|
|
166
|
-
const edges = this.db.prepare(`SELECT e.*,s.name AS source_name,s.kind,s.role_id AS source_role,s.ended,s.stale FROM edges e JOIN sources s ON s.cid=e.source_cid
|
|
167
|
-
WHERE e.contact_cid=? ORDER BY e.last_activity DESC,s.kind DESC`).all(row.cid);
|
|
168
|
-
return {
|
|
169
|
-
channel: toRow(row),
|
|
170
|
-
perspectives: edges.map(e => ({
|
|
171
|
-
sourceCid: e.source_cid, sourceName: e.source_name, kind: e.kind, ...(e.source_role ? { roleId: e.source_role } : {}),
|
|
172
|
-
ended: !!e.ended, stale: !!e.stale, contactName: e.contact_name, lastActivity: e.last_activity,
|
|
173
|
-
...(e.root_cid ? { claimedRoot: { rootCid: e.root_cid, rootName: e.root_name ?? '', roleId: e.role_id ?? '' } } : {}),
|
|
174
|
-
})),
|
|
175
|
-
};
|
|
176
|
-
}
|
|
177
|
-
/** Whether `sourceCid` is a recorded perspective of `contactCid`. */
|
|
178
|
-
hasPerspective(contactCid, sourceCid) {
|
|
179
|
-
const row = this.db.prepare(`SELECT s.name,s.kind,s.role_id,s.ended,s.generation FROM edges e JOIN sources s ON s.cid=e.source_cid WHERE e.contact_cid=? AND e.source_cid=?`)
|
|
180
|
-
.get(contactCid.toUpperCase(), sourceCid.toUpperCase());
|
|
181
|
-
return row ? { name: row.name, kind: row.kind, ...(row.role_id ? { roleId: row.role_id } : {}), ended: !!row.ended, ...(row.generation ? { generation: row.generation } : {}) } : null;
|
|
182
|
-
}
|
|
183
|
-
sourcesSummary() {
|
|
184
|
-
return this.db.prepare('SELECT cid,name,kind,ended,stale FROM sources ORDER BY kind DESC,name').all()
|
|
185
|
-
.map(s => ({ cid: s.cid, name: s.name, kind: s.kind, ended: !!s.ended, stale: !!s.stale }));
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
function toRow(row) {
|
|
189
|
-
return {
|
|
190
|
-
cid: row.cid, name: row.name, lastActivity: row.last_activity,
|
|
191
|
-
...(row.root_cid ? { claimedRoot: { rootCid: row.root_cid, rootName: row.root_name ?? '' } } : {}),
|
|
192
|
-
conflictingRootClaims: !!row.conflicting, perspectives: Number(row.perspectives), ownerConnected: !!row.owner_connected,
|
|
193
|
-
};
|
|
194
|
-
}
|
|
195
|
-
const encodeCursor = (at, cid) => Buffer.from(JSON.stringify([at, cid])).toString('base64url');
|
|
196
|
-
function decodeCursor(cursor) {
|
|
197
|
-
try {
|
|
198
|
-
const value = JSON.parse(Buffer.from(cursor, 'base64url').toString('utf8'));
|
|
199
|
-
if (Array.isArray(value) && value.length === 2 && value.every(v => typeof v === 'string'))
|
|
200
|
-
return value;
|
|
201
|
-
}
|
|
202
|
-
catch { /* fall through */ }
|
|
203
|
-
throw new Error('invalid channels cursor');
|
|
204
|
-
}
|