@canonry/canonry 7.51.5 → 7.51.6

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 (116) hide show
  1. package/dist/ads-ABAT3K4K.js +544 -0
  2. package/dist/agent-5G4DRLYX.js +70 -0
  3. package/dist/agent-ask-UDVCZRO7.js +139 -0
  4. package/dist/agent-conversations-5E4JP2QZ.js +52 -0
  5. package/dist/agent-memory-7IIJ4HGZ.js +92 -0
  6. package/dist/agent-providers-BOXPUXZ4.js +55 -0
  7. package/dist/agent-transcript-4O56G6PQ.js +77 -0
  8. package/dist/analytics-PKMWX5XL.js +240 -0
  9. package/dist/apply-OK4XEBDA.js +175 -0
  10. package/dist/backfill-2OT56CX2.js +41 -0
  11. package/dist/backlinks-547WCHND.js +303 -0
  12. package/dist/bing-ZVBV4ZD5.js +418 -0
  13. package/dist/bootstrap-HUB7XQ73.js +326 -0
  14. package/dist/cdp-KQKQ4PWJ.js +162 -0
  15. package/dist/chunk-2G6IP3MO.js +517 -0
  16. package/dist/chunk-42D2LE2B.js +1273 -0
  17. package/dist/chunk-4MJYGB56.js +124 -0
  18. package/dist/chunk-63ISSSGX.js +9150 -0
  19. package/dist/{chunk-PLYJX67A.js → chunk-6G6FTDWC.js} +8080 -13939
  20. package/dist/chunk-6GO5VVAC.js +15 -0
  21. package/dist/{chunk-4YCGZGA3.js → chunk-73P65KPW.js} +2 -2
  22. package/dist/chunk-7B2Q4NJE.js +133 -0
  23. package/dist/{chunk-JBZZEIM2.js → chunk-7WZ2FPB4.js} +2 -13
  24. package/dist/chunk-AOJU5LKX.js +8 -0
  25. package/dist/chunk-B2FR2ZQ4.js +420 -0
  26. package/dist/{chunk-HAHXPJQ5.js → chunk-B5J675KK.js} +16 -1684
  27. package/dist/{chunk-SFMWHPMX.js → chunk-D6COIM3U.js} +17128 -17143
  28. package/dist/{chunk-A3WSAAQS.js → chunk-DGVUTH7W.js} +9086 -34522
  29. package/dist/chunk-ELCLGWUT.js +83 -0
  30. package/dist/chunk-GO2J7SYT.js +1034 -0
  31. package/dist/chunk-HACZUMGM.js +145 -0
  32. package/dist/chunk-HM4NNKLG.js +94 -0
  33. package/dist/chunk-I3A56PFP.js +58 -0
  34. package/dist/chunk-I77PLCWG.js +961 -0
  35. package/dist/chunk-ISOQPVPY.js +232 -0
  36. package/dist/chunk-KFT5LOP2.js +610 -0
  37. package/dist/chunk-MLKGABMK.js +9 -0
  38. package/dist/chunk-MMEO22MF.js +38 -0
  39. package/dist/chunk-NHQ2U5I4.js +78 -0
  40. package/dist/chunk-PCXRFT3N.js +530 -0
  41. package/dist/chunk-PITHTCAX.js +15376 -0
  42. package/dist/chunk-QWKPSFGL.js +30 -0
  43. package/dist/chunk-RKIXES2B.js +609 -0
  44. package/dist/chunk-TSENU4GG.js +18 -0
  45. package/dist/{chunk-HLVEB5TB.js → chunk-TUTKNUMV.js} +7 -5
  46. package/dist/chunk-U3AHE2RT.js +1160 -0
  47. package/dist/chunk-UQ3MOZGC.js +644 -0
  48. package/dist/{chunk-AZFPA7JV.js → chunk-VBCE4CLX.js} +6 -4
  49. package/dist/chunk-VJWDBFSL.js +69 -0
  50. package/dist/chunk-VYMZ3QXG.js +8264 -0
  51. package/dist/chunk-WAULJDKO.js +2686 -0
  52. package/dist/chunk-WDFI5YMD.js +204 -0
  53. package/dist/chunk-XEBKF4N5.js +8 -0
  54. package/dist/chunk-Z7IUAJOF.js +13 -0
  55. package/dist/{chunk-KEATAHXH.js → chunk-ZWJRY5UI.js} +358 -581
  56. package/dist/chunk-ZXUAWVWM.js +15 -0
  57. package/dist/citations-UYB2RU5U.js +106 -0
  58. package/dist/{cli-catalog-MO6Z2CIZ.js → cli-catalog-F6FI7NB2.js} +5 -3
  59. package/dist/cli-commands-ZG5ILKDA.js +19 -0
  60. package/dist/cli.js +35 -29
  61. package/dist/competitor-EKP4R7YY.js +561 -0
  62. package/dist/content-DREE6JF3.js +257 -0
  63. package/dist/dashboard-ZALEOLLU.js +71 -0
  64. package/dist/demo-JG4Y22O4.js +75 -0
  65. package/dist/{demo-server-GIWDJGJX.js → demo-server-3A4J2C65.js} +22 -9
  66. package/dist/discover-W6GMD2HS.js +372 -0
  67. package/dist/discover-eval-CKFZHRBW.js +282 -0
  68. package/dist/doctor-TNGBSUMA.js +152 -0
  69. package/dist/evidence-3H2GFQBZ.js +57 -0
  70. package/dist/export-cmd-WUIKU5GK.js +49 -0
  71. package/dist/ga-JI6REFO4.js +911 -0
  72. package/dist/gbp-4ENDM5NS.js +370 -0
  73. package/dist/google-HKQSCLOC.js +946 -0
  74. package/dist/google-marketing-KQR5J2S4.js +403 -0
  75. package/dist/health-cmd-TS7EMMCS.js +64 -0
  76. package/dist/history-MSD5DK6K.js +90 -0
  77. package/dist/index.d.ts +47 -47
  78. package/dist/index.js +29 -6
  79. package/dist/init-L6WAEOWX.js +432 -0
  80. package/dist/insights-RTZ3IZTD.js +63 -0
  81. package/dist/intelligence-service-TH52PCNJ.js +15 -0
  82. package/dist/keys-625DZBRM.js +116 -0
  83. package/dist/keyword-CW46RNRR.js +164 -0
  84. package/dist/logs-V33SHBIW.js +30 -0
  85. package/dist/mcp-DFEDPSEG.js +14 -0
  86. package/dist/mcp.js +14 -5
  87. package/dist/measurement-plan-6W37RUOP.js +42 -0
  88. package/dist/notify-DSUOT7WO.js +125 -0
  89. package/dist/organic-evidence-BMN6L4OB.js +53 -0
  90. package/dist/overview-WRRMBZ6S.js +213 -0
  91. package/dist/project-2GJIU3FE.js +460 -0
  92. package/dist/query-3XPMGJUA.js +211 -0
  93. package/dist/research-V433CKJ4.js +200 -0
  94. package/dist/results-export-RGBU7QQQ.js +27 -0
  95. package/dist/run-NIAC6OJN.js +31 -0
  96. package/dist/schedule-KDWXRIE7.js +177 -0
  97. package/dist/search-626MPUJN.js +42 -0
  98. package/dist/serve-73SMMASI.js +557 -0
  99. package/dist/session-7WWOETZB.js +47 -0
  100. package/dist/settings-VKFQO6F2.js +107 -0
  101. package/dist/skills-5HC5H7TE.js +33 -0
  102. package/dist/snapshot-BSJUHFBC.js +538 -0
  103. package/dist/src-F6HM73TN.js +316 -0
  104. package/dist/status-V4OWP7LZ.js +126 -0
  105. package/dist/support-ARF4HER7.js +24 -0
  106. package/dist/technical-aeo-TG7CGU3F.js +625 -0
  107. package/dist/telemetry-O2IUNUBW.js +118 -0
  108. package/dist/tools-2GJIDKND.js +41 -0
  109. package/dist/traffic-XV4I3UPH.js +1295 -0
  110. package/dist/users-VGBLDL5K.js +170 -0
  111. package/dist/visibility-stats-UKJYJ6PP.js +241 -0
  112. package/dist/wordpress-JZA7CGC6.js +600 -0
  113. package/package.json +1 -1
  114. package/dist/chunk-4QQYYRHV.js +0 -23082
  115. package/dist/cli-commands-FOJR3HHU.js +0 -15
  116. package/dist/intelligence-service-XQCNWAPL.js +0 -9
