@kya-os/cli 1.6.3 → 1.8.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.
Files changed (34) hide show
  1. package/README.md +1 -1
  2. package/dist/commands/checkpoint-init.d.ts +32 -0
  3. package/dist/commands/checkpoint-init.d.ts.map +1 -0
  4. package/dist/commands/checkpoint-init.js +554 -0
  5. package/dist/commands/checkpoint-init.js.map +1 -0
  6. package/dist/commands/receipts.d.ts +11 -0
  7. package/dist/commands/receipts.d.ts.map +1 -1
  8. package/dist/commands/receipts.js +24 -19
  9. package/dist/commands/receipts.js.map +1 -1
  10. package/dist/index.js +10 -2
  11. package/dist/utils/checkpoint-api.d.ts +86 -0
  12. package/dist/utils/checkpoint-api.d.ts.map +1 -0
  13. package/dist/utils/checkpoint-api.js +196 -0
  14. package/dist/utils/checkpoint-api.js.map +1 -0
  15. package/dist/utils/checkpoint-env.d.ts +23 -0
  16. package/dist/utils/checkpoint-env.d.ts.map +1 -0
  17. package/dist/utils/checkpoint-env.js +59 -0
  18. package/dist/utils/checkpoint-env.js.map +1 -0
  19. package/dist/utils/checkpoint-scaffold.d.ts +61 -0
  20. package/dist/utils/checkpoint-scaffold.d.ts.map +1 -0
  21. package/dist/utils/checkpoint-scaffold.js +268 -0
  22. package/dist/utils/checkpoint-scaffold.js.map +1 -0
  23. package/dist/utils/dco/claude-config.d.ts +6 -0
  24. package/dist/utils/dco/claude-config.d.ts.map +1 -1
  25. package/dist/utils/dco/claude-config.js +22 -2
  26. package/dist/utils/dco/claude-config.js.map +1 -1
  27. package/dist/utils/dco/setup.d.ts.map +1 -1
  28. package/dist/utils/dco/setup.js +1 -0
  29. package/dist/utils/dco/setup.js.map +1 -1
  30. package/dist/utils/poll.d.ts +50 -0
  31. package/dist/utils/poll.d.ts.map +1 -0
  32. package/dist/utils/poll.js +73 -0
  33. package/dist/utils/poll.js.map +1 -0
  34. package/package.json +4 -4
@@ -110,10 +110,15 @@ export async function receipts(options = {}) {
110
110
  }
111
111
  if (verify) {
112
112
  const verification = await verifyReceipt(receipt);
113
- const verifyColor = verification.valid ? chalk.green : chalk.red;
114
- console.log(` Verification: ${verifyColor(verification.valid ? "✓ Valid" : "✗ Invalid")}`);
115
- if (!verification.valid && verification.error) {
116
- console.log(` Error: ${chalk.red(verification.error)}`);
113
+ const verifyColor = verification.status === "unsupported"
114
+ ? chalk.yellow
115
+ : chalk.red;
116
+ const verificationLabel = verification.status === "unsupported"
117
+ ? "? Unsupported"
118
+ : "✗ Invalid";
119
+ console.log(` Verification: ${verifyColor(verificationLabel)}`);
120
+ if (verification.error) {
121
+ console.log(` Reason: ${verifyColor(verification.error)}`);
117
122
  }
118
123
  }
119
124
  }
@@ -151,31 +156,31 @@ export async function receipts(options = {}) {
151
156
  }
152
157
  }
153
158
  /**
154
- * Verify a receipt against the KTA log
159
+ * Legacy registry receipts do not carry the signed KYA-OS audit envelopes
160
+ * required by the core verifier. Never promote structural well-formedness to
161
+ * cryptographic verification.
155
162
  */
