@codyn06/cboard 0.2.0 → 0.3.1
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 +6 -2
- package/dist/api.d.ts +29 -3
- package/dist/api.js +86 -27
- package/dist/cache.d.ts +28 -0
- package/dist/cache.js +101 -0
- package/dist/cli.js +2 -1
- package/dist/docs.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/issues.js +2 -1
- package/kit/cboard-connect.js +41 -19
- package/kit/cboard-kit/connect-check.js +7 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ graph, and checks that the connection works.
|
|
|
7
7
|
Requires Node 20 or newer. No native modules and no install scripts.
|
|
8
8
|
|
|
9
9
|
```sh
|
|
10
|
-
npx @codyn06/cboard connect
|
|
10
|
+
npx @codyn06/cboard connect # browser login and project selection
|
|
11
11
|
npx @codyn06/cboard sync # sync the committed code to the graph
|
|
12
12
|
npx @codyn06/cboard check # is the token accepted, is the project visible?
|
|
13
13
|
npx @codyn06/cboard connect --goal "<one line>" # record the project goal as a requirement node
|
|
@@ -19,7 +19,7 @@ Or install it once and use the `cboard` command directly:
|
|
|
19
19
|
|
|
20
20
|
```sh
|
|
21
21
|
npm install --global @codyn06/cboard
|
|
22
|
-
cboard connect
|
|
22
|
+
cboard connect
|
|
23
23
|
cboard sync
|
|
24
24
|
cboard check
|
|
25
25
|
```
|
|
@@ -39,6 +39,10 @@ changed. `cboard connect` also keeps the generated files on LF with a marked `#
|
|
|
39
39
|
|
|
40
40
|
## The token
|
|
41
41
|
|
|
42
|
+
`cboard connect` opens browser device login and saves the token to the repository's ignored
|
|
43
|
+
`.cboard/token` file. To configure a repository before signing in, use
|
|
44
|
+
`cboard connect --project <project-uuid> --no-login`, then save a token manually.
|
|
45
|
+
|
|
42
46
|
Create a token in the cboard web app (the "Agent tokens" button in the project header; members pick
|
|
43
47
|
`graph:read`, `graph:contribute` and `graph:context`, viewers are read-only) and save it to `.cboard/token` in the repository
|
|
44
48
|
(`connect` adds it to `.gitignore`), or export it as `CBOARD_PAT`. The repository's token file takes
|
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type WakeOptions } from "./wake.js";
|
|
2
|
+
import { type HeadStore } from "./cache.js";
|
|
2
3
|
import type { Contribution, Receipt, Result, Snapshot } from "./model.js";
|
|
3
4
|
export declare class GraphHttpError extends Error {
|
|
4
5
|
readonly status: number;
|
|
@@ -9,13 +10,19 @@ export declare class GraphToolError extends Error {
|
|
|
9
10
|
readonly code: string;
|
|
10
11
|
constructor(tool: string, code: string);
|
|
11
12
|
}
|
|
13
|
+
export interface ContextApiOptions extends WakeOptions {
|
|
14
|
+
/** Mirror of the heads read at the previous sync; reconcile then fetches only what changed. */
|
|
15
|
+
heads?: HeadStore;
|
|
16
|
+
}
|
|
12
17
|
export declare class ContextApi {
|
|
13
18
|
private readonly project;
|
|
14
19
|
private readonly token;
|
|
15
20
|
private readonly base;
|
|
16
21
|
private readonly mcp;
|
|
17
22
|
private readonly wake;
|
|
18
|
-
|
|
23
|
+
private readonly heads;
|
|
24
|
+
private readonly server;
|
|
25
|
+
constructor(server: string, project: string, token: string, { heads, ...wake }?: ContextApiOptions);
|
|
19
26
|
/** Retries a request while the hosted service wakes; announces that once per client. */
|
|
20
27
|
private waking;
|
|
21
28
|
private request;
|
|
@@ -30,7 +37,23 @@ export declare class ContextApi {
|
|
|
30
37
|
all(filters: Record<string, string>): Promise<Result>;
|
|
31
38
|
submit(body: Contribution): Promise<Receipt>;
|
|
32
39
|
nodeEdges(id: string): Promise<Result["edges"]>;
|
|
33
|
-
|
|
40
|
+
/** Edges of a namespace: active ones, or with `since` every head written after that revision. */
|
|
41
|
+
allEdges(namespace: string, since?: number): Promise<{
|
|
42
|
+
edges: Result["edges"];
|
|
43
|
+
revision: number;
|
|
44
|
+
}>;
|
|
45
|
+
private headKey;
|
|
46
|
+
/** Active nodes of a namespace, refreshed from the head cache by revision when there is one. */
|
|
47
|
+
nodeHeads(namespace: string): Promise<{
|
|
48
|
+
rows: Result["nodes"];
|
|
49
|
+
steady: boolean;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Active edges of a namespace, refreshed from the head cache by revision when there is one.
|
|
53
|
+
* `fresh` reads them in full: a full read hides edges of inactive nodes, so once a node is
|
|
54
|
+
* revived its unchanged edges reappear without a newer revision for a delta to find.
|
|
55
|
+
*/
|
|
56
|
+
edgeHeads(namespace: string, fresh?: boolean): Promise<Result["edges"]>;
|
|
34
57
|
}
|
|
35
58
|
/**
|
|
36
59
|
* Each contribution is one SERIALIZABLE transaction with pairwise similarity() queries, so cost
|
|
@@ -47,7 +70,10 @@ export declare function submitBatch<T>(api: ContextApi, group: T[], make: (items
|
|
|
47
70
|
items: T[];
|
|
48
71
|
receipt: Receipt;
|
|
49
72
|
}[]>;
|
|
50
|
-
/**
|
|
73
|
+
/**
|
|
74
|
+
* The head cache is a mirror refreshed from the server by revision, and the server stays
|
|
75
|
+
* authoritative: a doubtful cache is dropped for a full read, never trusted.
|
|
76
|
+
*/
|
|
51
77
|
export declare function reconcile(api: ContextApi, snapshot: Snapshot, namespace: string, supersede?: boolean,
|
|
52
78
|
/** Nodes outside the snapshot (other namespaces) that edges may point to, by client key. */
|
|
53
79
|
anchors?: Map<string, string>): Promise<{
|
package/dist/api.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
2
|
import { WAKE_BUDGET_MS, retryWake } from "./wake.js";
|
|
3
|
+
import { readHeads } from "./cache.js";
|
|
3
4
|
export class GraphHttpError extends Error {
|
|
4
5
|
status;
|
|
5
6
|
constructor(status) {
|
|
@@ -23,9 +24,13 @@ export class ContextApi {
|
|
|
23
24
|
base;
|
|
24
25
|
mcp;
|
|
25
26
|
wake;
|
|
26
|
-
|
|
27
|
+
heads;
|
|
28
|
+
server;
|
|
29
|
+
constructor(server, project, token, { heads, ...wake } = {}) {
|
|
27
30
|
this.project = project;
|
|
28
31
|
this.token = token;
|
|
32
|
+
this.heads = heads;
|
|
33
|
+
this.server = server;
|
|
29
34
|
const url = new URL(server);
|
|
30
35
|
if (url.username ||
|
|
31
36
|
url.password ||
|
|
@@ -118,13 +123,14 @@ export class ContextApi {
|
|
|
118
123
|
const nodes = [];
|
|
119
124
|
const edges = new Map();
|
|
120
125
|
let cursor;
|
|
121
|
-
|
|
126
|
+
// Pages are separate snapshots: the oldest one is the revision the whole read is good for.
|
|
127
|
+
let revision = Number.POSITIVE_INFINITY;
|
|
122
128
|
const seen = new Set();
|
|
123
129
|
do {
|
|
124
130
|
const page = await this.query({ ...filters, limit: "300", ...(cursor ? { cursor } : {}) });
|
|
125
131
|
nodes.push(...page.nodes);
|
|
126
132
|
page.edges.forEach((e) => edges.set(e.id, e));
|
|
127
|
-
revision = page.revision;
|
|
133
|
+
revision = Math.min(revision, page.revision);
|
|
128
134
|
cursor = page.nextCursor;
|
|
129
135
|
if (page.truncated && !cursor)
|
|
130
136
|
throw new Error("Graph response truncated without continuation");
|
|
@@ -157,13 +163,21 @@ export class ContextApi {
|
|
|
157
163
|
} while (cursor);
|
|
158
164
|
return edges;
|
|
159
165
|
}
|
|
160
|
-
|
|
166
|
+
/** Edges of a namespace: active ones, or with `since` every head written after that revision. */
|
|
167
|
+
async allEdges(namespace, since) {
|
|
161
168
|
const edges = [];
|
|
162
169
|
let cursor;
|
|
170
|
+
let revision = Number.POSITIVE_INFINITY;
|
|
163
171
|
const seen = new Set();
|
|
164
172
|
do {
|
|
165
|
-
const page = await this.request(`/edges?${new URLSearchParams({
|
|
173
|
+
const page = await this.request(`/edges?${new URLSearchParams({
|
|
174
|
+
namespace,
|
|
175
|
+
limit: "300",
|
|
176
|
+
...(since === undefined ? {} : { include_inactive: "true", since: String(since) }),
|
|
177
|
+
...(cursor ? { cursor } : {}),
|
|
178
|
+
})}`);
|
|
166
179
|
edges.push(...page.edges);
|
|
180
|
+
revision = Math.min(revision, page.revision);
|
|
167
181
|
cursor = page.nextCursor;
|
|
168
182
|
if (page.truncated && !cursor)
|
|
169
183
|
throw new Error("Edge list truncated without continuation");
|
|
@@ -172,7 +186,31 @@ export class ContextApi {
|
|
|
172
186
|
if (cursor)
|
|
173
187
|
seen.add(cursor);
|
|
174
188
|
} while (cursor);
|
|
175
|
-
return edges;
|
|
189
|
+
return { edges, revision };
|
|
190
|
+
}
|
|
191
|
+
headKey(kind, namespace) {
|
|
192
|
+
return `${kind}|${this.server}|${this.project}|${namespace}`;
|
|
193
|
+
}
|
|
194
|
+
/** Active nodes of a namespace, refreshed from the head cache by revision when there is one. */
|
|
195
|
+
nodeHeads(namespace) {
|
|
196
|
+
return readHeads(this.heads, this.headKey("nodes", namespace), async (since) => {
|
|
197
|
+
const read = await this.all(since === undefined
|
|
198
|
+
? { namespace }
|
|
199
|
+
: { namespace, include_inactive: "true", since: String(since) });
|
|
200
|
+
return { rows: read.nodes, revision: read.revision };
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Active edges of a namespace, refreshed from the head cache by revision when there is one.
|
|
205
|
+
* `fresh` reads them in full: a full read hides edges of inactive nodes, so once a node is
|
|
206
|
+
* revived its unchanged edges reappear without a newer revision for a delta to find.
|
|
207
|
+
*/
|
|
208
|
+
async edgeHeads(namespace, fresh = false) {
|
|
209
|
+
const read = await readHeads(this.heads, this.headKey("edges", namespace), async (since) => {
|
|
210
|
+
const read = await this.allEdges(namespace, since);
|
|
211
|
+
return { rows: read.edges, revision: read.revision };
|
|
212
|
+
}, fresh);
|
|
213
|
+
return read.rows;
|
|
176
214
|
}
|
|
177
215
|
}
|
|
178
216
|
/**
|
|
@@ -254,13 +292,15 @@ function stable(value) {
|
|
|
254
292
|
: v;
|
|
255
293
|
return JSON.stringify(sort(value));
|
|
256
294
|
}
|
|
295
|
+
/** A commit-only change is not a content change (#145); the repository node keeps it for the lag brief. */
|
|
296
|
+
const withoutCommit = (locators) => locators.map((p) => ({ ...p, commit: undefined }));
|
|
257
297
|
const comparable = (n) => stable([
|
|
258
298
|
n.title,
|
|
259
299
|
n.body,
|
|
260
300
|
n.status ?? null,
|
|
261
301
|
n.properties,
|
|
262
302
|
n.derivation,
|
|
263
|
-
n.
|
|
303
|
+
n.type === "repository" ? n.provenance : withoutCommit(n.provenance),
|
|
264
304
|
]);
|
|
265
305
|
const edgeKey = (e) => stable([
|
|
266
306
|
e.type,
|
|
@@ -269,27 +309,43 @@ const edgeKey = (e) => stable([
|
|
|
269
309
|
e.properties.contextNamespace ?? null,
|
|
270
310
|
e.type === "amends" ? (e.properties.scope ?? null) : null,
|
|
271
311
|
]);
|
|
272
|
-
/**
|
|
312
|
+
/** Up to this many absent keys are looked up one by one; more use the project-wide types scan. */
|
|
313
|
+
const KEY_LOOKUP_MAX = 50;
|
|
314
|
+
/**
|
|
315
|
+
* The head cache is a mirror refreshed from the server by revision, and the server stays
|
|
316
|
+
* authoritative: a doubtful cache is dropped for a full read, never trusted.
|
|
317
|
+
*/
|
|
273
318
|
export async function reconcile(api, snapshot, namespace, supersede = true,
|
|
274
319
|
/** Nodes outside the snapshot (other namespaces) that edges may point to, by client key. */
|
|
275
320
|
anchors = new Map()) {
|
|
276
|
-
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
//
|
|
280
|
-
//
|
|
321
|
+
// Active heads only: history is not re-downloaded on every sync (#145).
|
|
322
|
+
const { rows: existing, steady } = await api.nodeHeads(namespace);
|
|
323
|
+
const byKey = new Map(existing.map((n) => [n.clientKey, n]));
|
|
324
|
+
// Absent keys are new, superseded/withdrawn in this namespace (revived below), or legacy nodes
|
|
325
|
+
// outside the namespace with the same client key. A few are looked up by key; many use one
|
|
326
|
+
// project-wide scan of the snapshot's node types, so a first sync costs pages, not N requests.
|
|
281
327
|
const absent = new Set(snapshot.nodes.filter((n) => !byKey.has(n.clientKey)).map((n) => n.clientKey));
|
|
282
328
|
if (absent.size) {
|
|
283
|
-
const
|
|
284
|
-
const
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
329
|
+
const candidates = new Map();
|
|
330
|
+
const offer = (n) => {
|
|
331
|
+
if (absent.has(n.clientKey))
|
|
332
|
+
candidates.set(n.clientKey, [...(candidates.get(n.clientKey) ?? []), n]);
|
|
333
|
+
};
|
|
334
|
+
if (absent.size <= KEY_LOOKUP_MAX)
|
|
335
|
+
for (const client_key of absent)
|
|
336
|
+
(await api.all({ client_key, include_inactive: "true" })).nodes.forEach(offer);
|
|
337
|
+
else {
|
|
338
|
+
const types = [...new Set(snapshot.nodes.map((n) => n.type))].join(",");
|
|
339
|
+
(await api.all({ types, include_inactive: "true" })).nodes.forEach(offer);
|
|
340
|
+
}
|
|
341
|
+
for (const [key, list] of candidates) {
|
|
342
|
+
const inside = list.filter((n) => n.namespace === namespace);
|
|
343
|
+
const pool = inside.length ? inside : list;
|
|
344
|
+
const [only] = pool;
|
|
345
|
+
if (pool.length > 1 || !only)
|
|
346
|
+
throw new Error(`Ambiguous client key ${key}`);
|
|
347
|
+
byKey.set(key, only);
|
|
348
|
+
}
|
|
293
349
|
}
|
|
294
350
|
const ids = new Map([...anchors, ...[...byKey].map(([key, n]) => [key, n.id])]);
|
|
295
351
|
const desired = new Set(snapshot.nodes.map((n) => n.clientKey));
|
|
@@ -311,7 +367,7 @@ anchors = new Map()) {
|
|
|
311
367
|
});
|
|
312
368
|
}
|
|
313
369
|
if (supersede)
|
|
314
|
-
for (const old of existing
|
|
370
|
+
for (const old of existing)
|
|
315
371
|
if (!desired.has(old.clientKey) && old.lifecycle === "active")
|
|
316
372
|
revisions.push({
|
|
317
373
|
nodeId: old.id,
|
|
@@ -347,7 +403,10 @@ anchors = new Map()) {
|
|
|
347
403
|
for (const batch of chunks(revisions, (revisions) => ({ ...empty(), revisions })))
|
|
348
404
|
contributions += (await submitBatch(api, batch, (revisions) => ({ ...empty(), revisions })))
|
|
349
405
|
.length;
|
|
350
|
-
|
|
406
|
+
// A revived node (here or elsewhere) can bring back edges no delta reports: read them in full.
|
|
407
|
+
const revived = !steady ||
|
|
408
|
+
snapshot.nodes.some((n) => (byKey.get(n.clientKey)?.lifecycle ?? "active") !== "active");
|
|
409
|
+
const currentEdges = new Map((await api.edgeHeads(namespace, revived)).map((e) => [e.id, e]));
|
|
351
410
|
const desiredEdges = snapshot.edges.map((e) => {
|
|
352
411
|
const from = ids.get(e.from), to = ids.get(e.to);
|
|
353
412
|
if (!from || !to)
|
|
@@ -404,8 +463,8 @@ anchors = new Map()) {
|
|
|
404
463
|
for (const edge of edges) {
|
|
405
464
|
const old = activeByKey.get(edgeKey(edge));
|
|
406
465
|
if (old &&
|
|
407
|
-
stable([old.provenance, old.derivation, old.properties]) !==
|
|
408
|
-
stable([edge.provenance, edge.derivation, edge.properties]))
|
|
466
|
+
stable([withoutCommit(old.provenance), old.derivation, old.properties]) !==
|
|
467
|
+
stable([withoutCommit(edge.provenance), edge.derivation, edge.properties]))
|
|
409
468
|
updated.push({
|
|
410
469
|
edgeId: old.id,
|
|
411
470
|
expectedRevision: old.revision,
|
package/dist/cache.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Key-value store for the heads read at the previous sync (#145). */
|
|
2
|
+
export interface HeadStore {
|
|
3
|
+
get(key: string): string | undefined;
|
|
4
|
+
set(key: string, value: string): void;
|
|
5
|
+
}
|
|
6
|
+
/** One file per key under the user cache directory; a missing or unreadable file is a cache miss. */
|
|
7
|
+
export declare function fileHeadStore(dir?: string): HeadStore;
|
|
8
|
+
interface Head {
|
|
9
|
+
id: string;
|
|
10
|
+
revision: number;
|
|
11
|
+
lifecycle: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Active heads for `key`. The stored copy is a mirror refreshed from the server by revision: only
|
|
15
|
+
* rows written after the stored revision are fetched and merged (higher row revision wins).
|
|
16
|
+
* Anything doubtful - no or invalid entry, a server that rejects `since`, a server revision
|
|
17
|
+
* behind the stored one, or `fresh` - reads everything again.
|
|
18
|
+
* `steady` is true only for a delta read that brought back no row: every active row it added is
|
|
19
|
+
* new at revision 1. Callers use it to tell when visibility that depends on these rows changed.
|
|
20
|
+
*/
|
|
21
|
+
export declare function readHeads<T extends Head>(store: HeadStore | undefined, key: string, fetch: (since?: number) => Promise<{
|
|
22
|
+
rows: T[];
|
|
23
|
+
revision: number;
|
|
24
|
+
}>, fresh?: boolean): Promise<{
|
|
25
|
+
rows: T[];
|
|
26
|
+
steady: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
export {};
|
package/dist/cache.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
2
|
+
import { mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { homedir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
/** One file per key under the user cache directory; a missing or unreadable file is a cache miss. */
|
|
6
|
+
export function fileHeadStore(dir = join(process.env.XDG_CACHE_HOME || process.env.LOCALAPPDATA || join(homedir(), ".cache"), "cboard", "sync")) {
|
|
7
|
+
const file = (key) => join(dir, `${createHash("sha256").update(key).digest("hex")}.json`);
|
|
8
|
+
return {
|
|
9
|
+
get(key) {
|
|
10
|
+
try {
|
|
11
|
+
return readFileSync(file(key), "utf8");
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
set(key, value) {
|
|
18
|
+
mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
19
|
+
const target = file(key);
|
|
20
|
+
const tmp = `${target}.${randomUUID()}.tmp`;
|
|
21
|
+
try {
|
|
22
|
+
writeFileSync(tmp, value, { mode: 0o600 });
|
|
23
|
+
renameSync(tmp, target);
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
rmSync(tmp, { force: true });
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function parse(raw) {
|
|
33
|
+
if (raw === undefined)
|
|
34
|
+
return undefined;
|
|
35
|
+
try {
|
|
36
|
+
const value = JSON.parse(raw);
|
|
37
|
+
if (value?.v === 1 &&
|
|
38
|
+
typeof value.revision === "number" &&
|
|
39
|
+
Number.isInteger(value.revision) &&
|
|
40
|
+
value.revision >= 0 &&
|
|
41
|
+
Array.isArray(value.rows) &&
|
|
42
|
+
value.rows.every((r) => !!r &&
|
|
43
|
+
typeof r === "object" &&
|
|
44
|
+
typeof r.id === "string" &&
|
|
45
|
+
Number.isInteger(r.revision) &&
|
|
46
|
+
typeof r.lifecycle === "string"))
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
/* unparseable: read in full */
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
/** A 400 is how a server without `since` support answers (duck-typed: api.ts imports this module). */
|
|
55
|
+
const rejectsSince = (error) => error instanceof Error && error.status === 400;
|
|
56
|
+
/**
|
|
57
|
+
* Active heads for `key`. The stored copy is a mirror refreshed from the server by revision: only
|
|
58
|
+
* rows written after the stored revision are fetched and merged (higher row revision wins).
|
|
59
|
+
* Anything doubtful - no or invalid entry, a server that rejects `since`, a server revision
|
|
60
|
+
* behind the stored one, or `fresh` - reads everything again.
|
|
61
|
+
* `steady` is true only for a delta read that brought back no row: every active row it added is
|
|
62
|
+
* new at revision 1. Callers use it to tell when visibility that depends on these rows changed.
|
|
63
|
+
*/
|
|
64
|
+
export async function readHeads(store, key, fetch, fresh = false) {
|
|
65
|
+
const cached = fresh ? undefined : parse(store?.get(key));
|
|
66
|
+
let result;
|
|
67
|
+
let merged = new Map();
|
|
68
|
+
if (cached) {
|
|
69
|
+
try {
|
|
70
|
+
const delta = await fetch(cached.revision);
|
|
71
|
+
if (delta.revision >= cached.revision) {
|
|
72
|
+
result = delta;
|
|
73
|
+
merged = new Map(cached.rows.map((r) => [r.id, r]));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (!rejectsSince(error))
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
let steady = !!result;
|
|
82
|
+
result ??= await fetch();
|
|
83
|
+
for (const row of result.rows) {
|
|
84
|
+
const old = merged.get(row.id);
|
|
85
|
+
if (old && row.revision < old.revision)
|
|
86
|
+
continue;
|
|
87
|
+
// Active, unknown and past revision 1: revived (or never cached), so dependent reads may lag.
|
|
88
|
+
if (row.lifecycle === "active" && !old && row.revision > 1)
|
|
89
|
+
steady = false;
|
|
90
|
+
merged.set(row.id, row);
|
|
91
|
+
}
|
|
92
|
+
const rows = [...merged.values()].filter((r) => r.lifecycle === "active");
|
|
93
|
+
const entry = { v: 1, revision: result.revision, rows };
|
|
94
|
+
try {
|
|
95
|
+
store?.set(key, JSON.stringify(entry));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
/* an unwritable cache only costs a full read next time */
|
|
99
|
+
}
|
|
100
|
+
return { rows, steady };
|
|
101
|
+
}
|
package/dist/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { mkdir, writeFile, rename } from "node:fs/promises";
|
|
|
5
5
|
import { dirname, isAbsolute, posix, relative, resolve, sep, win32 } from "node:path";
|
|
6
6
|
import { pathToFileURL } from "node:url";
|
|
7
7
|
import { ContextApi, reconcile } from "./api.js";
|
|
8
|
+
import { fileHeadStore } from "./cache.js";
|
|
8
9
|
import { codeConfig, extract } from "./extract.js";
|
|
9
10
|
export function options(argv) {
|
|
10
11
|
const result = {};
|
|
@@ -136,7 +137,7 @@ export async function sync(argv) {
|
|
|
136
137
|
const args = options(argv);
|
|
137
138
|
const root = resolve(args.repo ?? process.cwd());
|
|
138
139
|
const { project, token, server } = resolveSync(args, root);
|
|
139
|
-
const api = new ContextApi(server, project, token);
|
|
140
|
+
const api = new ContextApi(server, project, token, { heads: fileHeadStore() });
|
|
140
141
|
const snapshot = await extract(root, [], codeConfig(root));
|
|
141
142
|
const result = await reconcile(api, snapshot, snapshot.namespace);
|
|
142
143
|
const state = args.state
|
package/dist/docs.js
CHANGED
|
@@ -2,6 +2,7 @@ import { execFileSync } from "node:child_process";
|
|
|
2
2
|
import { readFileSync } from "node:fs";
|
|
3
3
|
import { posix, resolve } from "node:path";
|
|
4
4
|
import { ContextApi, reconcile } from "./api.js";
|
|
5
|
+
import { fileHeadStore } from "./cache.js";
|
|
5
6
|
import { options, resolveSync } from "./cli.js";
|
|
6
7
|
import { repository } from "./extract.js";
|
|
7
8
|
import { globMatcher } from "./languages.js";
|
|
@@ -232,7 +233,7 @@ export async function docsSync(argv) {
|
|
|
232
233
|
const root = resolve(args.repo ?? process.cwd());
|
|
233
234
|
const { project, token, server } = resolveSync(args, root);
|
|
234
235
|
const snapshot = extractDocs(root, docsConfig(root));
|
|
235
|
-
const result = await reconcile(new ContextApi(server, project, token), snapshot, snapshot.namespace);
|
|
236
|
+
const result = await reconcile(new ContextApi(server, project, token, { heads: fileHeadStore() }), snapshot, snapshot.namespace);
|
|
236
237
|
console.log(JSON.stringify({
|
|
237
238
|
commit: snapshot.commit,
|
|
238
239
|
nodes: snapshot.nodes.length,
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/issues.js
CHANGED
|
@@ -3,6 +3,7 @@ import { createHash } from "node:crypto";
|
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
5
|
import { ContextApi, reconcile } from "./api.js";
|
|
6
|
+
import { fileHeadStore } from "./cache.js";
|
|
6
7
|
import { resolveSync } from "./cli.js";
|
|
7
8
|
import { repository } from "./extract.js";
|
|
8
9
|
const run = promisify(execFile);
|
|
@@ -133,6 +134,6 @@ export async function issuesSync(argv, source = githubSource) {
|
|
|
133
134
|
const args = issuesSyncOptions(argv);
|
|
134
135
|
const root = resolve(args.repo ?? process.cwd());
|
|
135
136
|
const { project, token, server } = resolveSync(args, root);
|
|
136
|
-
const result = await runIssuesSync(new ContextApi(server, project, token), repository(root), source, { state: args.state, limit: args.limit });
|
|
137
|
+
const result = await runIssuesSync(new ContextApi(server, project, token, { heads: fileHeadStore() }), repository(root), source, { state: args.state, limit: args.limit });
|
|
137
138
|
console.log(JSON.stringify(result));
|
|
138
139
|
}
|
package/kit/cboard-connect.js
CHANGED
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
// `.claude/settings.json`, adds a marked block to AGENTS.md, installs the `cboard-graph` Claude Code
|
|
10
10
|
// skill (`.claude/skills/cboard-graph/SKILL.md`), keeps the token file out of Git, and keeps the
|
|
11
11
|
// generated files on LF line endings with a marked block in `.gitattributes`.
|
|
12
|
-
// Without a usable token
|
|
13
|
-
//
|
|
12
|
+
// Without a usable token, omit --project to log in in the browser (device flow; the project is
|
|
13
|
+
// chosen there), or pass --no-login to write configuration only. It never prints a token.
|
|
14
|
+
// Rerunning with the same arguments changes nothing.
|
|
14
15
|
//
|
|
15
16
|
// Merge policy for an existing `mcpServers.cboard` entry in `.mcp.json`: other servers, other keys
|
|
16
17
|
// and key order are untouched. Extra keys a user added to the cboard entry are kept. `type` is set
|
|
@@ -569,8 +570,8 @@ export function connect(options = {}) {
|
|
|
569
570
|
if (options.codex) {
|
|
570
571
|
lines.push(
|
|
571
572
|
"",
|
|
572
|
-
"Codex (~/.codex/config.toml;
|
|
573
|
-
"
|
|
573
|
+
"Codex (~/.codex/config.toml; load the repository token into the environment before starting Codex,",
|
|
574
|
+
"using the bearer_token_env_var below):",
|
|
574
575
|
" [mcp_servers.cboard]",
|
|
575
576
|
` url = "${server}/mcp"`,
|
|
576
577
|
` bearer_token_env_var = "${config.tokenEnv}"`,
|
|
@@ -586,24 +587,24 @@ export function connect(options = {}) {
|
|
|
586
587
|
};
|
|
587
588
|
}
|
|
588
589
|
|
|
589
|
-
/**
|
|
590
|
-
async function tokenUsable({ repo, env, server, tokenRel, fetchImpl }) {
|
|
590
|
+
/** Distinguishes missing and rejected tokens; a network failure is not a rejection. */
|
|
591
|
+
async function tokenUsable({ repo, env, server, tokenRel, project, fetchImpl }) {
|
|
591
592
|
let config;
|
|
592
593
|
try {
|
|
593
594
|
// CBOARD_GRAPH_URL stands in for the target server; the trust check below replaces resolveConfig's.
|
|
594
595
|
config = resolveConfig({ ...env, CBOARD_GRAPH_URL: server }, repo);
|
|
595
596
|
} catch {
|
|
596
|
-
return
|
|
597
|
+
return "usable"; // connect() reports the configuration problem as it always did.
|
|
597
598
|
}
|
|
598
599
|
const token =
|
|
599
600
|
readToken(config, env) || readToken({ ...config, tokenFile: join(repo, tokenRel) }, env);
|
|
600
|
-
if (!token) return
|
|
601
|
+
if (!token) return "missing";
|
|
601
602
|
// Never send a token to a server the user has not trusted; assume it works.
|
|
602
603
|
if (config.hosted && !isTrustedServer(server, { ...env, CBOARD_GRAPH_URL: undefined })) {
|
|
603
|
-
return
|
|
604
|
+
return "usable";
|
|
604
605
|
}
|
|
605
606
|
try {
|
|
606
|
-
await retryWake(
|
|
607
|
+
const listed = await retryWake(
|
|
607
608
|
(attemptMs) =>
|
|
608
609
|
mcpCall({
|
|
609
610
|
api: config.api,
|
|
@@ -614,14 +615,22 @@ async function tokenUsable({ repo, env, server, tokenRel, fetchImpl }) {
|
|
|
614
615
|
}),
|
|
615
616
|
{ budgetMs: config.hosted ? 60_000 : 0 },
|
|
616
617
|
);
|
|
618
|
+
if (
|
|
619
|
+
project &&
|
|
620
|
+
UUID.test(project) &&
|
|
621
|
+
Array.isArray(listed?.data) &&
|
|
622
|
+
!listed.data.some((entry) => entry?.id === project.toLowerCase())
|
|
623
|
+
) {
|
|
624
|
+
return "wrong_project";
|
|
625
|
+
}
|
|
617
626
|
} catch (error) {
|
|
618
|
-
return
|
|
627
|
+
return error instanceof McpError && error.kind === "unauthorized" ? "rejected" : "usable";
|
|
619
628
|
}
|
|
620
|
-
return
|
|
629
|
+
return "usable";
|
|
621
630
|
}
|
|
622
631
|
|
|
623
632
|
/**
|
|
624
|
-
* `connect`, preceded by the browser (device) login when
|
|
633
|
+
* `connect`, preceded by the browser (device) login when there is no usable token and no --project.
|
|
625
634
|
* The token is written to the repository's token file before `connect` runs, so `connect` keeps it
|
|
626
635
|
* out of Git. `login` injects the network, browser and clock for tests.
|
|
627
636
|
* `noLogin` skips the token check and the login (the pre-login behaviour).
|
|
@@ -655,9 +664,27 @@ export async function connectWithLogin(options = {}) {
|
|
|
655
664
|
} catch (error) {
|
|
656
665
|
throw new ConnectError(error instanceof Error ? error.message : String(error));
|
|
657
666
|
}
|
|
658
|
-
|
|
667
|
+
const tokenStatus = await tokenUsable({
|
|
668
|
+
repo,
|
|
669
|
+
env,
|
|
670
|
+
server,
|
|
671
|
+
tokenRel,
|
|
672
|
+
project: options.project,
|
|
673
|
+
fetchImpl: login.fetchImpl,
|
|
674
|
+
});
|
|
675
|
+
if (tokenStatus === "usable") {
|
|
659
676
|
return connect(rest);
|
|
660
677
|
}
|
|
678
|
+
if (options.project) {
|
|
679
|
+
const reason = {
|
|
680
|
+
missing: "is missing",
|
|
681
|
+
rejected: "was rejected by the server",
|
|
682
|
+
wrong_project: `does not have access to project ${options.project}`,
|
|
683
|
+
}[tokenStatus];
|
|
684
|
+
throw new ConnectError(
|
|
685
|
+
`--project needs a usable token: token ${reason} (${tokenRel.replaceAll("\\", "/")} or $CBOARD_PAT); rerun without --project to log in in the browser, or pass --no-login to write the configuration only`,
|
|
686
|
+
);
|
|
687
|
+
}
|
|
661
688
|
const interactive = login.interactive ?? (Boolean(process.stdout.isTTY) && !env.CI);
|
|
662
689
|
const granted = await deviceLogin({
|
|
663
690
|
server,
|
|
@@ -679,11 +706,6 @@ export async function connectWithLogin(options = {}) {
|
|
|
679
706
|
rmSync(tokenFile, { force: true });
|
|
680
707
|
throw error;
|
|
681
708
|
}
|
|
682
|
-
if (options.project && options.project !== granted.projectId) {
|
|
683
|
-
result.warnings.push(
|
|
684
|
-
`you approved project ${granted.projectId} in the browser, not the --project ${options.project} you passed`,
|
|
685
|
-
);
|
|
686
|
-
}
|
|
687
709
|
return {
|
|
688
710
|
...result,
|
|
689
711
|
lines: [
|
|
@@ -66,7 +66,7 @@ async function checkMain(config, env, { fetchImpl, timeoutMs, wake }) {
|
|
|
66
66
|
if (config.projectId && !projects.some((p) => p.id === config.projectId)) {
|
|
67
67
|
return {
|
|
68
68
|
code: 1,
|
|
69
|
-
message: `connected to ${config.api}, but project ${config.projectId} is not visible to this token; ${tokenFix(config)}`,
|
|
69
|
+
message: `connected to ${config.api}, but project ${config.projectId} is not visible to this token: project not found or deleted; ${tokenFix(config)}`,
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
// Optional: an older server lacks whoami; any failure keeps the plain message. One short try only.
|
|
@@ -80,9 +80,12 @@ async function checkMain(config, env, { fetchImpl, timeoutMs, wake }) {
|
|
|
80
80
|
}),
|
|
81
81
|
);
|
|
82
82
|
const info = me ? describeWhoami(me) : null;
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
const archived = projects.some((p) => p.id === config.projectId && p.archived === true);
|
|
84
|
+
const head = archived
|
|
85
|
+
? "CONNECTED (archived, read-only)"
|
|
86
|
+
: info?.readOnly
|
|
87
|
+
? "CONNECTED (read-only): you can query, not contribute"
|
|
88
|
+
: "CONNECTED";
|
|
86
89
|
const tail = info?.warning ? `; ${info.warning}` : "";
|
|
87
90
|
return { code: 0, message: `${head} (${config.api}/mcp)${tail}` };
|
|
88
91
|
}
|