@@ -0,0 +1,15 @@
1
+ // src/operator-url.ts
2
+ function operatorHost(bindHost) {
3
+ if (bindHost === "0.0.0.0") return "127.0.0.1";
4
+ if (bindHost === "::" || bindHost === "[::]") return "::1";
5
+ return bindHost;
6
+ }
7
+ function operatorHttpUrl(bindHost, port) {
8
+ const host = operatorHost(bindHost);
9
+ const bare = host.replace(/^\[|\]$/g, "");
10
+ return `http://${bare.includes(":") ? `[${bare}]` : bare}:${port}`;
11
+ }
12
+
13
+ export {
14
+ operatorHttpUrl
15
+ };
@@ -5,7 +5,7 @@ import {
5
5
  siteCrawlGraphNodes,
6
6
  siteCrawlPages,
7
7
  siteCrawlSnapshots
8
- } from "./chunk-A3WSAAQS.js";
8
+ } from "./chunk-63ISSSGX.js";
9
9
  import {
10
10
  SITE_CRAWL_GRAPH_MAX_EDGES,
11
11
  SITE_CRAWL_GRAPH_MAX_NODES,
@@ -15,7 +15,7 @@ import {
15
15
  factorStatusFromDistribution,
16
16
  factorStatusFromScore,
17
17
  roundPreservingTotal
18
- } from "./chunk-SFMWHPMX.js";
18
+ } from "./chunk-D6COIM3U.js";
19
19
 
