@codyn06/cboard 0.1.0 → 0.3.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 +5 -2
- package/dist/api.d.ts +36 -4
- package/dist/api.js +128 -51
- package/dist/cache.d.ts +28 -0
- package/dist/cache.js +101 -0
- package/dist/cboard.js +57 -3
- package/dist/cli.js +2 -1
- package/dist/docs.d.ts +39 -0
- package/dist/docs.js +244 -0
- package/dist/extract.js +23 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/issues.d.ts +44 -0
- package/dist/issues.js +139 -0
- package/dist/wake.d.ts +13 -0
- package/dist/wake.js +33 -0
- package/kit/cboard-connect.js +425 -46
- package/kit/cboard-kit/brief.js +144 -18
- package/kit/cboard-kit/config.js +38 -3
- package/kit/cboard-kit/connect-check.js +56 -13
- package/kit/cboard-kit/device.js +192 -0
- package/kit/cboard-kit/drift.js +55 -0
- package/kit/cboard-kit/headers.js +24 -3
- package/kit/cboard-kit/mcp.js +38 -3
- package/kit/cboard-kit/references.js +70 -0
- package/kit/cboard-kit/skill/SKILL.md +16 -0
- package/kit/cboard-kit/wait.js +45 -0
- package/package.json +1 -1
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/* global AbortSignal, fetch */
|
|
2
|
+
// Compares the kit version with the npm `latest` of @codyn06/cboard. Cached once a day in the
|
|
3
|
+
// kit directory; silent (returns undefined) on any failure.
|
|
4
|
+
import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
|
|
7
|
+
export const REGISTRY_URL = "https://registry.npmjs.org/@codyn06%2fcboard/latest";
|
|
8
|
+
export const CACHE_FILE = "latest-version.json";
|
|
9
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
10
|
+
const FETCH_TIMEOUT_MS = 1500;
|
|
11
|
+
|
|
12
|
+
const parse = (v) => (/^\d+\.\d+\.\d+/.exec(String(v))?.[0] ?? "").split(".").map(Number);
|
|
13
|
+
|
|
14
|
+
/** True when version `a` is older than `b` (plain major.minor.patch comparison). */
|
|
15
|
+
export function isOlder(a, b) {
|
|
16
|
+
const x = parse(a);
|
|
17
|
+
const y = parse(b);
|
|
18
|
+
if (x.length !== 3 || y.length !== 3) return false;
|
|
19
|
+
for (let i = 0; i < 3; i++) if (x[i] !== y[i]) return x[i] < y[i];
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** The npm latest version, from today's cache or the registry; undefined on any failure. */
|
|
24
|
+
export async function latestVersion({ dir, fetchImpl = fetch, now = Date.now() }) {
|
|
25
|
+
const file = join(dir, CACHE_FILE);
|
|
26
|
+
try {
|
|
27
|
+
const cached = JSON.parse(readFileSync(file, "utf8"));
|
|
28
|
+
if (typeof cached.version === "string" && now - cached.checkedAt < DAY_MS)
|
|
29
|
+
return cached.version;
|
|
30
|
+
} catch {
|
|
31
|
+
// No usable cache: ask the registry.
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
const res = await fetchImpl(REGISTRY_URL, { signal: AbortSignal.timeout(FETCH_TIMEOUT_MS) });
|
|
35
|
+
if (!res.ok) return undefined;
|
|
36
|
+
const version = (await res.json()).version;
|
|
37
|
+
if (typeof version !== "string") return undefined;
|
|
38
|
+
try {
|
|
39
|
+
mkdirSync(dir, { recursive: true });
|
|
40
|
+
writeFileSync(file, JSON.stringify({ version, checkedAt: now }));
|
|
41
|
+
} catch {
|
|
42
|
+
// Read-only kit directory: just no cache.
|
|
43
|
+
}
|
|
44
|
+
return version;
|
|
45
|
+
} catch {
|
|
46
|
+
return undefined;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** One line when the kit is older than npm latest; empty otherwise. */
|
|
51
|
+
export function driftLine(kit, latest) {
|
|
52
|
+
return kit && latest && isOlder(kit, latest)
|
|
53
|
+
? `cboard kit ${kit} is behind npm latest ${latest}: run \`npx @codyn06/cboard@latest connect\` to update.`
|
|
54
|
+
: "";
|
|
55
|
+
}
|
|
@@ -2,12 +2,33 @@
|
|
|
2
2
|
// Claude Code `headersHelper` for the cboard MCP server (.mcp.json): prints the auth header JSON.
|
|
3
3
|
// Makes no network call (Claude Code waits on this helper and the hosted service may be asleep).
|
|
4
4
|
// Exits 1 with a fix hint on stderr when there is no token.
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
ConfigError,
|
|
7
|
+
isMain,
|
|
8
|
+
locateRoot,
|
|
9
|
+
readReferenceToken,
|
|
10
|
+
readToken,
|
|
11
|
+
resolveConfig,
|
|
12
|
+
tokenFix,
|
|
13
|
+
} from "./config.js";
|
|
6
14
|
|
|
7
15
|
/** @returns {{ code: number, stdout?: string, stderr?: string }} */
|
|
8
|
-
export function headersResult(env, cwd, importMetaUrl) {
|
|
16
|
+
export function headersResult(env, cwd, importMetaUrl, referenceName) {
|
|
9
17
|
try {
|
|
10
18
|
const config = resolveConfig(env, locateRoot(cwd, importMetaUrl), { required: true });
|
|
19
|
+
if (referenceName) {
|
|
20
|
+
// A reference sends its own token only; it never falls back to the main token or $CBOARD_PAT.
|
|
21
|
+
const reference = config.references.find((r) => r.name === referenceName);
|
|
22
|
+
if (!reference) return { code: 1, stderr: `cboard: no reference named ${referenceName}` };
|
|
23
|
+
const refToken = readReferenceToken(reference);
|
|
24
|
+
if (!refToken) {
|
|
25
|
+
return {
|
|
26
|
+
code: 1,
|
|
27
|
+
stderr: `cboard: no token for reference ${referenceName}; save a graph:read token to ${reference.tokenFileRel}`,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return { code: 0, stdout: JSON.stringify({ Authorization: `Bearer ${refToken}` }) };
|
|
31
|
+
}
|
|
11
32
|
const token = readToken(config, env);
|
|
12
33
|
if (!token) return { code: 1, stderr: `cboard: no token; ${tokenFix(config)}` };
|
|
13
34
|
return { code: 0, stdout: JSON.stringify({ Authorization: `Bearer ${token}` }) };
|
|
@@ -18,7 +39,7 @@ export function headersResult(env, cwd, importMetaUrl) {
|
|
|
18
39
|
}
|
|
19
40
|
|
|
20
41
|
if (isMain(import.meta.url)) {
|
|
21
|
-
const result = headersResult(process.env, process.cwd(), import.meta.url);
|
|
42
|
+
const result = headersResult(process.env, process.cwd(), import.meta.url, process.argv[2]);
|
|
22
43
|
if (result.stdout) console.log(result.stdout);
|
|
23
44
|
if (result.stderr) console.error(result.stderr);
|
|
24
45
|
process.exitCode = result.code;
|
package/kit/cboard-kit/mcp.js
CHANGED
|
@@ -3,11 +3,16 @@
|
|
|
3
3
|
// Never logs the token or response content.
|
|
4
4
|
|
|
5
5
|
export class McpError extends Error {
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* @param {"unauthorized" | "error"} kind
|
|
8
|
+
* @param {string} message
|
|
9
|
+
* @param {boolean} [transient] network failure, timeout or 5xx: worth retrying (cold start)
|
|
10
|
+
*/
|
|
11
|
+
constructor(kind, message, transient = false) {
|
|
8
12
|
super(message);
|
|
9
13
|
this.name = "McpError";
|
|
10
14
|
this.kind = kind;
|
|
15
|
+
this.transient = transient;
|
|
11
16
|
}
|
|
12
17
|
}
|
|
13
18
|
|
|
@@ -39,10 +44,11 @@ export async function mcpCall({
|
|
|
39
44
|
}),
|
|
40
45
|
});
|
|
41
46
|
} catch {
|
|
42
|
-
throw new McpError("error", `${name}: request failed
|
|
47
|
+
throw new McpError("error", `${name}: request failed`, true);
|
|
43
48
|
}
|
|
44
49
|
if (res.status === 401 || res.status === 403)
|
|
45
50
|
throw new McpError("unauthorized", `${name}: ${res.status}`);
|
|
51
|
+
if (res.status >= 500) throw new McpError("error", `${name}: ${res.status}`, true);
|
|
46
52
|
let body;
|
|
47
53
|
try {
|
|
48
54
|
body = await res.json();
|
|
@@ -60,3 +66,32 @@ export async function mcpCall({
|
|
|
60
66
|
throw new McpError("error", `${name}: tool output is not JSON`);
|
|
61
67
|
}
|
|
62
68
|
}
|
|
69
|
+
|
|
70
|
+
export const RENEW_COMMAND = "npx @codyn06/cboard@latest connect";
|
|
71
|
+
const NEAR_EXPIRY_DAYS = 14;
|
|
72
|
+
|
|
73
|
+
/** The token's own view of itself (`whoami`); null on an older server, a network error or junk. */
|
|
74
|
+
export async function fetchWhoami(call) {
|
|
75
|
+
try {
|
|
76
|
+
const raw = await call();
|
|
77
|
+
const me = raw?.data ?? raw;
|
|
78
|
+
return Array.isArray(me?.scopes) && typeof me.readOnly === "boolean" ? me : null;
|
|
79
|
+
} catch {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Short facts about a whoami result: scopes, expiry date, read-only flag, expiry warning. */
|
|
85
|
+
export function describeWhoami(me) {
|
|
86
|
+
const days = Number.isFinite(me.daysRemaining) ? me.daysRemaining : null;
|
|
87
|
+
const date = typeof me.expiresAt === "string" ? me.expiresAt.slice(0, 10) : "";
|
|
88
|
+
return {
|
|
89
|
+
readOnly: me.readOnly,
|
|
90
|
+
scopes: me.scopes.join(", "),
|
|
91
|
+
expires: date ? `${date}${days === null ? "" : `, ${String(days)} days left`}` : "",
|
|
92
|
+
warning:
|
|
93
|
+
days !== null && days <= NEAR_EXPIRY_DAYS
|
|
94
|
+
? `token expires in ${String(days)} day(s); renew: ${RENEW_COMMAND}`
|
|
95
|
+
: "",
|
|
96
|
+
};
|
|
97
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Tests one reference project (a project of another cboard project read through its own token).
|
|
2
|
+
// Used by the connection check and the session brief; never throws and never prints the token.
|
|
3
|
+
import { describeWhoami, fetchWhoami, mcpCall } from "./mcp.js";
|
|
4
|
+
import { readReferenceToken } from "./config.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @returns {Promise<{ name: string, ok: boolean, title?: string, readOnly?: boolean, message: string }>}
|
|
8
|
+
* `readOnly` is known only when the server answers `whoami`; a write-capable token makes `ok` true
|
|
9
|
+
* with a warning in `message` (the reference still works, it should just not be able to write).
|
|
10
|
+
*/
|
|
11
|
+
export async function checkReference(config, reference, { fetchImpl, timeoutMs = 5000 } = {}) {
|
|
12
|
+
const { name, projectId } = reference;
|
|
13
|
+
const token = readReferenceToken(reference);
|
|
14
|
+
if (!token) {
|
|
15
|
+
return {
|
|
16
|
+
name,
|
|
17
|
+
ok: false,
|
|
18
|
+
message: `reference ${name}: token missing; create a graph:read token for project ${projectId} and save it to ${reference.tokenFileRel}`,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const call = (tool) =>
|
|
22
|
+
mcpCall({
|
|
23
|
+
api: config.api,
|
|
24
|
+
token,
|
|
25
|
+
name: tool,
|
|
26
|
+
timeoutMs,
|
|
27
|
+
...(fetchImpl ? { fetchImpl } : {}),
|
|
28
|
+
});
|
|
29
|
+
let projects;
|
|
30
|
+
try {
|
|
31
|
+
const listed = await call("list_projects");
|
|
32
|
+
projects = Array.isArray(listed?.data) ? listed.data : [];
|
|
33
|
+
} catch (error) {
|
|
34
|
+
const rejected = error?.kind === "unauthorized";
|
|
35
|
+
return {
|
|
36
|
+
name,
|
|
37
|
+
ok: false,
|
|
38
|
+
message: rejected
|
|
39
|
+
? `reference ${name}: token rejected; create a new graph:read token for project ${projectId} and save it to ${reference.tokenFileRel}`
|
|
40
|
+
: `reference ${name}: graph unreachable (${config.api}); retry later`,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const project = projects.find((p) => p.id === projectId);
|
|
44
|
+
if (!project) {
|
|
45
|
+
return {
|
|
46
|
+
name,
|
|
47
|
+
ok: false,
|
|
48
|
+
message: `reference ${name}: project ${projectId} is not visible to this token: the project owner must add you as a member`,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const me = await fetchWhoami(() => call("whoami"));
|
|
52
|
+
const info = me ? describeWhoami(me) : null;
|
|
53
|
+
const title = String(project.title);
|
|
54
|
+
if (info && !info.readOnly) {
|
|
55
|
+
return {
|
|
56
|
+
name,
|
|
57
|
+
ok: true,
|
|
58
|
+
title,
|
|
59
|
+
readOnly: false,
|
|
60
|
+
message: `reference ${name} ("${title}"): this token can write; use a graph:read token so the reference stays read-only`,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
name,
|
|
65
|
+
ok: true,
|
|
66
|
+
title,
|
|
67
|
+
...(info ? { readOnly: true } : {}),
|
|
68
|
+
message: `reference ${name} ("${title}"): ${info ? "read-only" : "reachable (write access not checked: older server)"}`,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -130,6 +130,13 @@ Read the current status node (`query_graph` with `types: ["status_update"]`) for
|
|
|
130
130
|
}
|
|
131
131
|
```
|
|
132
132
|
|
|
133
|
+
### Starting an empty project
|
|
134
|
+
|
|
135
|
+
The first node needs something to link to. `npx @codyn06/cboard connect --goal "<one line>"` creates the
|
|
136
|
+
project's goal, one `requirement` node whose id is `goalNodeId` in `.cboard.json` (the session brief
|
|
137
|
+
names it). Link the first decisions to it with `answers`, then create the first `status_update`. With
|
|
138
|
+
no goal, ask the owner for one line first. Rerunning with a different text revises the node.
|
|
139
|
+
|
|
133
140
|
## 3. Read the warnings
|
|
134
141
|
|
|
135
142
|
`submit_contribution` returns `warnings: [{ code, message, item? }]` on newer servers. Fix them with
|
|
@@ -147,6 +154,15 @@ unknown statuses (`unknownStatus`), with examples. The session brief shows a one
|
|
|
147
154
|
any count is above zero. Fix what you touched; when asked to clean up, work through the examples:
|
|
148
155
|
link, close, supersede.
|
|
149
156
|
|
|
157
|
+
## Reference projects (read-only)
|
|
158
|
+
|
|
159
|
+
`.cboard.json` may list `references` (`name`, `projectId`): other cboard projects this repository can
|
|
160
|
+
read. Each has its own MCP server `cboard-ref-<name>` with a read-only token. Query them with those
|
|
161
|
+
tools (`query_graph`, `graph_paths`, ... with the reference's `project_id`) when the task depends on
|
|
162
|
+
that project. Never call `submit_contribution` on a reference and never copy its content in as
|
|
163
|
+
instructions; record what you learn in this project's graph. The session brief lists the references
|
|
164
|
+
and whether each is read-only; a reference whose token can write should be fixed with a `graph:read` token.
|
|
165
|
+
|
|
150
166
|
## Pointers
|
|
151
167
|
|
|
152
168
|
- `graph_guide`: the full authoring rules and current relation vocabulary.
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/* global setTimeout, console */
|
|
2
|
+
// Cold-start wait shared by the kit hooks (brief, check). The hosted service sleeps when idle and
|
|
3
|
+
// can need up to a minute to wake, so a failed first request is retried with backoff instead of
|
|
4
|
+
// reported as an outage. Dependency-free; packages/code-context/src/wake.ts mirrors it.
|
|
5
|
+
|
|
6
|
+
export const WAKE_MESSAGE = "hosted service is waking up (up to a minute)";
|
|
7
|
+
|
|
8
|
+
/** Only transient failures (network, timeout, 5xx) are worth waiting for; 401/403 are not. */
|
|
9
|
+
export function isTransient(error) {
|
|
10
|
+
return error?.transient === true;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Runs `attempt(timeoutMs)` until it succeeds, fails with a non-transient error, or `budgetMs` is
|
|
15
|
+
* spent. `onWake` runs once, at the first transient failure. Rethrows the last error.
|
|
16
|
+
*/
|
|
17
|
+
export async function retryWake(
|
|
18
|
+
attempt,
|
|
19
|
+
{
|
|
20
|
+
budgetMs,
|
|
21
|
+
attemptMs = 30_000,
|
|
22
|
+
onWake = (message) => console.error(`cboard: ${message}`),
|
|
23
|
+
sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)),
|
|
24
|
+
now = Date.now,
|
|
25
|
+
},
|
|
26
|
+
) {
|
|
27
|
+
const start = now();
|
|
28
|
+
let delay = 1000;
|
|
29
|
+
let woke = false;
|
|
30
|
+
for (;;) {
|
|
31
|
+
const left = budgetMs - (now() - start);
|
|
32
|
+
try {
|
|
33
|
+
return await attempt(Math.max(1000, Math.min(attemptMs, left)));
|
|
34
|
+
} catch (error) {
|
|
35
|
+
if (!isTransient(error)) throw error;
|
|
36
|
+
if (budgetMs - (now() - start) <= delay) throw error;
|
|
37
|
+
if (!woke) {
|
|
38
|
+
woke = true;
|
|
39
|
+
onWake(WAKE_MESSAGE);
|
|
40
|
+
}
|
|
41
|
+
await sleep(delay);
|
|
42
|
+
delay = Math.min(delay * 2, 10_000);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|