coaiajs 0.5.0 → 0.5.2

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 (35) hide show
  1. package/README.md +22 -3
  2. package/dist/src/cli.d.ts +9 -1
  3. package/dist/src/cli.d.ts.map +1 -1
  4. package/dist/src/cli.js +79 -7
  5. package/dist/src/cli.js.map +1 -1
  6. package/dist/src/index.d.ts +1 -0
  7. package/dist/src/index.d.ts.map +1 -1
  8. package/dist/src/index.js +1 -0
  9. package/dist/src/index.js.map +1 -1
  10. package/dist/src/narrative/tool-definitions.d.ts +9 -1
  11. package/dist/src/narrative/tool-definitions.d.ts.map +1 -1
  12. package/dist/src/narrative/tool-definitions.js +10 -1
  13. package/dist/src/narrative/tool-definitions.js.map +1 -1
  14. package/dist/src/skill.d.ts +98 -0
  15. package/dist/src/skill.d.ts.map +1 -0
  16. package/dist/src/skill.js +396 -0
  17. package/dist/src/skill.js.map +1 -0
  18. package/dist/src/version.d.ts +9 -0
  19. package/dist/src/version.d.ts.map +1 -1
  20. package/dist/src/version.js +30 -14
  21. package/dist/src/version.js.map +1 -1
  22. package/docs/LINEAGE-COAIA-NARRATIVE.md +150 -0
  23. package/llms-full.txt +29 -2
  24. package/llms.txt +2 -0
  25. package/package.json +7 -1
  26. package/skills/coaiajs/SKILL.md +165 -0
  27. package/skills/coaiajs/references/beyond-narrative.md +71 -0
  28. package/skills/coaiajs/references/creative-orientation.md +42 -0
  29. package/skills/coaiajs/references/delayed-resolution.md +48 -0
  30. package/skills/coaiajs/references/install-and-environment.md +85 -0
  31. package/skills/coaiajs/references/mcp-tools.md +83 -0
  32. package/skills/coaiajs/references/narrative-beats.md +44 -0
  33. package/skills/coaiajs/references/reading-the-store.md +66 -0
  34. package/skills/coaiajs/references/structural-tension-charting.md +71 -0
  35. package/skills/coaiajs/references/wampum-belts.md +72 -0