156
- async function verifyReceipt(receipt) {
163
+ export async function verifyReceipt(receipt) {
157
164
  try {
158
- // TODO: Implement actual receipt verification against KTA log root
159
- // This is a placeholder implementation
160
- // Basic format validation
161
165
  if (!receipt.logRoot ||
162
166
  !receipt.inclusionProof ||
163
- !Array.isArray(receipt.inclusionProof)) {
164
- return { valid: false, error: "Missing log root or inclusion proof" };
167
+ !Array.isArray(receipt.inclusionProof) ||
168
+ receipt.inclusionProof.length === 0) {
169
+ return {
170
+ status: "invalid",
171
+ valid: false,
172
+ error: "Missing log root or inclusion proof",
173
+ };
165
174
  }
166
- // Mock verification - in real implementation, this would:
167
- // 1. Fetch current log root from KTA
168
- // 2. Verify inclusion proof against the log root
169
- // 3. Check that the content hash matches the receipt
170
- // For now, just return valid for well-formed receipts
171
- const isWellFormed = receipt.logRoot.length > 0 && receipt.inclusionProof.length > 0;
172
175
  return {
173
- valid: isWellFormed,
174
- error: isWellFormed ? undefined : "Malformed receipt structure",
176
+ status: "unsupported",
177
+ valid: false,
178
+ error: "Legacy registry receipt cryptographic verification is unsupported",
175
179
  };
176
180
  }
177
181
  catch (error) {
178
182
  return {
183
+ status: "invalid",
179
184
  valid: false,
180
185
  error: error instanceof Error ? error.message : "Verification failed",
181
186
  };
@@ -1 +1 @@
1
- {"version":3,"file":"receipts.js","sourceRoot":"","sources":["../../src/commands/receipts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAC;AAChC,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAS1E;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,UAA2B,EAAE;IAC1D,MAAM,EACJ,IAAI,GAAG,KAAK,EACZ,IAAI,EAAE,WAAW,GAAG,gBAAgB,EACpC,MAAM,GAAG,KAAK,GACf,GAAG,OAAO,CAAC;IAEZ,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,CAAC;IACvD,CAAC;IAED,IAAI,CAAC,UAAU,CAAC,WAAW,CAAC,EAAE,CAAC;QAC7B,MAAM,OAAO,GACX,gFAAgF,CAAC;QACnF,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAClE,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpB,CAAC;QACD,OAAO;IACT,CAAC;IAED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4BAA4B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,EAAE,CAAC;QAE5G,IAAI,IAAI,EAAE,CAAC;YACT,OAAO,CAAC,GAAG,CACT,IAAI,CAAC,SAAS,CACZ;gBACE,OAAO,EAAE,KAAK;gBACd,KAAK,EAAE,YAAY;gBACnB,IAAI,EAAE,kBAAkB;aACzB,EACD,IAAI,EACJ,CAAC,CACF,CACF,CAAC;QACJ,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,YAAY,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAgB;IAMhB,IAAI,CAAC;QACH,IACE,CAAC,OAAO,CAAC,OAAO;YAChB,CAAC,OAAO,CAAC,cAAc;YACvB,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC;YACtC,OAAO,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,EACnC,CAAC;YACD,OAAO;gBACL,MAAM,EAAE,SAAS;gBACjB,KAAK,EAAE,KAAK;gBACZ,KAAK,EAAE,qCAAqC;aAC7C,CAAC;QACJ,CAAC;QACD,OAAO;YACL,MAAM,EAAE,aAAa;YACrB,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,mEAAmE;SAC3E,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,qBAAqB;SACtE,CAAC;IACJ,CAAC;AACH,CAAC"}
package/dist/index.js CHANGED
@@ -17,6 +17,7 @@ import { createDemoCommand } from "./commands/demo.js";
17
17
  import { createDcoCommand } from "./commands/dco.js";
18
18
  import { doctor } from "./commands/doctor.js";
19
19
  import { verify } from "./commands/verify.js";
20
+ import { createCheckpointCommand } from "./commands/checkpoint-init.js";
20
21
  export const program = new Command();
21
22
  // ASCII art logo
22
23
  const logo = chalk.cyan(`
@@ -143,6 +144,8 @@ program
143
144
  program.addCommand(createDemoCommand());
144
145
  // DCO / attribution commands
145
146
  program.addCommand(createDcoCommand());
147
+ // Checkpoint Detect install (KYA-1037)
148
+ program.addCommand(createCheckpointCommand());
146
149
  // Doctor command
147
150
  program
148
151
  .command("doctor")
@@ -172,6 +175,7 @@ ${chalk.bold("Available Commands:")}
172
175
  ${chalk.cyan("claim [token]")} Claim agent with token or get management URLs
173
176
  ${chalk.cyan("dco setup")} Sign commits with your agent identity and attribute PRs
174
177
  ${chalk.cyan("dco status")} Show DCO/attribution setup state
178
+ ${chalk.cyan("checkpoint init")} Register this repo with Checkpoint and set up Detect
175
179
  ${chalk.cyan("status")} Show agent status and mirror information
176
180
  ${chalk.cyan("keys rotate")} Rotate identity keys
177
181
  ${chalk.cyan("identity clean")} Clean identity configuration
@@ -201,8 +205,12 @@ ${chalk.bold("Examples:")}
201
205
  ${chalk.bold("Documentation:")}
202
206
  ${chalk.gray("https://docs.kya-os.ai/xmcp-i")}
203
207
  `);
204
- // Parse arguments (removed ES module guard that prevented CLI execution)
205
- program.parse();
208
+ // Parse arguments (removed ES module guard that prevented CLI execution).
209
+ // parseAsync, not parse: several command actions (including checkpoint
210
+ // init) are async, and plain parse() doesn't await them, so a rejection
211
+ // inside one surfaces as an unhandled promise rejection instead of a
212
+ // clean, reported command failure.
213
+ await program.parseAsync();
206
214
  // Show help if no command specified
207
215
  if (!process.argv.slice(2).length) {
208
216
  program.outputHelp();
@@ -0,0 +1,86 @@
1
+ /**
2
+ * HTTP client for the `mcpi checkpoint init` claim-token flow (KYA-1037).
3
+ *
4
+ * Talks to the three public Checkpoint dashboard endpoints added for this
5
+ * flow: register a claim token, poll its status, and exchange a claimed
6
+ * token for a project API key. Base URL is `CHECKPOINT_API_URL` when set,
7
+ * else the production dashboard origin, mirroring the `KTA_API_URL` /
8
+ * `KTA_BASE_URL` override pattern already used by `register.ts`/`claim.ts`
9
+ * for the sibling knowthat.ai claim flow.
10
+ */
11
+ /**
12
+ * Reconstructs the claim URL from a token alone, same shape the register
13
+ * endpoint itself builds (`/cli/claim?token=...` off the same base). Used
14
+ * only as a fallback for a marker written before this CLI persisted the
15
+ * server-issued `claimUrl` directly; a current run always reprints the
16
+ * value the server returned at register time.
17
+ */
18
+ export declare function buildCheckpointClaimUrl(claimToken: string): string;
19
+ /** The configured Checkpoint origin (protocol + host), to host-match a server-returned URL before acting on it. */
20
+ export declare function checkpointOrigin(): string;
21
+ /**
22
+ * True when CHECKPOINT_API_URL resolves to plain http on a non-localhost
23
+ * host: the claim token, and later the minted API key, cross that
24
+ * connection in the clear.
25
+ */
26
+ export declare function isInsecureCheckpointOrigin(): boolean;
27
+ export interface CheckpointRegisterHints {
28
+ domainHint?: string;
29
+ repoName?: string;
30
+ framework?: "nextjs" | "express" | "static" | "unknown";
31
+ }
32
+ export interface CheckpointRegisterResult {
33
+ registrationId: string;
34
+ claimToken: string;
35
+ claimUrl: string;
36
+ /**
37
+ * Short human-checkable code (`XXX-XXX`) derived from the registration
38
+ * id. The claim URL is first-claimer-wins with nothing binding it to
39
+ * the person who ran `checkpoint init`: if it leaks pre-claim (echoed
40
+ * into CI logs, shoulder-surfed), whoever opens it first claims it into
41
+ * THEIR org, and the real caller's CLI would otherwise proceed to
42
+ * install telemetry into the attacker's project. The claim page shows
43
+ * the same code so the human can cross-check terminal against browser
44
+ * before trusting a "claimed" status.
45
+ */
46
+ confirmationCode: string;
47
+ expiresAt: string;
48
+ }
49
+ export type CheckpointClaimStatus = "pending" | "claimed" | "expired";
50
+ export interface CheckpointExchangeResult {
51
+ projectId: string;
52
+ friendlyId: string | null;
53
+ organizationId: string;
54
+ apiKey: string;
55
+ dashboardUrl: string;
56
+ }
57
+ /** True for an http(s) URL only -- never file:, vscode:, or any other scheme an OS handler might act on unexpectedly. */
58
+ export declare function isHttpUrl(value: string): boolean;
59
+ export declare const CONFIRMATION_CODE_RE: RegExp;
60
+ export declare const API_KEY_RE: RegExp;
61
+ export declare const PROJECT_ID_RE: RegExp;
62
+ /**
63
+ * True only for an http(s) URL whose origin matches the configured
64
+ * Checkpoint origin. A same-shape check gated ONLY the open() call in
65
+ * checkpoint-init.ts (Bugbot, PR #658): announceClaim, the marker, and
66
+ * the --json payload still trusted and displayed any http(s) URL, so a
67
+ * compromised or misconfigured register response could still get a
68
+ * cross-origin, token-bearing link printed and persisted even though it
69
+ * was already judged unsafe to open. Validating at the source means
70
+ * every consumer of a parsed CheckpointRegisterResult gets the guarantee
71
+ * for free.
72
+ */
73
+ export declare function isTrustedClaimUrl(value: string): boolean;
74
+ /**
75
+ * `POST /api/cli/register`: mints a 24h claim token for this repo. The
76
+ * plaintext token is returned here and persisted (alongside
77
+ * `registrationId`) to `.checkpoint/registration.json` (0600, gitignored)
78
+ * by checkpoint-init.ts: a resumed run needs the token itself, not just
79
+ * the id, since the token IS the exchange credential.
80
+ */
81
+ export declare function registerCheckpointProject(hints: CheckpointRegisterHints, signal?: AbortSignal): Promise<CheckpointRegisterResult>;
82
+ /** `GET /api/cli/registrations/:id/status`: the poll target while waiting for the browser claim. */
83
+ export declare function fetchCheckpointClaimStatus(registrationId: string, signal?: AbortSignal): Promise<CheckpointClaimStatus>;
84
+ /** `POST /api/cli/exchange`: trades a claimed token for a project API key exactly once. */
85
+ export declare function exchangeCheckpointClaim(claimToken: string, signal?: AbortSignal): Promise<CheckpointExchangeResult>;
86
+ //# sourceMappingURL=checkpoint-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint-api.d.ts","sourceRoot":"","sources":["../../src/utils/checkpoint-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAkBH;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAIlE;AAED,mHAAmH;A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ACtB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,qBAAqB,CAAC,CAUhC;AAED,2FAA2F;AAC3F,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,wBAAwB,CAAC,CAUnC"}
@@ -0,0 +1,196 @@
1
+ /**
2
+ * HTTP client for the `mcpi checkpoint init` claim-token flow (KYA-1037).
3
+ *
4
+ * Talks to the three public Checkpoint dashboard endpoints added for this
5
+ * flow: register a claim token, poll its status, and exchange a claimed
6
+ * token for a project API key. Base URL is `CHECKPOINT_API_URL` when set,
7
+ * else the production dashboard origin, mirroring the `KTA_API_URL` /
8
+ * `KTA_BASE_URL` override pattern already used by `register.ts`/`claim.ts`
9
+ * for the sibling knowthat.ai claim flow.
10
+ */
11
+ const DEFAULT_CHECKPOINT_ORIGIN = "https://kya.vouched.id";
12
+ function checkpointApiUrl(path) {
13
+ const base = process.env.CHECKPOINT_API_URL || DEFAULT_CHECKPOINT_ORIGIN;
14
+ const url = new URL(base);
15
+ // new URL(path, base) would silently drop any path prefix already on
16
+ // `base` (e.g. a preview deploy served at http://localhost:3000/preview-x)
17
+ // because an absolute path like "/api/cli/register" overrides the
18
+ // base's own path entirely. Join onto the base's pathname instead so a
19
+ // prefix survives.
20
+ const prefix = url.pathname === "/" ? "" : url.pathname.replace(/\/$/, "");
21
+ const suffix = path.startsWith("/") ? path : `/${path}`;
22
+ url.pathname = `${prefix}${suffix}`;
23
+ return url.toString();
24
+ }
25
+ /**
26
+ * Reconstructs the claim URL from a token alone, same shape the register
27
+ * endpoint itself builds (`/cli/claim?token=...` off the same base). Used
28
+ * only as a fallback for a marker written before this CLI persisted the
29
+ * server-issued `claimUrl` directly; a current run always reprints the
30
+ * value the server returned at register time.
31
+ */
32
+ export function buildCheckpointClaimUrl(claimToken) {
33
+ const url = new URL(checkpointApiUrl("/cli/claim"));
34
+ url.searchParams.set("token", claimToken);
35
+ return url.toString();
36
+ }
37
+ /** The configured Checkpoint origin (protocol + host), to host-match a server-returned URL before acting on it. */
38
+ export function checkpointOrigin() {
39
+ const base = process.env.CHECKPOINT_API_URL || DEFAULT_CHECKPOINT_ORIGIN;
40
+ return new URL(base).origin;
41
+ }
42
+ /**
43
+ * True when CHECKPOINT_API_URL resolves to plain http on a non-localhost
44
+ * host: the claim token, and later the minted API key, cross that
45
+ * connection in the clear.
46
+ */
47
+ export function isInsecureCheckpointOrigin() {
48
+ const base = process.env.CHECKPOINT_API_URL || DEFAULT_CHECKPOINT_ORIGIN;
49
+ try {
50
+ const url = new URL(base);
51
+ if (url.protocol !== "http:")
52
+ return false;
53
+ // WHATWG URL keeps the brackets on an IPv6 literal ("[::1]", not
54
+ // "::1"), so the un-bracketed form here was dead code and IPv6
55
+ // loopback (http://[::1]:PORT, real for local dev) incorrectly
56
+ // tripped the insecure-origin warning (bestbrian, PR #658 follow-up).
57
+ return (url.hostname !== "localhost" &&
58
+ url.hostname !== "127.0.0.1" &&
59
+ url.hostname !== "[::1]");
60
+ }
61
+ catch {
62
+ return false;
63
+ }
64
+ }
65
+ async function parseEnvelope(res) {
66
+ const body = (await res.json().catch(() => null));
67
+ if (!res.ok || !body?.success || !body.data) {
68
+ const message = body?.error?.message || `Request failed with status ${res.status}`;
69
+ const error = new Error(message);
70
+ error.code = body?.error?.code;
71
+ throw error;
72
+ }
73
+ return body.data;
74
+ }
75
+ function isNonEmptyString(value) {
76
+ return typeof value === "string" && value.length > 0;
77
+ }
78
+ /** True for an http(s) URL only -- never file:, vscode:, or any other scheme an OS handler might act on unexpectedly. */
79
+ export function isHttpUrl(value) {
80
+ try {
81
+ const protocol = new URL(value).protocol;
82
+ return protocol === "http:" || protocol === "https:";
83
+ }
84
+ catch {
85
+ return false;
86
+ }
87
+ }
88
+ // Exported so checkpoint-init.ts's isValidMarker can apply the SAME
89
+ // shape checks to a marker read off disk, not just a fresh API response
90
+ // (bestbrian, PR #658 follow-up review): a marker's apiKey/projectId/
91
+ // claimUrl otherwise reached writeCheckpointEnv/the Beacon snippet/
92
+ // announceClaim unchecked on the resume-after-exchange path, a gap a
93
+ // hostile committed `.checkpoint/` directory could exploit even though
94
+ // nothing here opens a new trust boundary a malicious repo doesn't
95
+ // already have some other way in.
96
+ export const CONFIRMATION_CODE_RE = /^[0-9A-F]{3}-[0-9A-F]{3}$/;
97
+ // The two live formats the server mints (credentials.mdx): sk_... for
98
+ // current keys, as_... as a real legacy format some paths still generate.
99
+ export const API_KEY_RE = /^(sk|as)_[A-Za-z0-9._-]+$/;
100
+ export const PROJECT_ID_RE = /^[A-Za-z0-9._-]+$/;
101
+ /**
102
+ * True only for an http(s) URL whose origin matches the configured
103
+ * Checkpoint origin. A same-shape check gated ONLY the open() call in
104
+ * checkpoint-init.ts (Bugbot, PR #658): announceClaim, the marker, and
105
+ * the --json payload still trusted and displayed any http(s) URL, so a
106
+ * compromised or misconfigured register response could still get a
107
+ * cross-origin, token-bearing link printed and persisted even though it
108
+ * was already judged unsafe to open. Validating at the source means
109
+ * every consumer of a parsed CheckpointRegisterResult gets the guarantee
110
+ * for free.
111
+ */
112
+ export function isTrustedClaimUrl(value) {
113
+ if (!isHttpUrl(value))
114
+ return false;
115
+ try {
116
+ return new URL(value).origin === checkpointOrigin();
117
+ }
118
+ catch {
119
+ return false;
120
+ }
121
+ }
122
+ /** Validates only the fields checkpoint-init.ts actually reads, not the whole declared shape. */
123
+ function assertRegisterResult(data) {
124
+ const d = data;
125
+ if (!d ||
126
+ !isNonEmptyString(d.registrationId) ||
127
+ !isNonEmptyString(d.claimToken) ||
128
+ !isNonEmptyString(d.claimUrl) ||
129
+ !isTrustedClaimUrl(d.claimUrl) ||
130
+ !isNonEmptyString(d.confirmationCode) ||
131
+ !CONFIRMATION_CODE_RE.test(d.confirmationCode)) {
132
+ throw new Error("Malformed response from Checkpoint (register)");
133
+ }
134
+ }
135
+ function assertStatusResult(data) {
136
+ const status = data?.status;
137
+ if (status !== "pending" && status !== "claimed" && status !== "expired") {
138
+ throw new Error("Malformed response from Checkpoint (status)");
139
+ }
140
+ }
141
+ function assertExchangeResult(data) {
142
+ const d = data;
143
+ if (!d ||
144
+ // projectId and apiKey are format-checked, not just non-empty: both
145
+ // land in a sink an unvalidated newline could corrupt -- projectId
146
+ // into the Beacon snippet's JS string literal, apiKey into a raw
147
+ // .env.local line (a value containing "\nINJECTED=evil" would write
148
+ // a rogue env var into the user's app).
149
+ !isNonEmptyString(d.projectId) ||
150
+ !PROJECT_ID_RE.test(d.projectId) ||
151
+ !isNonEmptyString(d.apiKey) ||
152
+ !API_KEY_RE.test(d.apiKey) ||
153
+ !isNonEmptyString(d.dashboardUrl) ||
154
+ !isHttpUrl(d.dashboardUrl) ||
155
+ !isNonEmptyString(d.organizationId)) {
156
+ throw new Error("Malformed response from Checkpoint (exchange)");
157
+ }
158
+ }
159
+ /**
160
+ * `POST /api/cli/register`: mints a 24h claim token for this repo. The
161
+ * plaintext token is returned here and persisted (alongside
162
+ * `registrationId`) to `.checkpoint/registration.json` (0600, gitignored)
163
+ * by checkpoint-init.ts: a resumed run needs the token itself, not just
164
+ * the id, since the token IS the exchange credential.
165
+ */
166
+ export async function registerCheckpointProject(hints, signal) {
167
+ const res = await fetch(checkpointApiUrl("/api/cli/register"), {
168
+ method: "POST",
169
+ headers: { "content-type": "application/json" },
170
+ body: JSON.stringify(hints),
171
+ signal,
172
+ });
173
+ const data = await parseEnvelope(res);
174
+ assertRegisterResult(data);
175
+ return data;
176
+ }
177
+ /** `GET /api/cli/registrations/:id/status`: the poll target while waiting for the browser claim. */
178
+ export async function fetchCheckpointClaimStatus(registrationId, signal) {
179
+ const res = await fetch(checkpointApiUrl(`/api/cli/registrations/${encodeURIComponent(registrationId)}/status`), { signal });
180
+ const data = await parseEnvelope(res);
181
+ assertStatusResult(data);
182
+ return data.status;
183
+ }
184
+ /** `POST /api/cli/exchange`: trades a claimed token for a project API key exactly once. */
185
+ export async function exchangeCheckpointClaim(claimToken, signal) {
186
+ const res = await fetch(checkpointApiUrl("/api/cli/exchange"), {
187
+ method: "POST",
188
+ headers: { "content-type": "application/json" },
189
+ body: JSON.stringify({ claimToken }),
190
+ signal,
191
+ });
192
+ const data = await parseEnvelope(res);
193
+ assertExchangeResult(data);
194
+ return data;
195
+ }
196
+ //# sourceMappingURL=checkpoint-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint-api.js","sourceRoot":"","sources":["../../src/utils/checkpoint-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,MAAM,yBAAyB,GAAG,wBAAwB,CAAC;AAE3D,SAAS,gBAAgB,CAAC,IAAY;IACpC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,yBAAyB,CAAC;IACzE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC;IAC1B,qEAAqE;IACrE,2EAA2E;IAC3E,kEAAkE;IAClE,uEAAuE;IACvE,mBAAmB;IACnB,MAAM,MAAM,GAAG,GAAG,CAAC,QAAQ,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC3E,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC;IACxD,GAAG,CAAC,QAAQ,GAAG,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC;IACpC,OAAO,GAAG,CAAC,QAAQ,EAAE,CAAC;AACxB,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CAAC,UAAkB;IACxD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,gBAAgB,CAAC,YAAY,CAAC,CAAC,CAAC;IACpD,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,C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MAAM,aAAa,CAA2B,GAAG,CAAC,CAAC;IAChE,oBAAoB,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Minimal, dedicated `.env.local` writer for `mcpi checkpoint init`'s two
3
+ * variables.
4
+ *
5
+ * `EnvManager` (env-manager.ts) is intentionally NOT reused here: its
6
+ * `EnvVariables` interface and every parsing/regex path inside it are
7
+ * hardcoded to the MCP-I identity variable set (`AGENT_DID`,
8
+ * `AGENT_KEY_ID`, `KYA_VOUCHED_API_KEY`, ...). Feeding it
9
+ * `CHECKPOINT_API_KEY`/`CHECKPOINT_PROJECT_ID` would silently fall
10
+ * through its "unrecognized variable" branches and duplicate the lines on
11
+ * every re-run instead of updating them in place. This mirrors
12
+ * EnvManager's SAFE behaviors (prefer updating existing lines, append a
13
+ * clearly-labeled new section otherwise, never touch unrelated lines)
14
+ * scoped to just the two keys this command owns.
15
+ */
16
+ export interface CheckpointEnvVars {
17
+ CHECKPOINT_API_KEY: string;
18
+ CHECKPOINT_PROJECT_ID: string;
19
+ }
20
+ export declare function writeCheckpointEnv(projectRoot: string, vars: CheckpointEnvVars): {
21
+ file: string;
22
+ };
23
+ //# sourceMappingURL=checkpoint-env.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint-env.d.ts","sourceRoot":"","sources":["../../src/utils/checkpoint-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAKH,MAAM,WAAW,iBAAiB;IAChC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,qBAAqB,EAAE,MAAM,CAAC;CAC/B;AAOD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,MAAM,EACnB,IAAI,EAAE,iBAAiB,GACtB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAyClB"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Minimal, dedicated `.env.local` writer for `mcpi checkpoint init`'s two
3
+ * variables.
4
+ *
5
+ * `EnvManager` (env-manager.ts) is intentionally NOT reused here: its
6
+ * `EnvVariables` interface and every parsing/regex path inside it are
7
+ * hardcoded to the MCP-I identity variable set (`AGENT_DID`,
8
+ * `AGENT_KEY_ID`, `KYA_VOUCHED_API_KEY`, ...). Feeding it
9
+ * `CHECKPOINT_API_KEY`/`CHECKPOINT_PROJECT_ID` would silently fall
10
+ * through its "unrecognized variable" branches and duplicate the lines on
11
+ * every re-run instead of updating them in place. This mirrors
12
+ * EnvManager's SAFE behaviors (prefer updating existing lines, append a
13
+ * clearly-labeled new section otherwise, never touch unrelated lines)
14
+ * scoped to just the two keys this command owns.
15
+ */
16
+ import { existsSync, readFileSync, writeFileSync } from "fs";
17
+ import { join } from "path";
18
+ const ENV_KEYS = [
19
+ "CHECKPOINT_API_KEY",
20
+ "CHECKPOINT_PROJECT_ID",
21
+ ];
22
+ export function writeCheckpointEnv(projectRoot, vars) {
23
+ const filePath = join(projectRoot, ".env.local");
24
+ const existing = existsSync(filePath) ? readFileSync(filePath, "utf-8") : "";
25
+ const lines = existing.length > 0 ? existing.split("\n") : [];
26
+ const seen = new Set();
27
+ const updatedLines = lines.map((line) => {
28
+ // Optional leading `export ` so a shell-sourced .env.local
29
+ // (`export CHECKPOINT_API_KEY=...`) gets updated in place too, rather
30
+ // than falling through to the "missing" branch and appending a
31
+ // duplicate line alongside it. The prefix (captured separately) is
32
+ // preserved on update, not silently dropped, so an exported var
33
+ // doesn't quietly become unexported.
34
+ const match = line.match(/^(export\s+)?([A-Z_][A-Z0-9_]*)\s*=/);
35
+ const exportPrefix = match?.[1] ?? "";
36
+ const key = match?.[2];
37
+ if (key && ENV_KEYS.includes(key)) {
38
+ seen.add(key);
39
+ return `${exportPrefix}${key}=${vars[key]}`;
40
+ }
41
+ return line;
42
+ });
43
+ const missing = ENV_KEYS.filter((key) => !seen.has(key));
44
+ if (missing.length > 0) {
45
+ if (updatedLines.length > 0 &&
46
+ updatedLines[updatedLines.length - 1] !== "") {
47
+ updatedLines.push("");
48
+ }
49
+ updatedLines.push("# Added by `mcpi checkpoint init`");
50
+ for (const key of missing) {
51
+ updatedLines.push(`${key}=${vars[key]}`);
52
+ }
53
+ }
54
+ // Exactly one trailing newline, regardless of what was there before.
55
+ const content = `${updatedLines.join("\n").replace(/\n+$/, "")}\n`;
56
+ writeFileSync(filePath, content, "utf-8");
57
+ return { file: ".env.local" };
58
+ }
59
+ //# sourceMappingURL=checkpoint-env.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint-env.js","sourceRoot":"","sources":["../../src/utils/checkpoint-env.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,IAAI,CAAC;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAO5B,MAAM,QAAQ,GAAgC;IAC5C,oBAAoB;IACpB,uBAAuB;CACxB,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAChC,WAAmB,EACnB,IAAuB;IAEvB,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,YAAY,CAAC,CAAC;IACjD,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC7E,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAC9D,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE/B,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;QACtC,2DAA2D;QAC3D,sEAAsE;QACtE,+DAA+D;QAC/D,mEAAmE;QACnE,gEAAgE;QAChE,qCAAqC;QACrC,MAA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C,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,CAAC;AAChC,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Detect-layer scaffolding for `mcpi checkpoint init` (KYA-1037).
3
+ *
4
+ * Maps the repo's detected platform onto one of the three Detect layers
5
+ * Checkpoint ships (Next.js middleware, Express snippet, the keyless
6
+ * Beacon), and, for Next.js, installs the SDK and writes middleware.ts
7
+ * directly (no shelling out to another package's setup script, see the
8
+ * comment on scaffoldNextjs for why). Every install/write step is behind
9
+ * an injectable ScaffoldRunner, so tests never spawn a real process or
10
+ * touch the real filesystem.
11
+ */
12
+ import { type PlatformInfo } from "./platform-detector.js";
13
+ export type CheckpointFramework = "nextjs" | "express" | "static" | "unknown";
14
+ /**
15
+ * Maps `detectPlatform()`'s general-purpose platform/framework detection
16
+ * onto the three layers Checkpoint's `init` can scaffold. A repo with no
17
+ * `package.json` at all (a plain HTML/CSS/JS site) maps to `static`; one
18
+ * with a `package.json` but no recognized framework maps to `unknown`,
19
+ * both get the same keyless Beacon snippet, but the distinction is kept
20
+ * server-side as a hint for future support triage.
21
+ *
22
+ * Checks package.json's own `next` dependency directly, not just
23
+ * platformInfo's derived platform/framework fields: detectPlatform()
24
+ * unconditionally overwrites both to 'cloudflare'/'cloudflare-workers'
25
+ * whenever wrangler.toml/json exists, even for a Next.js repo deployed
26
+ * there, silently losing the nextjs detection underneath it.
27
+ */
28
+ export declare function detectCheckpointFramework(projectRoot?: string, platformInfo?: PlatformInfo): CheckpointFramework;
29
+ export declare function checkpointFrameworkLabel(framework: CheckpointFramework): string;
30
+ /** Best-effort repo name: git remote slug, else the directory name. */
31
+ export declare function detectRepoName(projectRoot?: string): string | undefined;
32
+ /** Best-effort domain hint from `package.json`'s `homepage` field. */
33
+ export declare function detectDomainHint(projectRoot?: string): string | undefined;
34
+ export interface ScaffoldRunner {
35
+ /** Runs `command` with `args` in `cwd`; returns the exit status (0 = success). Never throws. */
36
+ run(command: string, args: string[], cwd: string): {
37
+ status: number;
38
+ };
39
+ /** Writes `content` to `path`. Throws on failure, so the caller can decide how to degrade. */
40
+ writeFile(path: string, content: string): void;
41
+ /** True if `path` exists. */
42
+ fileExists(path: string): boolean;
43
+ }
44
+ /** The real runner: shells out via execFileSync (swallowing spawn errors into a non-zero status) and touches the real filesystem. */
45
+ export declare const defaultScaffoldRunner: ScaffoldRunner;
46
+ export declare const NEXTJS_MANUAL_SNIPPET = "import { createMiddleware } from '@kya-os/checkpoint-nextjs';\n\nexport default createMiddleware({\n apiKey: process.env.CHECKPOINT_API_KEY!,\n projectId: process.env.CHECKPOINT_PROJECT_ID!,\n // The SDK default is 'enforce', which is inert without a deployed\n // policy, spelled out explicitly so flipping it later is a one-word diff.\n enforcementMode: 'observe',\n});\n\nexport const config = { matcher: '/((?!_next/static|_next/image|favicon.ico).*)' };\n";
47
+ export declare const EXPRESS_SNIPPET = "import { withCheckpoint } from '@kya-os/checkpoint-express';\n\napp.use(withCheckpoint({\n apiKey: process.env.CHECKPOINT_API_KEY!,\n projectId: process.env.CHECKPOINT_PROJECT_ID!,\n}));\n";
48
+ export declare function beaconSnippet(projectId: string): string;
49
+ export interface ScaffoldResult {
50
+ framework: CheckpointFramework;
51
+ /** True once the SDK package install succeeded (Next.js/Express only). */
52
+ installed: boolean;
53
+ /** True once the framework's own setup step (writing middleware.ts, printing the snippet) actually ran. */
54
+ setupRan: boolean;
55
+ /** Human-readable next step: either a success line or the manual wiring snippet + docs link. */
56
+ message: string;
57
+ }
58
+ export declare function scaffoldNextjs(projectRoot: string, packageManager: PlatformInfo["packageManager"], runner?: ScaffoldRunner): ScaffoldResult;
59
+ export declare function scaffoldExpress(projectRoot: string, packageManager: PlatformInfo["packageManager"], runner?: ScaffoldRunner): ScaffoldResult;
60
+ export declare function scaffoldBeacon(projectId: string, framework: CheckpointFramework): ScaffoldResult;
61
+ //# sourceMappingURL=checkpoint-scaffold.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checkpoint-scaffold.d.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