@codyn06/cboard 0.3.7 → 0.3.8
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 -1
- package/dist/cboard.js +3 -1
- package/kit/cboard-connect.js +147 -27
- package/kit/cboard-kit/mcp.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -47,7 +47,12 @@ Create a token in the cboard web app (the "Agent tokens" button in the project h
|
|
|
47
47
|
`graph:read`, `graph:contribute` and `graph:context`, viewers are read-only) and save it to `.cboard/token` in the repository
|
|
48
48
|
(`connect` adds it to `.gitignore`), or export it as `CBOARD_PAT`. The repository's token file takes
|
|
49
49
|
precedence over `CBOARD_PAT`. The token is only ever sent to the default cboard server or to a server you
|
|
50
|
-
list in `CBOARD_TRUSTED_SERVERS`.
|
|
50
|
+
list in `CBOARD_TRUSTED_SERVERS`. `connect` logs in only when neither holds a usable token; to renew a
|
|
51
|
+
working token early, run `connect --renew` (user guide, "Renewing tokens").
|
|
52
|
+
|
|
53
|
+
Developing inside a cboard checkout: `npx @codyn06/cboard@<version> …` there runs the workspace package, whose
|
|
54
|
+
`dist` may be stale. Rebuild it first (`npx tsc -b packages/code-context`) or run the published copy from outside
|
|
55
|
+
the checkout (`npx --prefix "$env:TEMP" @codyn06/cboard@<version> …`).
|
|
51
56
|
|
|
52
57
|
---
|
|
53
58
|
|
package/dist/cboard.js
CHANGED
|
@@ -21,13 +21,15 @@ Options:
|
|
|
21
21
|
--version, -v Show the version
|
|
22
22
|
`;
|
|
23
23
|
const CONNECT_HELP = `Usage: cboard connect [--project <uuid>] [--server <https url>] [--repo <path>]
|
|
24
|
-
[--no-hooks] [--no-agents] [--no-skill] [--no-login] [--strict] [--codex]
|
|
24
|
+
[--no-hooks] [--no-agents] [--no-skill] [--no-login] [--renew] [--strict] [--codex]
|
|
25
25
|
[--goal "<one line>"] [--reference <projectId> --name <name>]...
|
|
26
26
|
[--remove-reference <name>]...
|
|
27
27
|
|
|
28
28
|
Without a usable token (none saved, or the server rejects it) connect logs in through your browser: it
|
|
29
29
|
prints a URL and a code, you approve and pick the project there, and the token is saved to the repository's
|
|
30
30
|
token file (kept out of Git; never printed). --no-login skips that and needs --project and an existing token.
|
|
31
|
+
--renew logs in again although the token works, and replaces the token file once the server accepts the new
|
|
32
|
+
token for the same project (not with --project or --no-login).
|
|
31
33
|
|
|
32
34
|
Writes .cboard.json, the committed kit in .cboard/ (hooks and the MCP header helper run it, never npx),
|
|
33
35
|
.mcp.json, the SessionStart hooks, an AGENTS.md block, the cboard-graph skill and a .gitattributes
|
package/kit/cboard-connect.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Connects a repository to a cboard project. Normally run as `npx @codyn06/cboard connect`; from a
|
|
3
3
|
// cboard checkout (development) run this file directly, inside the target repo (or pass --repo):
|
|
4
4
|
// node <cboard>/scripts/cboard-connect.js --project <uuid> [--server <https url>]
|
|
5
|
-
// [--repo <path>] [--no-hooks] [--no-agents] [--no-skill] [--no-login] [--strict] [--codex] [--goal "<one line>"]
|
|
5
|
+
// [--repo <path>] [--no-hooks] [--no-agents] [--no-skill] [--no-login] [--renew] [--strict] [--codex] [--goal "<one line>"]
|
|
6
6
|
// [--reference <projectId> --name <name>]... [--remove-reference <name>]...
|
|
7
7
|
// It writes `.cboard.json`, copies the dependency-free kit (scripts/cboard-kit) into `.cboard/`,
|
|
8
8
|
// registers the `cboard` MCP server in `.mcp.json`, adds the SessionStart hooks to
|
|
@@ -10,14 +10,18 @@
|
|
|
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
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.
|
|
13
|
+
// chosen there), or pass --no-login to write configuration only. --renew logs in again although the
|
|
14
|
+
// token still works and replaces the token file once the server accepts the new token for the same
|
|
15
|
+
// project. It never prints a token.
|
|
14
16
|
// Rerunning with the same arguments changes nothing.
|
|
15
17
|
//
|
|
16
18
|
// Merge policy for an existing `mcpServers.cboard` entry in `.mcp.json`: other servers, other keys
|
|
17
19
|
// and key order are untouched. Extra keys a user added to the cboard entry are kept. `type` is set
|
|
18
20
|
// when absent. `url` and `headersHelper` are rewritten when absent, when they look generated by
|
|
19
21
|
// this command (the `${CBOARD_GRAPH_URL:-…}/mcp` form; a kit or graph-up headers helper), or, for
|
|
20
|
-
// `url`, when --server was passed. Anything else is kept and reported.
|
|
22
|
+
// `url`, when --server was passed. Anything else is kept and reported. `node scripts/graph-up.js
|
|
23
|
+
// --headers` is kept while scripts/graph-up.js exists (the repository's own helper). SessionStart
|
|
24
|
+
// hooks running connect-check/graph-up and brief/graph-brief count as the kit's hooks.
|
|
21
25
|
import { execFileSync } from "node:child_process";
|
|
22
26
|
import { createHash } from "node:crypto";
|
|
23
27
|
import {
|
|
@@ -32,7 +36,7 @@ import {
|
|
|
32
36
|
} from "node:fs";
|
|
33
37
|
import { dirname, join, relative, resolve } from "node:path";
|
|
34
38
|
import { fileURLToPath } from "node:url";
|
|
35
|
-
import { McpError, mcpCall } from "./cboard-kit/mcp.js";
|
|
39
|
+
import { McpError, describeWhoami, fetchWhoami, mcpCall } from "./cboard-kit/mcp.js";
|
|
36
40
|
import { DeviceError, deviceLogin, openBrowser } from "./cboard-kit/device.js";
|
|
37
41
|
import { retryWake } from "./cboard-kit/wait.js";
|
|
38
42
|
import { parseArgs } from "node:util";
|
|
@@ -348,7 +352,13 @@ export function connect(options = {}) {
|
|
|
348
352
|
setGenerated(
|
|
349
353
|
"headersHelper",
|
|
350
354
|
helperCommand,
|
|
351
|
-
(current) =>
|
|
355
|
+
(current) =>
|
|
356
|
+
typeof current === "string" &&
|
|
357
|
+
GENERATED_HELPER.test(current) &&
|
|
358
|
+
!(
|
|
359
|
+
current.startsWith("node scripts/graph-up.js") &&
|
|
360
|
+
existsSync(join(repo, "scripts", "graph-up.js"))
|
|
361
|
+
),
|
|
352
362
|
);
|
|
353
363
|
mcp.mcpServers[serverName] = entry;
|
|
354
364
|
};
|
|
@@ -377,14 +387,29 @@ export function connect(options = {}) {
|
|
|
377
387
|
if (!isObject(settings.hooks)) settings.hooks = {};
|
|
378
388
|
const groups = Array.isArray(settings.hooks.SessionStart) ? settings.hooks.SessionStart : [];
|
|
379
389
|
settings.hooks.SessionStart = groups;
|
|
380
|
-
|
|
390
|
+
// A replaced hook (this repository's graph-up/graph-brief) satisfies the kit's.
|
|
391
|
+
const present = (command, equivalent) =>
|
|
381
392
|
groups.some(
|
|
382
|
-
(g) =>
|
|
393
|
+
(g) =>
|
|
394
|
+
isObject(g) &&
|
|
395
|
+
Array.isArray(g.hooks) &&
|
|
396
|
+
g.hooks.some(
|
|
397
|
+
(h) =>
|
|
398
|
+
h?.command === command ||
|
|
399
|
+
(typeof h?.command === "string" && equivalent.test(h.command)),
|
|
400
|
+
),
|
|
383
401
|
);
|
|
384
402
|
const wanted = [
|
|
385
|
-
{
|
|
386
|
-
|
|
387
|
-
|
|
403
|
+
{
|
|
404
|
+
type: "command",
|
|
405
|
+
command: checkCommand,
|
|
406
|
+
timeout: 120,
|
|
407
|
+
equivalent: /\b(connect-check|graph-up)\.js\b/,
|
|
408
|
+
},
|
|
409
|
+
{ type: "command", command: briefCommand, timeout: 60, equivalent: /\b(graph-)?brief\.js\b/ },
|
|
410
|
+
]
|
|
411
|
+
.filter((hook) => !present(hook.command, hook.equivalent))
|
|
412
|
+
.map((hook) => ({ type: hook.type, command: hook.command, timeout: hook.timeout }));
|
|
388
413
|
if (wanted.length) {
|
|
389
414
|
const group = groups.find((g) => isObject(g) && Array.isArray(g.hooks) && !("matcher" in g));
|
|
390
415
|
if (group) group.hooks.push(...wanted);
|
|
@@ -614,14 +639,21 @@ async function tokenUsable({ repo, env, server, tokenRel, project, fetchImpl })
|
|
|
614
639
|
// CBOARD_GRAPH_URL stands in for the target server; the trust check below replaces resolveConfig's.
|
|
615
640
|
config = resolveConfig({ ...env, CBOARD_GRAPH_URL: server }, repo);
|
|
616
641
|
} catch {
|
|
617
|
-
return "usable"; // connect() reports the configuration problem as it always did.
|
|
642
|
+
return { status: "usable", source: "", checked: false }; // connect() reports the configuration problem as it always did.
|
|
618
643
|
}
|
|
619
644
|
const token =
|
|
620
645
|
readToken(config, env) || readToken({ ...config, tokenFile: join(repo, tokenRel) }, env);
|
|
621
|
-
if (!token) return "missing";
|
|
646
|
+
if (!token) return { status: "missing", source: "", checked: false };
|
|
647
|
+
const custom =
|
|
648
|
+
config.tokenEnv !== DEFAULT_TOKEN_ENV && env[config.tokenEnv]?.trim() ? config.tokenEnv : "";
|
|
649
|
+
const source = custom
|
|
650
|
+
? `$${custom}`
|
|
651
|
+
: readToken({ ...config, tokenEnv: DEFAULT_TOKEN_ENV, tokenFile: join(repo, tokenRel) }, {})
|
|
652
|
+
? tokenRel.replaceAll("\\", "/")
|
|
653
|
+
: "$CBOARD_PAT";
|
|
622
654
|
// Never send a token to a server the user has not trusted; assume it works.
|
|
623
655
|
if (config.hosted && !isTrustedServer(server, { ...env, CBOARD_GRAPH_URL: undefined })) {
|
|
624
|
-
return "usable";
|
|
656
|
+
return { status: "usable", source, checked: false };
|
|
625
657
|
}
|
|
626
658
|
try {
|
|
627
659
|
const listed = await retryWake(
|
|
@@ -641,12 +673,14 @@ async function tokenUsable({ repo, env, server, tokenRel, project, fetchImpl })
|
|
|
641
673
|
Array.isArray(listed?.data) &&
|
|
642
674
|
!listed.data.some((entry) => entry?.id === project.toLowerCase())
|
|
643
675
|
) {
|
|
644
|
-
return "wrong_project";
|
|
676
|
+
return { status: "wrong_project", source, checked: true };
|
|
645
677
|
}
|
|
646
678
|
} catch (error) {
|
|
647
|
-
return error instanceof McpError && error.kind === "unauthorized"
|
|
679
|
+
return error instanceof McpError && error.kind === "unauthorized"
|
|
680
|
+
? { status: "rejected", source, checked: true }
|
|
681
|
+
: { status: "usable", source, checked: false };
|
|
648
682
|
}
|
|
649
|
-
return "usable";
|
|
683
|
+
return { status: "usable", source, checked: true };
|
|
650
684
|
}
|
|
651
685
|
|
|
652
686
|
/**
|
|
@@ -661,7 +695,12 @@ async function tokenUsable({ repo, env, server, tokenRel, project, fetchImpl })
|
|
|
661
695
|
export async function connectWithLogin(options = {}) {
|
|
662
696
|
const env = options.env ?? process.env;
|
|
663
697
|
const repo = resolve(options.repo ?? process.cwd());
|
|
664
|
-
const { login = {}, noLogin = false, ...rest } = options;
|
|
698
|
+
const { login = {}, noLogin = false, renew = false, ...rest } = options;
|
|
699
|
+
if (renew && (options.project || noLogin)) {
|
|
700
|
+
throw new ConnectError(
|
|
701
|
+
"--renew logs in again; it cannot be combined with --project or --no-login",
|
|
702
|
+
);
|
|
703
|
+
}
|
|
665
704
|
// Removing a reference needs no token, so it never starts a login.
|
|
666
705
|
if (
|
|
667
706
|
noLogin ||
|
|
@@ -684,16 +723,34 @@ export async function connectWithLogin(options = {}) {
|
|
|
684
723
|
} catch (error) {
|
|
685
724
|
throw new ConnectError(error instanceof Error ? error.message : String(error));
|
|
686
725
|
}
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
726
|
+
if (renew && !existing?.projectId) {
|
|
727
|
+
throw new ConnectError(`--renew needs a connected repository (projectId in ${CONFIG_FILE})`);
|
|
728
|
+
}
|
|
729
|
+
let tokenStatus = "";
|
|
730
|
+
if (!renew) {
|
|
731
|
+
const found = await tokenUsable({
|
|
732
|
+
repo,
|
|
733
|
+
env,
|
|
734
|
+
server,
|
|
735
|
+
tokenRel,
|
|
736
|
+
project: options.project,
|
|
737
|
+
fetchImpl: login.fetchImpl,
|
|
738
|
+
});
|
|
739
|
+
tokenStatus = found.status;
|
|
740
|
+
if (tokenStatus === "usable") {
|
|
741
|
+
const result = connect(rest);
|
|
742
|
+
if (!found.source) return result;
|
|
743
|
+
const how = found.checked
|
|
744
|
+
? "accepted by the server"
|
|
745
|
+
: "not checked: server not trusted or unreachable";
|
|
746
|
+
return {
|
|
747
|
+
...result,
|
|
748
|
+
lines: [
|
|
749
|
+
`Token: using ${found.source} (${how}); login skipped. To renew: connect --renew.`,
|
|
750
|
+
...result.lines,
|
|
751
|
+
],
|
|
752
|
+
};
|
|
753
|
+
}
|
|
697
754
|
}
|
|
698
755
|
if (options.project) {
|
|
699
756
|
const reason = {
|
|
@@ -717,6 +774,8 @@ export async function connectWithLogin(options = {}) {
|
|
|
717
774
|
});
|
|
718
775
|
const tokenFile = join(repo, tokenRel);
|
|
719
776
|
mkdirSync(dirname(tokenFile), { recursive: true });
|
|
777
|
+
if (renew)
|
|
778
|
+
return renewToken({ granted, existing, tokenFile, tokenRel, repo, env, server, login, rest });
|
|
720
779
|
writeFileSync(tokenFile, `${granted.token}\n`, { mode: 0o600 });
|
|
721
780
|
let result;
|
|
722
781
|
try {
|
|
@@ -735,6 +794,65 @@ export async function connectWithLogin(options = {}) {
|
|
|
735
794
|
};
|
|
736
795
|
}
|
|
737
796
|
|
|
797
|
+
/** Replaces the token file with a freshly granted token, only once the server accepts it for the same project. */
|
|
798
|
+
async function renewToken({
|
|
799
|
+
granted,
|
|
800
|
+
existing,
|
|
801
|
+
tokenFile,
|
|
802
|
+
tokenRel,
|
|
803
|
+
repo,
|
|
804
|
+
env,
|
|
805
|
+
server,
|
|
806
|
+
login,
|
|
807
|
+
rest,
|
|
808
|
+
}) {
|
|
809
|
+
if (granted.projectId !== existing.projectId) {
|
|
810
|
+
throw new ConnectError(
|
|
811
|
+
`the new token belongs to a different project (${granted.projectId}) than ${CONFIG_FILE} (${existing.projectId}); the old token was kept`,
|
|
812
|
+
);
|
|
813
|
+
}
|
|
814
|
+
const config = resolveConfig({ ...env, CBOARD_GRAPH_URL: server }, repo);
|
|
815
|
+
const call = (name, timeoutMs) =>
|
|
816
|
+
mcpCall({
|
|
817
|
+
api: config.api,
|
|
818
|
+
token: granted.token,
|
|
819
|
+
name,
|
|
820
|
+
timeoutMs,
|
|
821
|
+
...(login.fetchImpl ? { fetchImpl: login.fetchImpl } : {}),
|
|
822
|
+
});
|
|
823
|
+
const temp = `${tokenFile}.tmp-${String(process.pid)}`;
|
|
824
|
+
try {
|
|
825
|
+
writeFileSync(temp, `${granted.token}\n`, { mode: 0o600 });
|
|
826
|
+
await retryWake((attemptMs) => call("list_projects", config.hosted ? attemptMs : 5000), {
|
|
827
|
+
budgetMs: config.hosted ? 60_000 : 0,
|
|
828
|
+
});
|
|
829
|
+
renameSync(temp, tokenFile);
|
|
830
|
+
} catch (error) {
|
|
831
|
+
rmSync(temp, { force: true });
|
|
832
|
+
throw error instanceof McpError
|
|
833
|
+
? new ConnectError(
|
|
834
|
+
`the server did not accept the new token (${error.message}); the old token was kept`,
|
|
835
|
+
)
|
|
836
|
+
: error;
|
|
837
|
+
}
|
|
838
|
+
const me = await fetchWhoami(() => call("whoami", 5000));
|
|
839
|
+
const expires = me ? describeWhoami(me).expires : "";
|
|
840
|
+
const result = connect({ ...rest, project: granted.projectId });
|
|
841
|
+
const custom = config.tokenEnv !== DEFAULT_TOKEN_ENV ? config.tokenEnv : "";
|
|
842
|
+
if (custom && env[custom]?.trim()) {
|
|
843
|
+
result.warnings.push(
|
|
844
|
+
`$${custom} is set and shadows the renewed token file; update or unset it`,
|
|
845
|
+
);
|
|
846
|
+
}
|
|
847
|
+
return {
|
|
848
|
+
...result,
|
|
849
|
+
lines: [
|
|
850
|
+
`Renewed: token saved to ${tokenRel.replaceAll("\\", "/")} (not shown)${expires ? `; expires ${expires}` : ""}.`,
|
|
851
|
+
...result.lines,
|
|
852
|
+
],
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
|
|
738
856
|
export const GOAL_KEY = "cboard:project-goal";
|
|
739
857
|
|
|
740
858
|
/**
|
|
@@ -858,6 +976,7 @@ async function main() {
|
|
|
858
976
|
"no-agents": { type: "boolean", default: false },
|
|
859
977
|
"no-skill": { type: "boolean", default: false },
|
|
860
978
|
"no-login": { type: "boolean", default: false },
|
|
979
|
+
renew: { type: "boolean", default: false },
|
|
861
980
|
strict: { type: "boolean", default: false },
|
|
862
981
|
codex: { type: "boolean", default: false },
|
|
863
982
|
goal: { type: "string" },
|
|
@@ -890,6 +1009,7 @@ async function main() {
|
|
|
890
1009
|
agents: !values["no-agents"],
|
|
891
1010
|
skill: !values["no-skill"],
|
|
892
1011
|
noLogin: values["no-login"],
|
|
1012
|
+
renew: values.renew,
|
|
893
1013
|
strict: values.strict,
|
|
894
1014
|
codex: values.codex,
|
|
895
1015
|
});
|
package/kit/cboard-kit/mcp.js
CHANGED
|
@@ -67,7 +67,7 @@ export async function mcpCall({
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
export const RENEW_COMMAND = "npx @codyn06/cboard@latest connect";
|
|
70
|
+
export const RENEW_COMMAND = "npx @codyn06/cboard@latest connect --renew";
|
|
71
71
|
const NEAR_EXPIRY_DAYS = 14;
|
|
72
72
|
|
|
73
73
|
/** The token's own view of itself (`whoami`); null on an older server, a network error or junk. */
|