@@ -0,0 +1,98 @@
1
+ /**
2
+ * coaiajs — the packaged agent skill.
3
+ *
4
+ * WHY THE CONTENT IS NOT IN THIS FILE
5
+ *
6
+ * The lineage this is adapted from (coaia-narrative's `src/skill.ts`) embedded ~250
7
+ * lines of markdown as `['---', 'name: ...', ...].join('\n')`. That works, and it is
8
+ * unreadable: a documentation change shows up in review as a diff of quoted string
9
+ * fragments, no markdown tool can lint it, and the prose cannot be read in the form
10
+ * the reader will see.
11
+ *
12
+ * So the skill lives as real markdown under `skills/coaiajs/`, shipped by the `files`
13
+ * field, and is read from the package root at run time. `tests/skill.test.mjs` fails
14
+ * if a file listed here does not resolve, which is the failure mode this trades for.
15
+ *
16
+ * WHY THE TOOL MAP IS GENERATED
17
+ *
18
+ * A hand-written tool table drifts from the server the moment a tool is added, and a
19
+ * skill that advertises a tool the server does not serve teaches an agent to make a
20
+ * call that fails. `{{TOOL_MAP}}` is rendered from `ALL_TOOL_DEFINITIONS` — the same
21
+ * array the MCP server registers — so the two cannot disagree.
22
+ */
23
+ interface ToolLike {
24
+ name: string;
25
+ description: string;
26
+ }
27
+ /**
28
+ * Every tool the MCP server serves at STANDARD, assembled from the same definition
29
+ * sources the server itself registers.
30
+ *
31
+ * The first version of this skill mapped only the narrative group, and described the
32
+ * rest in prose written by hand — which is precisely the drift the generated map was
33
+ * introduced to prevent. A skill named for the package has to cover the package.
34
+ */
35
+ export declare function servedTools(): ToolLike[];
36
+ export declare const SKILL_NAME = "coaiajs";
37
+ /**
38
+ * Files that make up the skill, in the order a reader meets them.
39
+ *
40
+ * Listed explicitly rather than discovered by walking the directory: a stray file
41
+ * under `skills/` should not silently become part of what gets installed, and a
42
+ * missing one should be an error rather than a quietly shorter skill.
43
+ */
44
+ export declare const SKILL_FILES: readonly string[];
45
+ /** Directory inside the package holding the skill's markdown. */
46
+ export declare function getPackagedSkillDir(): string;
47
+ /**
48
+ * Render the served tool surface as grouped markdown tables, from the definitions the
49
+ * MCP server actually registers. A tool belonging to no group still appears, under
50
+ * "Other" — a tool silently absent from its own map is the drift this avoids.
51
+ */
52
+ export declare function renderToolMap(): string;
53
+ /**
54
+ * Render the CLI as a table of commands and their subcommands, walked from the real
55
+ * commander program. Hand-written command tables were already a maintenance debt in
56
+ * README and llms-full; the skill does not add a third copy.
57
+ */
58
+ export declare function renderCliMap(): string;
59
+ /** Read one packaged skill file and fill its placeholders. */
60
+ export declare function renderSkillFile(relativeFilePath: string): string;
61
+ /** Every skill file, rendered, keyed by its path within the skill directory. */
62
+ export declare function renderSkill(): Map<string, string>;
63
+ export declare function getSkillInstallDir(globalInstall: boolean): string;
64
+ export declare function getClaudeSkillLinkPath(globalInstall: boolean): string;
65
+ /** Print the packaged SKILL.md, rendered. */
66
+ export declare function showSkill(): void;
67
+ export interface InstallSkillOptions {
68
+ global?: boolean;
69
+ force?: boolean;
70
+ yes?: boolean;
71
+ }
72
+ export declare function installSkill(options?: InstallSkillOptions): Promise<string>;
73
+ export interface SkillCheckResult {
74
+ status: 'current' | 'stale' | 'missing';
75
+ installDir: string;
76
+ packageVersion: string;
77
+ /** Version recorded in the installed SKILL.md frontmatter, when one is readable. */
78
+ installedVersion?: string;
79
+ /** Files whose installed content differs from what this package would write. */
80
+ differing: string[];
81
+ /** Files this package ships that the install does not have. */
82
+ absent: string[];
83
+ }
84
+ /**
85
+ * Compare an installed skill against the packaged one.
86
+ *
87
+ * The failure this exists for is silent: a skill installed by an older `coaiajs`
88
+ * describes an older tool surface, sits there looking authoritative, and nothing in
89
+ * the normal flow ever says so. An agent then reads a tool map that no longer matches
90
+ * the server it is talking to.
91
+ */
92
+ export declare function checkSkill(options?: {
93
+ global?: boolean;
94
+ }): SkillCheckResult;
95
+ /** Human-readable form of a check, for the CLI. */
96
+ export declare function formatSkillCheck(result: SkillCheckResult): string;
97
+ export {};
98
+ //# sourceMappingURL=skill.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/skill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAgCH,UAAU,QAAQ;IA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AA+D;IAC/D,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GAAG,gBAAgB,CA6B/E;AAED,mDAAmD;AACnD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,GAAG,MAAM,CAqBjE"}
@@ -0,0 +1,396 @@
1
+ /**
2
+ * coaiajs — the packaged agent skill.
3
+ *
4
+ * WHY THE CONTENT IS NOT IN THIS FILE
5
+ *
6
+ * The lineage this is adapted from (coaia-narrative's `src/skill.ts`) embedded ~250
7
+ * lines of markdown as `['---', 'name: ...', ...].join('\n')`. That works, and it is
8
+ * unreadable: a documentation change shows up in review as a diff of quoted string
9
+ * fragments, no markdown tool can lint it, and the prose cannot be read in the form
10
+ * the reader will see.
11
+ *
12
+ * So the skill lives as real markdown under `skills/coaiajs/`, shipped by the `files`
13
+ * field, and is read from the package root at run time. `tests/skill.test.mjs` fails
14
+ * if a file listed here does not resolve, which is the failure mode this trades for.
15
+ *
16
+ * WHY THE TOOL MAP IS GENERATED
17
+ *
18
+ * A hand-written tool table drifts from the server the moment a tool is added, and a
19
+ * skill that advertises a tool the server does not serve teaches an agent to make a
20
+ * call that fails. `{{TOOL_MAP}}` is rendered from `ALL_TOOL_DEFINITIONS` — the same
21
+ * array the MCP server registers — so the two cannot disagree.
22
+ */
23
+ import { lstatSync, mkdirSync, readFileSync, readlinkSync, realpathSync, rmSync, symlinkSync, unlinkSync, writeFileSync, } from 'node:fs';
24
+ import { homedir } from 'node:os';
25
+ import { dirname, join, relative as relativePath, resolve } from 'node:path';
26
+ import { createInterface } from 'node:readline/promises';
27
+ import { getPackageRoot, getPackageVersion } from './version.js';
28
+ import { ALL_TOOL_DEFINITIONS as NARRATIVE_TOOL_DEFINITIONS, CORE_TOOLS, STC_TOOLS, NARRATIVE_TOOLS, WAMPUM_TOOLS, KG_TOOLS, } from './narrative/index.js';
29
+ import { PDE_MCP_TOOLS } from './pde/index.js';
30
+ import { PLANNING_MCP_TOOLS } from './planning/index.js';
31
+ import { getCoaiapyToolDefinitions } from '../mcp/tools/index.js';
32
+ import { FeatureConfig } from '../mcp/config.js';
33
+ import { buildProgram } from './cli.js';
34
+ /**
35
+ * Every tool the MCP server serves at STANDARD, assembled from the same definition
36
+ * sources the server itself registers.
37
+ *
38
+ * The first version of this skill mapped only the narrative group, and described the
39
+ * rest in prose written by hand — which is precisely the drift the generated map was
40
+ * introduced to prevent. A skill named for the package has to cover the package.
41
+ */
42
+ export function servedTools() {
43
+ const featureConfig = new FeatureConfig('STANDARD');
44
+ return [
45
+ ...getCoaiapyToolDefinitions(featureConfig),
46
+ ...NARRATIVE_TOOL_DEFINITIONS,
47
+ ...PDE_MCP_TOOLS,
48
+ ...PLANNING_MCP_TOOLS,
49
+ ];
50
+ }
51
+ export const SKILL_NAME = 'coaiajs';
52
+ /**
53
+ * Files that make up the skill, in the order a reader meets them.
54
+ *
55
+ * Listed explicitly rather than discovered by walking the directory: a stray file
56
+ * under `skills/` should not silently become part of what gets installed, and a
57
+ * missing one should be an error rather than a quietly shorter skill.
58
+ */
59
+ export const SKILL_FILES = [
60
+ 'SKILL.md',
61
+ 'references/creative-orientation.md',
62
+ 'references/structural-tension-charting.md',
63
+ 'references/delayed-resolution.md',
64
+ 'references/narrative-beats.md',
65
+ 'references/wampum-belts.md',
66
+ 'references/reading-the-store.md',
67
+ 'references/beyond-narrative.md',
68
+ 'references/mcp-tools.md',
69
+ 'references/install-and-environment.md',
70
+ ];
71
+ /** Directory inside the package holding the skill's markdown. */
72
+ export function getPackagedSkillDir() {
73
+ return join(getPackageRoot(), 'skills', SKILL_NAME);
74
+ }
75
+ // ─── Tool map generation ──────────────────────────────────────────────
76
+ /**
77
+ * Abbreviations whose trailing period does not end a sentence. Without these,
78
+ * `open_nodes` — whose description reads "…by exact name (e.g. 'chart_123_chart')" —
79
+ * rendered as "Open specific entity nodes by exact name (e.g." in the table, which
80
+ * reads as a truncation bug rather than as a description.
81
+ */
82
+ const NON_TERMINAL_ABBREVIATIONS = ['e.g', 'i.e', 'etc', 'vs', 'cf', 'approx', 'no'];
83
+ /**
84
+ * One line of description, trimmed to something a table cell can hold.
85
+ *
86
+ * Leading emphasis markers ("🚨 NEW LLM?", "✨ RECOMMENDED:", "⚠️ DEPRECATED:") are kept
87
+ * deliberately — they carry the tool's own stance about itself, and a map that hides a
88
+ * deprecation is worse than one that shows it.
89
+ */
90
+ function shortDescription(description) {
91
+ const collapsed = description.replace(/\s+/g, ' ').trim();
92
+ // Cut at the first period that actually ends a sentence: followed by whitespace and
93
+ // something that starts one, and not preceded by an abbreviation or a single letter.
94
+ let sentence = collapsed;
95
+ for (const match of collapsed.matchAll(/\.(?=\s+[A-Z0-9`'"(\u{1F300}-\u{1FAFF}])/gu)) {
96
+ const before = collapsed.slice(0, match.index);
97
+ const lastWord = (/([A-Za-z.]+)$/.exec(before)?.[1] ?? '').toLowerCase();
98
+ if (NON_TERMINAL_ABBREVIATIONS.includes(lastWord))
99
+ continue;
100
+ if (/^[a-z]$/.test(lastWord))
101
+ continue; // an initial, not a sentence end
102
+ sentence = collapsed.slice(0, match.index + 1);
103
+ break;
104
+ }
105
+ const escaped = sentence.replace(/\|/g, '\\|');
106
+ return escaped.length > 180 ? `${escaped.slice(0, 177)}…` : escaped;
107
+ }
108
+ const TOOL_GROUP_ORDER = [
109
+ { title: 'Start here', names: CORE_TOOLS },
110
+ { title: 'Structural tension charts', names: STC_TOOLS },
111
+ { title: 'Narrative beats', names: NARRATIVE_TOOLS },
112
+ { title: 'Wampum belts', names: WAMPUM_TOOLS },
113
+ { title: 'Knowledge graph', names: KG_TOOLS },
114
+ { title: 'Prompt decomposition (PDE)', names: PDE_MCP_TOOLS.map(t => t.name) },
115
+ { title: 'Planning', names: PLANNING_MCP_TOOLS.map(t => t.name) },
116
+ { title: 'Redis and Langfuse', prefix: 'coaia_' },
117
+ ];
118
+ function toolTable(rows) {
119
+ return `| Tool | Use |\n|---|---|\n${rows.join('\n')}`;
120
+ }
121
+ /**
122
+ * Render the served tool surface as grouped markdown tables, from the definitions the
123
+ * MCP server actually registers. A tool belonging to no group still appears, under
124
+ * "Other" — a tool silently absent from its own map is the drift this avoids.
125
+ */
126
+ export function renderToolMap() {
127
+ const tools = servedTools();
128
+ const byName = new Map(tools.map(t => [t.name, t]));
129
+ const placed = new Set();
130
+ const sections = [];
131
+ for (const group of TOOL_GROUP_ORDER) {
132
+ const names = group.names
133
+ ?? tools.filter(t => t.name.startsWith(group.prefix)).map(t => t.name);
134
+ const rows = [];
135
+ for (const name of names) {
136
+ const tool = byName.get(name);
137
+ if (!tool || placed.has(name))
138
+ continue;
139
+ placed.add(name);
140
+ rows.push(`| \`${name}\` | ${shortDescription(tool.description)} |`);
141
+ }
142
+ if (rows.length === 0)
143
+ continue;
144
+ sections.push(`### ${group.title}\n\n${toolTable(rows)}`);
145
+ }
146
+ const leftover = tools.filter(t => !placed.has(t.name));
147
+ if (leftover.length > 0) {
148
+ sections.push(`### Other\n\n${toolTable(leftover.map(t => `| \`${t.name}\` | ${shortDescription(t.description)} |`))}`);
149
+ }
150
+ return sections.join('\n\n');
151
+ }
152
+ /**
153
+ * Render the CLI as a table of commands and their subcommands, walked from the real
154
+ * commander program. Hand-written command tables were already a maintenance debt in
155
+ * README and llms-full; the skill does not add a third copy.
156
+ */
157
+ export function renderCliMap() {
158
+ const program = buildProgram();
159
+ const rows = [];
160
+ for (const command of program.commands) {
161
+ if (command.name() === 'help')
162
+ continue;
163
+ const aliases = command.aliases();
164
+ const name = aliases.length > 0 ? `\`${command.name()}\` (\`${aliases[0]}\`)` : `\`${command.name()}\``;
165
+ const subs = command.commands
166
+ .filter(c => c.name() !== 'help')
167
+ .map(c => `\`${c.name()}\``);
168
+ const detail = subs.length > 0
169
+ ? `${shortDescription(command.description())} — ${subs.join(', ')}`
170
+ : shortDescription(command.description());
171
+ rows.push(`| ${name} | ${detail} |`);
172
+ }
173
+ const globals = program.options
174
+ .map(o => `\`${o.flags}\``)
175
+ .join(' · ');
176
+ return `Global options: ${globals}\n\n| Command | Purpose |\n|---|---|\n${rows.join('\n')}`;
177
+ }
178
+ // ─── Rendering ────────────────────────────────────────────────────────
179
+ /** Placeholders a packaged skill file may carry. */
180
+ function substitutions() {
181
+ return {
182
+ VERSION: getPackageVersion(),
183
+ TOOL_COUNT: String(servedTools().length),
184
+ NARRATIVE_TOOL_COUNT: String(NARRATIVE_TOOL_DEFINITIONS.length),
185
+ TOOL_MAP: renderToolMap(),
186
+ CLI_MAP: renderCliMap(),
187
+ };
188
+ }
189
+ function applySubstitutions(content, values) {
190
+ return content.replace(/\{\{([A-Z_]+)\}\}/g, (whole, key) => {
191
+ const value = values[key];
192
+ if (value === undefined) {
193
+ throw new Error(`Packaged skill carries an unknown placeholder {{${key}}}. ` +
194
+ `Add it to substitutions() in src/skill.ts or remove it from the markdown.`);
195
+ }
196
+ return value;
197
+ });
198
+ }
199
+ /** Read one packaged skill file and fill its placeholders. */
200
+ export function renderSkillFile(relativeFilePath) {
201
+ const source = join(getPackagedSkillDir(), relativeFilePath);
202
+ let raw;
203
+ try {
204
+ raw = readFileSync(source, 'utf8');
205
+ }
206
+ catch {
207
+ throw new Error(`Packaged skill file missing: ${source}. ` +
208
+ `The published package must ship skills/ — check the "files" field in package.json.`);
209
+ }
210
+ return applySubstitutions(raw, substitutions());
211
+ }
212
+ /** Every skill file, rendered, keyed by its path within the skill directory. */
213
+ export function renderSkill() {
214
+ const values = substitutions();
215
+ const rendered = new Map();
216
+ for (const file of SKILL_FILES) {
217
+ const source = join(getPackagedSkillDir(), file);
218
+ let raw;
219
+ try {
220
+ raw = readFileSync(source, 'utf8');
221
+ }
222
+ catch {
223
+ throw new Error(`Packaged skill file missing: ${source}. ` +
224
+ `The published package must ship skills/ — check the "files" field in package.json.`);
225
+ }
226
+ rendered.set(file, applySubstitutions(raw, values));
227
+ }
228
+ return rendered;
229
+ }
230
+ // ─── Install locations ────────────────────────────────────────────────
231
+ export function getSkillInstallDir(globalInstall) {
232
+ return globalInstall
233
+ ? resolve(homedir(), '.agents', 'skills', SKILL_NAME)
234
+ : resolve(process.cwd(), '.agents', 'skills', SKILL_NAME);
235
+ }
236
+ export function getClaudeSkillLinkPath(globalInstall) {
237
+ return globalInstall
238
+ ? resolve(homedir(), '.claude', 'skills', SKILL_NAME)
239
+ : resolve(process.cwd(), '.claude', 'skills', SKILL_NAME);
240
+ }
241
+ function pathExists(pathName) {
242
+ try {
243
+ lstatSync(pathName);
244
+ return true;
245
+ }
246
+ catch {
247
+ return false;
248
+ }
249
+ }
250
+ function removePath(pathName) {
251
+ const stat = lstatSync(pathName);
252
+ if (stat.isDirectory() && !stat.isSymbolicLink()) {
253
+ rmSync(pathName, { recursive: true, force: true });
254
+ }
255
+ else {
256
+ unlinkSync(pathName);
257
+ }
258
+ }
259
+ function writeRenderedSkill(targetDir, force) {
260
+ // Render before touching anything on disk: a missing packaged file must not leave
261
+ // a half-written skill where a whole one used to be.
262
+ const rendered = renderSkill();
263
+ if (pathExists(targetDir)) {
264
+ if (!force) {
265
+ throw new Error(`Skill already exists: ${targetDir} (use --force to replace it)`);
266
+ }
267
+ removePath(targetDir);
268
+ }
269
+ mkdirSync(targetDir, { recursive: true });
270
+ for (const [file, content] of rendered) {
271
+ const destination = resolve(targetDir, file);
272
+ mkdirSync(dirname(destination), { recursive: true });
273
+ writeFileSync(destination, content, 'utf-8');
274
+ }
275
+ }
276
+ function ensureClaudeSymlink(linkPath, targetDir, force) {
277
+ const parentDir = dirname(linkPath);
278
+ if (pathExists(parentDir)) {
279
+ const resolvedTargetParent = realpathSync(dirname(targetDir));
280
+ const resolvedLinkParent = realpathSync(parentDir);
281
+ // Already the same directory — Claude sees the skill without a link.
282
+ if (resolvedTargetParent === resolvedLinkParent) {
283
+ return false;
284
+ }
285
+ }
286
+ const linkTarget = relativePath(parentDir, targetDir) || '.';
287
+ mkdirSync(parentDir, { recursive: true });
288
+ if (pathExists(linkPath)) {
289
+ const stat = lstatSync(linkPath);
290
+ if (stat.isSymbolicLink() && readlinkSync(linkPath) === linkTarget) {
291
+ return true;
292
+ }
293
+ if (!force) {
294
+ throw new Error(`Claude skill path already exists: ${linkPath} (use --force to replace it)`);
295
+ }
296
+ removePath(linkPath);
297
+ }
298
+ symlinkSync(linkTarget, linkPath, 'dir');
299
+ return true;
300
+ }
301
+ async function shouldCreateClaudeSymlink(linkPath, autoYes) {
302
+ if (autoYes)
303
+ return true;
304
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
305
+ console.log(`Tip: create a Claude symlink manually at ${linkPath}`);
306
+ return false;
307
+ }
308
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
309
+ try {
310
+ const answer = await rl.question(`Create a symlink in ${linkPath}? [y/N] `);
311
+ const normalized = answer.trim().toLowerCase();
312
+ return normalized === 'y' || normalized === 'yes';
313
+ }
314
+ finally {
315
+ rl.close();
316
+ }
317
+ }
318
+ // ─── Commands ─────────────────────────────────────────────────────────
319
+ /** Print the packaged SKILL.md, rendered. */
320
+ export function showSkill() {
321
+ process.stdout.write(renderSkillFile('SKILL.md'));
322
+ }
323
+ export async function installSkill(options = {}) {
324
+ const globalInstall = options.global === true;
325
+ const installDir = getSkillInstallDir(globalInstall);
326
+ writeRenderedSkill(installDir, options.force === true);
327
+ console.log(`Installed the coaiajs skill (v${getPackageVersion()}) to ${installDir}`);
328
+ const claudeLinkPath = getClaudeSkillLinkPath(globalInstall);
329
+ if (await shouldCreateClaudeSymlink(claudeLinkPath, options.yes === true)) {
330
+ const linked = ensureClaudeSymlink(claudeLinkPath, installDir, options.force === true);
331
+ console.log(linked
332
+ ? `Linked Claude skill at ${claudeLinkPath}`
333
+ : `Claude already sees the skill via ${dirname(claudeLinkPath)}`);
334
+ }
335
+ return installDir;
336
+ }
337
+ /**
338
+ * Compare an installed skill against the packaged one.
339
+ *
340
+ * The failure this exists for is silent: a skill installed by an older `coaiajs`
341
+ * describes an older tool surface, sits there looking authoritative, and nothing in
342
+ * the normal flow ever says so. An agent then reads a tool map that no longer matches
343
+ * the server it is talking to.
344
+ */
345
+ export function checkSkill(options = {}) {
346
+ const installDir = getSkillInstallDir(options.global === true);
347
+ const packageVersion = getPackageVersion();
348
+ if (!pathExists(installDir)) {
349
+ return { status: 'missing', installDir, packageVersion, differing: [], absent: [...SKILL_FILES] };
350
+ }
351
+ const rendered = renderSkill();
352
+ const differing = [];
353
+ const absent = [];
354
+ let installedVersion;
355
+ for (const [file, expected] of rendered) {
356
+ let actual;
357
+ try {
358
+ actual = readFileSync(resolve(installDir, file), 'utf8');
359
+ }
360
+ catch {
361
+ absent.push(file);
362
+ continue;
363
+ }
364
+ if (file === 'SKILL.md') {
365
+ installedVersion = /^\s*packageVersion:\s*"?([^"\n]+)"?\s*$/m.exec(actual)?.[1]?.trim();
366
+ }
367
+ if (actual !== expected)
368
+ differing.push(file);
369
+ }
370
+ const status = differing.length === 0 && absent.length === 0 ? 'current' : 'stale';
371
+ return { status, installDir, packageVersion, installedVersion, differing, absent };
372
+ }
373
+ /** Human-readable form of a check, for the CLI. */
374
+ export function formatSkillCheck(result) {
375
+ const lines = [];
376
+ switch (result.status) {
377
+ case 'missing':
378
+ lines.push(`No skill installed at ${result.installDir}`);
379
+ lines.push(`Install it with: coaia skill install`);
380
+ break;
381
+ case 'current':
382
+ lines.push(`Skill at ${result.installDir} is current (v${result.packageVersion})`);
383
+ break;
384
+ case 'stale':
385
+ lines.push(`Skill at ${result.installDir} is stale: installed from ` +
386
+ `v${result.installedVersion ?? 'unknown'}, package is v${result.packageVersion}`);
387
+ if (result.absent.length > 0)
388
+ lines.push(` absent: ${result.absent.join(', ')}`);
389
+ if (result.differing.length > 0)
390
+ lines.push(` differs: ${result.differing.join(', ')}`);
391
+ lines.push(`Refresh it with: coaia skill install --force`);
392
+ break;
393
+ }
394
+ return lines.join('\n');
395
+ }
396
+ //# sourceMappingURL=skill.js.map
@@ -0,0 +1 @@
1
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IAAI,CAAC,cAAc,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACzF,KAAK,CAAC,IAAI,CAAC,8CAA8C,CAAC,CAAC;YAC3D,MAAM;IACV,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Directory holding this package's own `package.json`.
3
+ *
4
+ * Anything shipped alongside `dist/` — the packaged skill under `skills/`, the
5
+ * Custom GPT specs, the rispecs — is found from here rather than from
6
+ * `process.cwd()`, which is the caller's directory and says nothing about where
7
+ * the package was installed.
8
+ */
9
+ export declare function getPackageRoot(): string;
1
10
  /** Resolved version of the installed `coaiajs` package. */