20
20
  // src/site-audit-factors.ts
21
21
  function recordedSharePct(factor) {
@@ -0,0 +1,133 @@
1
+ import {
2
+ USAGE_TELEMETRY_HEADERS,
3
+ redactLogString
4
+ } from "./chunk-D6COIM3U.js";
5
+
6
+ // ../api-routes/src/request-context.ts
7
+ import { AsyncLocalStorage } from "async_hooks";
8
+ var requestContext = new AsyncLocalStorage();
9
+ var MAX_REQUEST_CONTEXT_LENGTH = 512;
10
+ var ERROR_CODE_PATTERN = /^[A-Z][A-Z0-9_]{1,39}$/;
11
+ var MAX_ERROR_BODY_BYTES = 16384;
12
+ function errorCodeOfBody(payload) {
13
+ const text = typeof payload === "string" ? payload : Buffer.isBuffer(payload) ? payload.toString("utf8") : void 0;
14
+ if (!text || text.length > MAX_ERROR_BODY_BYTES || !text.trimStart().startsWith("{")) return void 0;
15
+ try {
16
+ const code = JSON.parse(text).error?.code;
17
+ return typeof code === "string" && ERROR_CODE_PATTERN.test(code) ? code : void 0;
18
+ } catch {
19
+ return void 0;
20
+ }
21
+ }
22
+ function getRequestContext(boundRequestId) {
23
+ const context = requestContext.getStore();
24
+ if (!context || context.completed && context.requestId !== boundRequestId) return void 0;
25
+ const { completed: _completed, ...safeContext } = context;
26
+ return safeContext;
27
+ }
28
+ function currentOutcomeAttribution() {
29
+ const context = getRequestContext();
30
+ return context ? { userAgent: context.userAgent, surfaceLabel: context.usageSurface, agentLabel: context.usageAgent } : void 0;
31
+ }
32
+ function requestAuditIdentity(request) {
33
+ const principal = request.principal;
34
+ if (!principal) return {};
35
+ if (principal.delegatedUser) {
36
+ return {
37
+ actor: `user:${principal.delegatedUser.id}`,
38
+ credentialId: request.apiKey?.id ?? principal.id
39
+ };
40
+ }
41
+ if (principal.kind === "user") return { actor: `user:${principal.id}` };
42
+ return {
43
+ actor: `api-key:${principal.id}`,
44
+ credentialId: request.apiKey?.id ?? principal.id
45
+ };
46
+ }
47
+ function headerValue(value) {
48
+ const first = Array.isArray(value) ? value[0] : value;
49
+ return first ? first.slice(0, MAX_REQUEST_CONTEXT_LENGTH) : void 0;
50
+ }
51
+ function registerRequestContext(app, options = {}) {
52
+ app.addHook("onRequest", (request, reply, done) => {
53
+ reply.header("x-request-id", request.id);
54
+ requestContext.run({
55
+ requestId: sanitizeRequestContext(request.id) ?? void 0,
56
+ userAgent: sanitizeRequestContext(request.headers["user-agent"]) ?? void 0,
57
+ actorSession: sanitizeRequestContext(request.headers["x-canonry-actor-session"]) ?? void 0,
58
+ method: request.method,
59
+ // Route template only, never a raw URL, query string, or route parameter.
60
+ route: request.routeOptions.url,
61
+ usageSurface: headerValue(request.headers[USAGE_TELEMETRY_HEADERS.surface]),
62
+ usageAgent: headerValue(request.headers[USAGE_TELEMETRY_HEADERS.agent])
63
+ }, done);
64
+ });
65
+ app.addHook("preHandler", (request, _reply, done) => {
66
+ populateIdentity(request);
67
+ done();
68
+ });
69
+ app.addHook("onError", (request, _reply, error, done) => {
70
+ populateIdentity(request);
71
+ const code = error.code;
72
+ const context = requestContext.getStore();
73
+ if (context && typeof code === "string" && ERROR_CODE_PATTERN.test(code)) context.errorCode = code;
74
+ done();
75
+ });
76
+ app.addHook("onSend", (_request, reply, payload, done) => {
77
+ if (reply.statusCode >= 400) {
78
+ const context = requestContext.getStore();
79
+ const code = context ? errorCodeOfBody(payload) : void 0;
80
+ if (context && code) context.errorCode = code;
81
+ }
82
+ done(null, payload);
83
+ });
84
+ app.addHook("onResponse", (request, reply, done) => {
85
+ populateIdentity(request);
86
+ const context = requestContext.getStore();
87
+ if (context) context.statusCode = reply.statusCode;
88
+ const route = request.routeOptions.url;
89
+ if (options.onRequestCompleted && route) {
90
+ try {
91
+ const kind = request.principal?.kind;
92
+ options.onRequestCompleted({
93
+ method: request.method,
94
+ route,
95
+ statusCode: reply.statusCode,
96
+ durationMs: reply.elapsedTime,
97
+ ...context?.errorCode && reply.statusCode >= 400 ? { errorCode: context.errorCode } : {},
98
+ userAgent: headerValue(request.headers["user-agent"]),
99
+ actorSession: headerValue(request.headers["x-canonry-actor-session"]),
100
+ principalKind: kind === "user" ? "user" : kind ? "api-key" : void 0,
101
+ usageLabels: {
102
+ surface: headerValue(request.headers[USAGE_TELEMETRY_HEADERS.surface]),
103
+ agent: headerValue(request.headers[USAGE_TELEMETRY_HEADERS.agent]),
104
+ mcpClient: headerValue(request.headers[USAGE_TELEMETRY_HEADERS.mcpClient]),
105
+ mcpTool: headerValue(request.headers[USAGE_TELEMETRY_HEADERS.mcpTool]),
106
+ mcpCall: headerValue(request.headers[USAGE_TELEMETRY_HEADERS.mcpCall])
107
+ }
108
+ });
109
+ } catch {
110
+ }
111
+ }
112
+ done();
113
+ if (context) context.completed = true;
114
+ });
115
+ }
116
+ function populateIdentity(request) {
117
+ const context = requestContext.getStore();
118
+ if (context) Object.assign(context, requestAuditIdentity(request));
119
+ }
120
+ function sanitizeRequestContext(value) {
121
+ const joined = Array.isArray(value) ? value.join(", ") : value;
122
+ if (!joined) return null;
123
+ const sanitized = redactLogString(joined).replace(/[\r\n]+/g, " ").trim().slice(0, MAX_REQUEST_CONTEXT_LENGTH);
124
+ return sanitized || null;
125
+ }
126
+
127
+ export {
128
+ getRequestContext,
129
+ currentOutcomeAttribution,
130
+ requestAuditIdentity,
131
+ registerRequestContext,
132
+ sanitizeRequestContext
133
+ };
@@ -5,7 +5,7 @@ import {
5
5
  AppError,
6
6
  parseWindowIn,
7
7
  resolveDateRange
8
- } from "./chunk-SFMWHPMX.js";
8
+ } from "./chunk-D6COIM3U.js";
9
9
 