2
11
  export declare function getPackageVersion(): string;
3
12
  //# sourceMappingURL=version.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAYA,2DAA2D;AAC3D,wBAAgB,iBAAiB,IAAI,MAAM,CAyB1C"}
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAaA;;;;;;;GAOG;AACH,wBAAgB,cAAc,IAAI,MAAM,CA0BvC;AAED,2DAA2D;AAC3D,wBAAgB,iBAAiB,IAAI,MAAM,CAI1C"}
@@ -1,33 +1,49 @@
1
- // coaiajs/src/version.ts — single source of truth for the runtime version.
2
- // Reads package.json at runtime so the CLI banner, the MCP handshake, and the
3
- // published package can never drift apart again.
1
+ // coaiajs/src/version.ts — single source of truth for the runtime version and the
2
+ // installed package root. Reads package.json at runtime so the CLI banner, the MCP
3
+ // handshake, the packaged skill, and the published package can never drift apart.
4
4
  import { readFileSync } from 'node:fs';
5
5
  import { dirname, join } from 'node:path';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  const PACKAGE_NAME = 'coaiajs';
8
- let cached;
9
- /** Resolved version of the installed `coaiajs` package. */
10
- export function getPackageVersion() {
11
- if (cached)
12
- return cached;
8
+ let cachedVersion;
9
+ let cachedRoot;
10
+ /**
11
+ * Directory holding this package's own `package.json`.
12
+ *
13
+ * Anything shipped alongside `dist/` — the packaged skill under `skills/`, the
14
+ * Custom GPT specs, the rispecs — is found from here rather than from
15
+ * `process.cwd()`, which is the caller's directory and says nothing about where
16
+ * the package was installed.
17
+ */
18
+ export function getPackageRoot() {
19
+ if (cachedRoot)
20
+ return cachedRoot;
13
21
  const here = dirname(fileURLToPath(import.meta.url));
14
22
  // dist/src/version.js -> package root is two levels up.
15
23
  // src/version.ts (ts-node/tsx) -> package root is one level up.
16
- const candidates = [join(here, '..', '..', 'package.json'), join(here, '..', 'package.json')];
17
- for (const candidate of candidates) {
24
+ const candidates = [join(here, '..', '..'), join(here, '..')];
25
+ for (const root of candidates) {
18
26
  let raw;
19
27
  try {
20
- raw = readFileSync(candidate, 'utf8');
28
+ raw = readFileSync(join(root, 'package.json'), 'utf8');
21
29
  }
22
30
  catch {
23
31
  continue; // not at this depth; try the next candidate
24
32
  }
25
33
  const pkg = JSON.parse(raw);
26
34
  if (pkg.name === PACKAGE_NAME && pkg.version) {
27
- cached = pkg.version;
28
- return cached;
35
+ cachedRoot = root;
36
+ cachedVersion = pkg.version;
37
+ return cachedRoot;
29
38
  }
30
39
  }
31
- throw new Error(`Unable to resolve ${PACKAGE_NAME} version: no package.json found near ${here}`);
40
+ throw new Error(`Unable to resolve the ${PACKAGE_NAME} package root: no matching package.json near ${here}`);
41
+ }
42
+ /** Resolved version of the installed `coaiajs` package. */
43
+ export function getPackageVersion() {
44
+ if (cachedVersion)
45
+ return cachedVersion;
46
+ getPackageRoot(); // populates cachedVersion, or throws naming the reason
47
+ return cachedVersion;
32
48
  }
33
49
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,8EAA8E;AAC9E,i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