10
10
  // src/cli-access.ts
11
11
  var CLI_ACCESS_BY_ID = Object.freeze({
@@ -408,16 +408,6 @@ function resolveCliAccessForInvocation(spec, input) {
408
408
  return spec.accessFor?.(input) ?? resolveCliAccess(spec);
409
409
  }
410
410
 
411
- // src/cli-output.ts
412
- function emitJsonl(records) {
413
- let out = "";
414
- for (const record of records) {
415
- out += `${JSON.stringify(record)}
416
- `;
417
- }
418
- if (out) process.stdout.write(out);
419
- }
420
-
421
411
  // src/cli-command-helpers.ts
422
412
  function getString(values, key) {
423
413
  const value = values[key];
@@ -545,6 +535,5 @@ export {
545
535
  windowOptions,
546
536
  readWindowOptions,
547
537
  resolveCliAccess,
548
- resolveCliAccessForInvocation,
549
- emitJsonl
538
+ resolveCliAccessForInvocation
550
539
  };
@@ -0,0 +1,8 @@
1
+ // src/package-version.ts
2
+ import { createRequire } from "module";
3
+ var _require = createRequire(import.meta.url);
4
+ var PACKAGE_VERSION = _require("../package.json").version;
5
+
6
+ export {
7
+ PACKAGE_VERSION
8
+ };
@@ -0,0 +1,420 @@
1
+ import {
2
+ PACKAGE_VERSION
3
+ } from "./chunk-AOJU5LKX.js";
4
+ import {
5
+ CliError,
6
+ isMachineFormat
7
+ } from "./chunk-HGMYEDAQ.js";
8
+ import {
9
+ CodingAgents,
10
+ SKILL_MANIFEST_FILENAME,
11
+ SkillsClients,
12
+ agentPluginClientLabel,
13
+ classifySkillFile,
14
+ coerceSkillManifest,
15
+ formatCanonryPluginUpdateHint,
16
+ formatCanonryPluginVersionMismatch,
17
+ skillsClientSchema
18
+ } from "./chunk-D6COIM3U.js";
19
+
20
+ // src/commands/skills.ts
21
+ import crypto from "crypto";
22
+ import fs from "fs";
23
+ import os from "os";
24
+ import path from "path";
25
+ import { fileURLToPath } from "url";
26
+ var BUNDLED_SKILL_NAMES = ["canonry", "aero"];
27
+ function resolveBundledSkillsRoot(pkgDir) {
28
+ const here = pkgDir ?? path.dirname(fileURLToPath(import.meta.url));
29
+ const candidates = [
30
+ path.join(here, "../assets/agent-workspace/skills"),
31
+ path.join(here, "../../assets/agent-workspace/skills"),
32
+ path.join(here, "../../../../skills")
33
+ ];
34
+ for (const candidate of candidates) {
35
+ if (BUNDLED_SKILL_NAMES.every((name) => fs.existsSync(path.join(candidate, name, "SKILL.md")))) {
36
+ return candidate;
37
+ }
38
+ }
39
+ throw new CliError({
40
+ code: "INTERNAL_ERROR",
41
+ message: `Bundled skills not found. Searched:
42
+ ${candidates.join("\n ")}`,
43
+ exitCode: 2
44
+ });
45
+ }
46
+ function parseDescription(content) {
47
+ const fmMatch = /^---\n([\s\S]*?)\n---/.exec(content);
48
+ if (!fmMatch) return "";
49
+ const descMatch = /^description:\s*(\S.*)$/m.exec(fmMatch[1]);
50
+ if (!descMatch) return "";
51
+ return descMatch[1].replace(/^["']|["']$/g, "").trim();
52
+ }
53
+ function getBundledSkills(pkgDir) {
54
+ const root = resolveBundledSkillsRoot(pkgDir);
55
+ return BUNDLED_SKILL_NAMES.map((name) => {
56
+ const skillDir = path.join(root, name);
57
+ const skillFile = path.join(skillDir, "SKILL.md");
58
+ const content = fs.readFileSync(skillFile, "utf-8");
59
+ return { name, description: parseDescription(content), bundledPath: skillDir };
60
+ });
61
+ }
62
+ function walkRelative(dir, prefix = "") {
63
+ const out = [];
64
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
65
+ const rel = prefix ? path.join(prefix, entry.name) : entry.name;
66
+ const full = path.join(dir, entry.name);
67
+ if (entry.isDirectory()) {
68
+ out.push(...walkRelative(full, rel));
69
+ } else if (entry.isFile()) {
70
+ out.push(rel);
71
+ }
72
+ }
73
+ return out.sort();
74
+ }
75
+ function sha256File(filePath) {
76
+ return crypto.createHash("sha256").update(fs.readFileSync(filePath)).digest("hex");
77
+ }
78
+ function readSkillManifest(skillDir) {
79
+ try {
80
+ return coerceSkillManifest(JSON.parse(fs.readFileSync(path.join(skillDir, SKILL_MANIFEST_FILENAME), "utf-8")));
81
+ } catch {
82
+ return null;
83
+ }
84
+ }
85
+ function writeSkillManifest(skillDir, manifest) {
86
+ fs.writeFileSync(path.join(skillDir, SKILL_MANIFEST_FILENAME), `${JSON.stringify(manifest, null, 2)}
87
+ `, "utf-8");
88
+ }
89
+ function reconcileSkillTree(srcDir, destDir, manifest, force) {
90
+ const result = { added: [], updated: [], unchanged: [], conflicts: [], bundledHashes: /* @__PURE__ */ new Map() };
91
+ for (const rel of walkRelative(srcDir)) {
92
+ const srcPath = path.join(srcDir, rel);
93
+ const destPath = path.join(destDir, rel);
94
+ const bundledHash = sha256File(srcPath);
95
+ result.bundledHashes.set(rel, bundledHash);
96
+ const installedHash = fs.existsSync(destPath) ? sha256File(destPath) : void 0;
97
+ const state = classifySkillFile({ bundledHash, installedHash, manifestHash: manifest?.files[rel] });
98
+ switch (state) {
99
+ case "missing":
100
+ fs.mkdirSync(path.dirname(destPath), { recursive: true });
101
+ fs.copyFileSync(srcPath, destPath);
102
+ result.added.push(rel);
103
+ break;
104
+ case "unchanged":
105
+ result.unchanged.push(rel);
106
+ break;
107
+ case "stale":
108
+ fs.copyFileSync(srcPath, destPath);
109
+ result.updated.push(rel);
110
+ break;
111
+ case "edited":
112
+ if (force) {
113
+ fs.copyFileSync(srcPath, destPath);
114
+ result.updated.push(rel);
115
+ } else {
116
+ result.conflicts.push(rel);
117
+ }
118
+ break;
119
+ }
120
+ }
121
+ return result;
122
+ }
123
+ function buildManifest(skillName, recon, prior) {
124
+ const conflicts = new Set(recon.conflicts);
125
+ const files = {};
126
+ for (const [rel, bundledHash] of recon.bundledHashes) {
127
+ files[rel] = conflicts.has(rel) ? prior?.files[rel] ?? bundledHash : bundledHash;
128
+ }
129
+ return { skill: skillName, version: PACKAGE_VERSION, files };
130
+ }
131
+ function describeChanges(recon) {
132
+ const parts = [];
133
+ if (recon.added.length > 0) parts.push(`${recon.added.length} added`);
134
+ if (recon.updated.length > 0) parts.push(`${recon.updated.length} refreshed`);
135
+ return parts.length > 0 ? parts.join(", ") : "no changes";
136
+ }
137
+ function buildClaudeMessage(name, status, recon) {
138
+ const rel = `.claude/skills/${name}`;
139
+ let message = status === "installed" ? `Installed ${rel}` : status === "updated" ? `Updated ${rel} (${describeChanges(recon)})` : `Already installed: ${rel}`;
140
+ if (recon.conflicts.length > 0) {
141
+ message += ` \u2014 ${recon.conflicts.length} file(s) differ from the bundle (local edits kept; pass --force to overwrite)`;
142
+ }
143
+ return message;
144
+ }
145
+ function installClaudeSkill(skill, targetDir, force) {
146
+ const targetPath = path.join(targetDir, ".claude", "skills", skill.name);
147
+ const existedBefore = fs.existsSync(path.join(targetPath, "SKILL.md"));
148
+ const priorManifest = readSkillManifest(targetPath);
149
+ fs.mkdirSync(targetPath, { recursive: true });
150
+ const recon = reconcileSkillTree(skill.bundledPath, targetPath, priorManifest, force);
151
+ writeSkillManifest(targetPath, buildManifest(skill.name, recon, priorManifest));
152
+ const changed = recon.added.length + recon.updated.length;
153
+ const status = !existedBefore ? "installed" : changed > 0 ? "updated" : "already-installed";
154
+ return {
155
+ skill: skill.name,
156
+ client: CodingAgents.claude,
157
+ targetPath,
158
+ status,
159
+ message: buildClaudeMessage(skill.name, status, recon),
160
+ added: recon.added,
161
+ updated: recon.updated,
162
+ unchanged: recon.unchanged,
163
+ conflicts: recon.conflicts
164
+ };
165
+ }
166
+ function installCodexSymlink(skill, targetDir, force) {
167
+ const codexPath = path.join(targetDir, ".codex", "skills", skill.name);
168
+ const claudePath = path.join(targetDir, ".claude", "skills", skill.name);
169
+ const linkTarget = path.relative(path.dirname(codexPath), claudePath);
170
+ fs.mkdirSync(path.dirname(codexPath), { recursive: true });
171
+ let stat;
172
+ try {
173
+ stat = fs.lstatSync(codexPath);
174
+ } catch {
175
+ stat = void 0;
176
+ }
177
+ if (stat?.isSymbolicLink()) {
178
+ const existing = fs.readlinkSync(codexPath);
179
+ if (existing === linkTarget) {
180
+ return {
181
+ skill: skill.name,
182
+ client: CodingAgents.codex,
183
+ targetPath: codexPath,
184
+ status: "already-linked",
185
+ message: `Already linked: .codex/skills/${skill.name}`
186
+ };
187
+ }
188
+ if (!force) {
189
+ throw new CliError({
190
+ code: "VALIDATION_ERROR",
191
+ message: `.codex/skills/${skill.name} is a symlink pointing elsewhere (${existing}). Pass --force to relink.`,
192
+ details: { skill: skill.name, targetPath: codexPath, existingTarget: existing },
193
+ exitCode: 1
194
+ });
195
+ }
196
+ fs.unlinkSync(codexPath);
197
+ fs.symlinkSync(linkTarget, codexPath);
198
+ return {
199
+ skill: skill.name,
200
+ client: CodingAgents.codex,
201
+ targetPath: codexPath,
202
+ status: "relinked",
203
+ message: `Relinked .codex/skills/${skill.name} \u2192 ${linkTarget}`
204
+ };
205
+ }
206
+ if (stat) {
207
+ if (!force) {
208
+ throw new CliError({
209
+ code: "VALIDATION_ERROR",
210
+ message: `.codex/skills/${skill.name} exists but is not a symlink. Pass --force to replace.`,
211
+ details: { skill: skill.name, targetPath: codexPath },
212
+ exitCode: 1
213
+ });
214
+ }
215
+ fs.rmSync(codexPath, { recursive: true, force: true });
216
+ }
217
+ fs.symlinkSync(linkTarget, codexPath);
218
+ return {
219
+ skill: skill.name,
220
+ client: CodingAgents.codex,
221
+ targetPath: codexPath,
222
+ status: stat ? "relinked" : "linked",
223
+ message: stat ? `Replaced and linked .codex/skills/${skill.name} \u2192 ${linkTarget}` : `Linked .codex/skills/${skill.name} \u2192 ${linkTarget}`
224
+ };
225
+ }
226
+ function buildSummaryMessage(results) {
227
+ const counts = {};
228
+ for (const r of results) counts[r.status] = (counts[r.status] ?? 0) + 1;
229
+ const parts = Object.entries(counts).map(([status, n]) => `${n} ${status}`);
230
+ let message = `Skills install summary: ${parts.join(", ")}.`;
231
+ const totalConflicts = results.reduce((sum, r) => sum + (r.conflicts?.length ?? 0), 0);
232
+ if (totalConflicts > 0) {
233
+ message += ` ${totalConflicts} file(s) differ from the bundle and were kept \u2014 pass --force to overwrite local edits.`;
234
+ }
235
+ return message;
236
+ }
237
+ function getBundledSkillSnapshots(pkgDir) {
238
+ return getBundledSkills(pkgDir).map((skill) => {
239
+ const files = {};
240
+ for (const rel of walkRelative(skill.bundledPath)) {
241
+ files[rel] = sha256File(path.join(skill.bundledPath, rel));
242
+ }
243
+ return {
244
+ name: skill.name,
245
+ version: PACKAGE_VERSION,
246
+ files,
247
+ description: readBundledSkillDescription(skill.bundledPath)
248
+ };
249
+ });
250
+ }
251
+ function readBundledSkillDescription(skillDir) {
252
+ let raw;
253
+ try {
254
+ raw = fs.readFileSync(path.join(skillDir, "SKILL.md"), "utf-8");
255
+ } catch {
256
+ return void 0;
257
+ }
258
+ const parts = raw.split("---");
259
+ if (parts.length < 3) return void 0;
260
+ const lines = (parts[1] ?? "").split("\n");
261
+ const collected = [];
262
+ let inside = false;
263
+ for (const line of lines) {
264
+ const isTopLevelKey = /^[a-z][\w-]*:/i.test(line);
265
+ if (inside && isTopLevelKey) break;
266
+ if (isTopLevelKey && line.startsWith("description:")) {
267
+ inside = true;
268
+ collected.push(line.slice("description:".length).trim());
269
+ continue;
270
+ }
271
+ if (inside) collected.push(line.trim());
272
+ }
273
+ if (!inside) return void 0;
274
+ const value = collected.join(" ").trim();
275
+ const unquoted = value.length >= 2 && value.startsWith('"') && value.endsWith('"') ? value.slice(1, -1) : value;
276
+ return unquoted.length > 0 ? unquoted : void 0;
277
+ }
278
+ async function installSkills(opts = {}) {
279
+ const targetDir = opts.user ? os.homedir() : path.resolve(opts.dir ?? process.cwd());
280
+ const client = opts.client ?? SkillsClients.all;
281
+ const force = opts.force ?? false;
282
+ const allSkills = getBundledSkills();
283
+ const requestedNames = opts.skills && opts.skills.length > 0 ? opts.skills : allSkills.map((s) => s.name);
284
+ const knownNames = new Set(allSkills.map((s) => s.name));
285
+ const unknown = requestedNames.filter((n) => !knownNames.has(n));
286
+ if (unknown.length > 0) {
287
+ throw new CliError({
288
+ code: "VALIDATION_ERROR",
289
+ message: `Unknown skill(s): ${unknown.join(", ")}. Available: ${[...knownNames].join(", ")}`,
290
+ details: { unknownSkills: unknown, availableSkills: [...knownNames] },
291
+ exitCode: 1
292
+ });
293
+ }
294
+ const skillsToInstall = allSkills.filter((s) => requestedNames.includes(s.name));
295
+ fs.mkdirSync(targetDir, { recursive: true });
296
+ const results = [];
297
+ for (const skill of skillsToInstall) {
298
+ results.push(installClaudeSkill(skill, targetDir, force));
299
+ if (client !== SkillsClients.claude) {
300
+ results.push(installCodexSymlink(skill, targetDir, force));
301
+ }
302
+ }
303
+ return {
304
+ targetDir,
305
+ results,
306
+ message: buildSummaryMessage(results)
307
+ };
308
+ }
309
+ async function listSkills(opts = {}) {
310
+ const skills = getBundledSkills();
311
+ if (isMachineFormat(opts.format)) {
312
+ console.log(JSON.stringify({
313
+ skills: skills.map((s) => ({
314
+ name: s.name,
315
+ description: s.description,
316
+ claudePath: `.claude/skills/${s.name}`,
317
+ codexPath: `.codex/skills/${s.name}`
318
+ }))
319
+ }, null, 2));
320
+ return;
321
+ }
322
+ console.log("Bundled canonry skills:\n");
323
+ for (const skill of skills) {
324
+ console.log(` ${skill.name}`);
325
+ if (skill.description) console.log(` ${skill.description}`);
326
+ console.log(` Claude: .claude/skills/${skill.name}/`);
327
+ console.log(` Codex: .codex/skills/${skill.name} (symlink \u2192 ../../.claude/skills/${skill.name})`);
328
+ console.log();
329
+ }
330
+ }
331
+ function emitInstallSummary(summary, format) {
332
+ if (isMachineFormat(format)) {
333
+ console.log(JSON.stringify(summary, null, 2));
334
+ return;
335
+ }
336
+ for (const r of summary.results) console.log(r.message);
337
+ console.log(`
338
+ Target: ${summary.targetDir}`);
339
+ console.log(summary.message);
340
+ }
341
+ function shouldPrintServeSkillsNudge(nudge, updateAvailable) {
342
+ if (!nudge) return false;
343
+ if (nudge.source === "plugin" && updateAvailable) return false;
344
+ return true;
345
+ }
346
+ function getMissingUserSkillsNudge(home, agentPlugin) {
347
+ if (!home) return null;
348
+ const skillsBase = path.join(home, ".claude", "skills");
349
+ const installed = [];
350
+ const missing = [];
351
+ for (const name of BUNDLED_SKILL_NAMES) {
352
+ const skillFile = path.join(skillsBase, name, "SKILL.md");
353
+ if (existsSafe(skillFile)) installed.push(name);
354
+ else missing.push(name);
355
+ }
356
+ if (agentPlugin && agentPlugin.configuredClients.length > 0) {
357
+ const unverifiedClients = agentPlugin.configuredClients.filter((client) => !agentPlugin.verifiedClients.includes(client));
358
+ const mismatchedClients = agentPlugin.verifiedClients.filter((client) => agentPlugin.verifiedClientVersions?.[client] !== PACKAGE_VERSION);
359
+ if (unverifiedClients.length === 0 && mismatchedClients.length === 0) return null;
360
+ const displayClients = (clients) => clients.map((client) => agentPluginClientLabel(client)).join(" + ");
361
+ const problems = [];
362
+ if (unverifiedClients.length > 0) {
363
+ problems.push(`The Canonry plugin is enabled for ${displayClients(unverifiedClients)}, but its cached manifest and skill assets could not be verified.`);
364
+ }
365
+ if (mismatchedClients.length > 0) {
366
+ problems.push(`${formatCanonryPluginVersionMismatch({
367
+ mismatchedClients,
368
+ verifiedClientVersions: agentPlugin.verifiedClientVersions,
369
+ runningVersion: PACKAGE_VERSION
370
+ })}.`);
371
+ }
372
+ const hintClients = [.../* @__PURE__ */ new Set([...unverifiedClients, ...mismatchedClients])];
373
+ return {
374
+ message: `Tip: ${problems.join(" ")} ${formatCanonryPluginUpdateHint(hintClients)}`,
375
+ source: "plugin",
376
+ missing,
377
+ installed
378
+ };
379
+ }
380
+ if (missing.length === 0) return null;
381
+ const fix = missing.length === BUNDLED_SKILL_NAMES.length ? "canonry skills install --user" : `canonry skills install ${missing.join(" ")} --user`;
382
+ return {
383
+ message: `Tip: ${missing.join(" + ")} skill${missing.length === 1 ? "" : "s"} not installed in ~/.claude/skills/. Run \`${fix}\` so Claude/Codex sessions on this host auto-load the canonry reference docs.`,
384
+ source: "legacy-skills",
385
+ missing,
386
+ installed
387
+ };
388
+ }
389
+ function existsSafe(p) {
390
+ try {
391
+ return fs.existsSync(p);
392
+ } catch {
393
+ return false;
394
+ }
395
+ }
396
+ function parseSkillsClient(value) {
397
+ if (!value) return SkillsClients.all;
398
+ const parsed = skillsClientSchema.safeParse(value);
399
+ if (parsed.success) return parsed.data;
400
+ const allowed = skillsClientSchema.options;
401
+ throw new CliError({
402
+ code: "VALIDATION_ERROR",
403
+ message: `Invalid --client value "${value}". Must be one of: ${allowed.join(", ")}`,
404
+ details: { flag: "client", value, allowed },
405
+ exitCode: 1
406
+ });
407
+ }
408
+
409
+ export {
410
+ BUNDLED_SKILL_NAMES,
411
+ resolveBundledSkillsRoot,
412
+ getBundledSkills,
413
+ getBundledSkillSnapshots,
414
+ installSkills,
415
+ listSkills,
416
+ emitInstallSummary,
417
+ shouldPrintServeSkillsNudge,
418
+ getMissingUserSkillsNudge,
419
+ parseSkillsClient
420
+ };