coaiajs 0.5.0 → 0.5.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.
@@ -0,0 +1,341 @@
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, CORE_TOOLS, STC_TOOLS, NARRATIVE_TOOLS, WAMPUM_TOOLS, KG_TOOLS, } from './narrative/index.js';
29
+ export const SKILL_NAME = 'coaiajs';
30
+ /**
31
+ * Files that make up the skill, in the order a reader meets them.
32
+ *
33
+ * Listed explicitly rather than discovered by walking the directory: a stray file
34
+ * under `skills/` should not silently become part of what gets installed, and a
35
+ * missing one should be an error rather than a quietly shorter skill.
36
+ */
37
+ export const SKILL_FILES = [
38
+ 'SKILL.md',
39
+ 'references/creative-orientation.md',
40
+ 'references/structural-tension-charting.md',
41
+ 'references/delayed-resolution.md',
42
+ 'references/narrative-beats.md',
43
+ 'references/wampum-belts.md',
44
+ 'references/reading-the-store.md',
45
+ 'references/beyond-narrative.md',
46
+ 'references/mcp-tools.md',
47
+ 'references/install-and-environment.md',
48
+ ];
49
+ /** Directory inside the package holding the skill's markdown. */
50
+ export function getPackagedSkillDir() {
51
+ return join(getPackageRoot(), 'skills', SKILL_NAME);
52
+ }
53
+ // ─── Tool map generation ──────────────────────────────────────────────
54
+ /**
55
+ * Abbreviations whose trailing period does not end a sentence. Without these,
56
+ * `open_nodes` — whose description reads "…by exact name (e.g. 'chart_123_chart')" —
57
+ * rendered as "Open specific entity nodes by exact name (e.g." in the table, which
58
+ * reads as a truncation bug rather than as a description.
59
+ */
60
+ const NON_TERMINAL_ABBREVIATIONS = ['e.g', 'i.e', 'etc', 'vs', 'cf', 'approx', 'no'];
61
+ /**
62
+ * One line of description, trimmed to something a table cell can hold.
63
+ *
64
+ * Leading emphasis markers ("🚨 NEW LLM?", "✨ RECOMMENDED:", "⚠️ DEPRECATED:") are kept
65
+ * deliberately — they carry the tool's own stance about itself, and a map that hides a
66
+ * deprecation is worse than one that shows it.
67
+ */
68
+ function shortDescription(description) {
69
+ const collapsed = description.replace(/\s+/g, ' ').trim();
70
+ // Cut at the first period that actually ends a sentence: followed by whitespace and
71
+ // something that starts one, and not preceded by an abbreviation or a single letter.
72
+ let sentence = collapsed;
73
+ for (const match of collapsed.matchAll(/\.(?=\s+[A-Z0-9`'"(\u{1F300}-\u{1FAFF}])/gu)) {
74
+ const before = collapsed.slice(0, match.index);
75
+ const lastWord = (/([A-Za-z.]+)$/.exec(before)?.[1] ?? '').toLowerCase();
76
+ if (NON_TERMINAL_ABBREVIATIONS.includes(lastWord))
77
+ continue;
78
+ if (/^[a-z]$/.test(lastWord))
79
+ continue; // an initial, not a sentence end
80
+ sentence = collapsed.slice(0, match.index + 1);
81
+ break;
82
+ }
83
+ const escaped = sentence.replace(/\|/g, '\\|');
84
+ return escaped.length > 180 ? `${escaped.slice(0, 177)}…` : escaped;
85
+ }
86
+ const TOOL_GROUP_ORDER = [
87
+ { title: 'Start here', names: CORE_TOOLS },
88
+ { title: 'Structural tension charts', names: STC_TOOLS },
89
+ { title: 'Narrative beats', names: NARRATIVE_TOOLS },
90
+ { title: 'Wampum belts', names: WAMPUM_TOOLS },
91
+ { title: 'Knowledge graph', names: KG_TOOLS },
92
+ ];
93
+ /**
94
+ * Render the narrative tool surface as grouped markdown tables, from the definitions
95
+ * the MCP server actually registers. A tool that belongs to no group still appears,
96
+ * under "Other" — a tool silently absent from its own map is the drift this avoids.
97
+ */
98
+ export function renderToolMap() {
99
+ const byName = new Map(ALL_TOOL_DEFINITIONS.map(t => [t.name, t]));
100
+ const placed = new Set();
101
+ const sections = [];
102
+ for (const group of TOOL_GROUP_ORDER) {
103
+ const rows = [];
104
+ for (const name of group.names) {
105
+ const tool = byName.get(name);
106
+ if (!tool || placed.has(name))
107
+ continue;
108
+ placed.add(name);
109
+ rows.push(`| \`${name}\` | ${shortDescription(tool.description)} |`);
110
+ }
111
+ if (rows.length === 0)
112
+ continue;
113
+ sections.push(`### ${group.title}\n\n| Tool | Use |\n|---|---|\n${rows.join('\n')}`);
114
+ }
115
+ const leftover = ALL_TOOL_DEFINITIONS.filter(t => !placed.has(t.name));
116
+ if (leftover.length > 0) {
117
+ const rows = leftover.map(t => `| \`${t.name}\` | ${shortDescription(t.description)} |`);
118
+ sections.push(`### Other\n\n| Tool | Use |\n|---|---|\n${rows.join('\n')}`);
119
+ }
120
+ return sections.join('\n\n');
121
+ }
122
+ // ─── Rendering ────────────────────────────────────────────────────────
123
+ /** Placeholders a packaged skill file may carry. */
124
+ function substitutions() {
125
+ return {
126
+ VERSION: getPackageVersion(),
127
+ // The narrative/chart surface only. The server also serves Langfuse, PDE, and
128
+ // planning tools, and counting those here would mean importing the MCP feature
129
+ // config into the library — see references/beyond-narrative.md instead.
130
+ NARRATIVE_TOOL_COUNT: String(ALL_TOOL_DEFINITIONS.length),
131
+ TOOL_MAP: renderToolMap(),
132
+ };
133
+ }
134
+ function applySubstitutions(content, values) {
135
+ return content.replace(/\{\{([A-Z_]+)\}\}/g, (whole, key) => {
136
+ const value = values[key];
137
+ if (value === undefined) {
138
+ throw new Error(`Packaged skill carries an unknown placeholder {{${key}}}. ` +
139
+ `Add it to substitutions() in src/skill.ts or remove it from the markdown.`);
140
+ }
141
+ return value;
142
+ });
143
+ }
144
+ /** Read one packaged skill file and fill its placeholders. */
145
+ export function renderSkillFile(relativeFilePath) {
146
+ const source = join(getPackagedSkillDir(), relativeFilePath);
147
+ let raw;
148
+ try {
149
+ raw = readFileSync(source, 'utf8');
150
+ }
151
+ catch {
152
+ throw new Error(`Packaged skill file missing: ${source}. ` +
153
+ `The published package must ship skills/ — check the "files" field in package.json.`);
154
+ }
155
+ return applySubstitutions(raw, substitutions());
156
+ }
157
+ /** Every skill file, rendered, keyed by its path within the skill directory. */
158
+ export function renderSkill() {
159
+ const values = substitutions();
160
+ const rendered = new Map();
161
+ for (const file of SKILL_FILES) {
162
+ const source = join(getPackagedSkillDir(), file);
163
+ let raw;
164
+ try {
165
+ raw = readFileSync(source, 'utf8');
166
+ }
167
+ catch {
168
+ throw new Error(`Packaged skill file missing: ${source}. ` +
169
+ `The published package must ship skills/ — check the "files" field in package.json.`);
170
+ }
171
+ rendered.set(file, applySubstitutions(raw, values));
172
+ }
173
+ return rendered;
174
+ }
175
+ // ─── Install locations ────────────────────────────────────────────────
176
+ export function getSkillInstallDir(globalInstall) {
177
+ return globalInstall
178
+ ? resolve(homedir(), '.agents', 'skills', SKILL_NAME)
179
+ : resolve(process.cwd(), '.agents', 'skills', SKILL_NAME);
180
+ }
181
+ export function getClaudeSkillLinkPath(globalInstall) {
182
+ return globalInstall
183
+ ? resolve(homedir(), '.claude', 'skills', SKILL_NAME)
184
+ : resolve(process.cwd(), '.claude', 'skills', SKILL_NAME);
185
+ }
186
+ function pathExists(pathName) {
187
+ try {
188
+ lstatSync(pathName);
189
+ return true;
190
+ }
191
+ catch {
192
+ return false;
193
+ }
194
+ }
195
+ function removePath(pathName) {
196
+ const stat = lstatSync(pathName);
197
+ if (stat.isDirectory() && !stat.isSymbolicLink()) {
198
+ rmSync(pathName, { recursive: true, force: true });
199
+ }
200
+ else {
201
+ unlinkSync(pathName);
202
+ }
203
+ }
204
+ function writeRenderedSkill(targetDir, force) {
205
+ // Render before touching anything on disk: a missing packaged file must not leave
206
+ // a half-written skill where a whole one used to be.
207
+ const rendered = renderSkill();
208
+ if (pathExists(targetDir)) {
209
+ if (!force) {
210
+ throw new Error(`Skill already exists: ${targetDir} (use --force to replace it)`);
211
+ }
212
+ removePath(targetDir);
213
+ }
214
+ mkdirSync(targetDir, { recursive: true });
215
+ for (const [file, content] of rendered) {
216
+ const destination = resolve(targetDir, file);
217
+ mkdirSync(dirname(destination), { recursive: true });
218
+ writeFileSync(destination, content, 'utf-8');
219
+ }
220
+ }
221
+ function ensureClaudeSymlink(linkPath, targetDir, force) {
222
+ const parentDir = dirname(linkPath);
223
+ if (pathExists(parentDir)) {
224
+ const resolvedTargetParent = realpathSync(dirname(targetDir));
225
+ const resolvedLinkParent = realpathSync(parentDir);
226
+ // Already the same directory — Claude sees the skill without a link.
227
+ if (resolvedTargetParent === resolvedLinkParent) {
228
+ return false;
229
+ }
230
+ }
231
+ const linkTarget = relativePath(parentDir, targetDir) || '.';
232
+ mkdirSync(parentDir, { recursive: true });
233
+ if (pathExists(linkPath)) {
234
+ const stat = lstatSync(linkPath);
235
+ if (stat.isSymbolicLink() && readlinkSync(linkPath) === linkTarget) {
236
+ return true;
237
+ }
238
+ if (!force) {
239
+ throw new Error(`Claude skill path already exists: ${linkPath} (use --force to replace it)`);
240
+ }
241
+ removePath(linkPath);
242
+ }
243
+ symlinkSync(linkTarget, linkPath, 'dir');
244
+ return true;
245
+ }
246
+ async function shouldCreateClaudeSymlink(linkPath, autoYes) {
247
+ if (autoYes)
248
+ return true;
249
+ if (!process.stdin.isTTY || !process.stdout.isTTY) {
250
+ console.log(`Tip: create a Claude symlink manually at ${linkPath}`);
251
+ return false;
252
+ }
253
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
254
+ try {
255
+ const answer = await rl.question(`Create a symlink in ${linkPath}? [y/N] `);
256
+ const normalized = answer.trim().toLowerCase();
257
+ return normalized === 'y' || normalized === 'yes';
258
+ }
259
+ finally {
260
+ rl.close();
261
+ }
262
+ }
263
+ // ─── Commands ─────────────────────────────────────────────────────────
264
+ /** Print the packaged SKILL.md, rendered. */
265
+ export function showSkill() {
266
+ process.stdout.write(renderSkillFile('SKILL.md'));
267
+ }
268
+ export async function installSkill(options = {}) {
269
+ const globalInstall = options.global === true;
270
+ const installDir = getSkillInstallDir(globalInstall);
271
+ writeRenderedSkill(installDir, options.force === true);
272
+ console.log(`Installed the coaiajs skill (v${getPackageVersion()}) to ${installDir}`);
273
+ const claudeLinkPath = getClaudeSkillLinkPath(globalInstall);
274
+ if (await shouldCreateClaudeSymlink(claudeLinkPath, options.yes === true)) {
275
+ const linked = ensureClaudeSymlink(claudeLinkPath, installDir, options.force === true);
276
+ console.log(linked
277
+ ? `Linked Claude skill at ${claudeLinkPath}`
278
+ : `Claude already sees the skill via ${dirname(claudeLinkPath)}`);
279
+ }
280
+ return installDir;
281
+ }
282
+ /**
283
+ * Compare an installed skill against the packaged one.
284
+ *
285
+ * The failure this exists for is silent: a skill installed by an older `coaiajs`
286
+ * describes an older tool surface, sits there looking authoritative, and nothing in
287
+ * the normal flow ever says so. An agent then reads a tool map that no longer matches
288
+ * the server it is talking to.
289
+ */
290
+ export function checkSkill(options = {}) {
291
+ const installDir = getSkillInstallDir(options.global === true);
292
+ const packageVersion = getPackageVersion();
293
+ if (!pathExists(installDir)) {
294
+ return { status: 'missing', installDir, packageVersion, differing: [], absent: [...SKILL_FILES] };
295
+ }
296
+ const rendered = renderSkill();
297
+ const differing = [];
298
+ const absent = [];
299
+ let installedVersion;
300
+ for (const [file, expected] of rendered) {
301
+ let actual;
302
+ try {
303
+ actual = readFileSync(resolve(installDir, file), 'utf8');
304
+ }
305
+ catch {
306
+ absent.push(file);
307
+ continue;
308
+ }
309
+ if (file === 'SKILL.md') {
310
+ installedVersion = /^\s*packageVersion:\s*"?([^"\n]+)"?\s*$/m.exec(actual)?.[1]?.trim();
311
+ }
312
+ if (actual !== expected)
313
+ differing.push(file);
314
+ }
315
+ const status = differing.length === 0 && absent.length === 0 ? 'current' : 'stale';
316
+ return { status, installDir, packageVersion, installedVersion, differing, absent };
317
+ }
318
+ /** Human-readable form of a check, for the CLI. */
319
+ export function formatSkillCheck(result) {
320
+ const lines = [];
321
+ switch (result.status) {
322
+ case 'missing':
323
+ lines.push(`No skill installed at ${result.installDir}`);
324
+ lines.push(`Install it with: coaia skill install`);
325
+ break;
326
+ case 'current':
327
+ lines.push(`Skill at ${result.installDir} is current (v${result.packageVersion})`);
328
+ break;
329
+ case 'stale':
330
+ lines.push(`Skill at ${result.installDir} is stale: installed from ` +
331
+ `v${result.installedVersion ?? 'unknown'}, package is v${result.packageVersion}`);
332
+ if (result.absent.length > 0)
333
+ lines.push(` absent: ${result.absent.join(', ')}`);
334
+ if (result.differing.length > 0)
335
+ lines.push(` differs: ${result.differing.join(', ')}`);
336
+ lines.push(`Refresh it with: coaia skill install --force`);
337
+ break;
338
+ }
339
+ return lines.join('\n');
340
+ }
341
+ //# sourceMappingURL=skill.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skill.js","sourceRoot":"","sources":["../../src/skill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EACL,SAAS,EACT,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,MAAM,EACN,WAAW,EACX,UAAU,EACV,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAA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
+ * 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,iDAAiD;AAEjD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,YAAY,GAAG,SAAS,CAAC;AAE/B,IAAI,MAA0B,CAAC;AAE/B,2DAA2D;AAC3D,MAA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AAC;AAEnC;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc;IAC5B,IAAI,UAAU;QAAE,OAAO,UAAU,CAAC;IAElC,MAAM,IAAI,GAAG,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,wDAAwD;IACxD,gEAAgE;IAChE,MAAM,UAAU,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IAE9D,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;QAC9B,IAAI,GAAW,CAAC;QAChB,IAAI,CAAC;YACH,GAAG,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,MAAM,CAAC,CAAC;QACzD,CAAC;QAAC,MAAM,CAAC;YACP,SAAS,CAAC,4CAA4C;QACxD,CAAC;QACD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAwC,CAAC;QACnE,IAAI,GAAG,CAAC,IAAI,KAAK,YAAY,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC;YAC7C,UAAU,GAAG,IAAI,CAAC;YAClB,aAAa,GAAG,GAAG,CAAC,OAAO,CAAC;YAC5B,OAAO,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;IAED,MAAM,IAAI,KAAK,CACb,yBAAyB,YAAY,gDAAgD,IAAI,EAAE,CAC5F,CAAC;AACJ,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,iBAAiB;IAC/B,IAAI,aAAa;QAAE,OAAO,aAAa,CAAC;IACxC,cAAc,EAAE,CAAC,CAAC,uDAAuD;IACzE,OAAO,aAAuB,CAAC;AACjC,CAAC"}
@@ -0,0 +1,150 @@
1
+ # Lineage: coaia-narrative → coaiajs
2
+
3
+ ## What the relationship is
4
+
5
+ `coaiajs` is the package we maintain. `avadisabelle/coaia-narrative` is where several of
6
+ these ideas were first built and several of these bugs were first paid for.
7
+
8
+ That makes this a **one-way port, not a mirror**. We read that repository for corrections
9
+ worth carrying, we decide what shape they take here, and we own the result. Nothing in
10
+ this package is expected to stay byte-identical to anything over there, and a future
11
+ instance should not treat a difference as drift to be undone.
12
+
13
+ The direction never reverses. We do not push changes back, and we do not wait on that
14
+ repository before fixing something here.
15
+
16
+ ## Ported through
17
+
18
+ | | |
19
+ |---|---|
20
+ | Upstream repo | `avadisabelle/coaia-narrative` (`git@github.com:avadisabelle/coaia-narrative.git`) |
21
+ | Original snapshot taken at | `12c60f8` (2026-03-08) — landed here as `d6a544e`, 2026-03-11 |
22
+ | **Ported through** | **`68f6e2f`** — merge of PR #55, upstream v0.16.2, 2026-08-11 |
23
+ | Landed here as | `03658fa` (narrative parity) and the commit adding this file |
24
+ | Tracking issue | jgwill/coaiajs#13 |
25
+
26
+ **Update the "Ported through" row in the same commit that lands the next port.** It is the
27
+ only record of where the last one stopped, and a port that does not update it costs the
28
+ next instance the whole diff again.
29
+
30
+ ## How to find the next port
31
+
32
+ ```bash
33
+ UPSTREAM=/path/to/coaia-narrative # or: git clone git@github.com:avadisabelle/coaia-narrative.git
34
+ PORTED_THROUGH=68f6e2f
35
+
36
+ cd "$UPSTREAM" && git fetch --all
37
+
38
+ # What changed in code since we last looked
39
+ git diff --stat "$PORTED_THROUGH..origin/main" -- '*.ts'
40
+
41
+ # Release-shaped commits carry their reason in the subject line — read these first,
42
+ # they are usually one measured failure each
43
+ git log --oneline "$PORTED_THROUGH..origin/main"
44
+
45
+ # The full text of one change, with its comments, which is where the reasoning lives
46
+ git show <sha>
47
+ ```
48
+
49
+ Upstream writes its commit subjects as the failure that was found, not as the change that
50
+ was made ("a --memory-path carrying an unexpanded shell variable is refused"). Read the
51
+ subject lines before the diff — they tell you which changes carry a real finding and which
52
+ are packaging.
53
+
54
+ ## How to port
55
+
56
+ The two trees are not diff-compatible. When the March snapshot was taken it was
57
+ reformatted (single quotes, trailing commas, prettier widths), types were moved to
58
+ `src/types.ts`, and `LLM_GUIDANCE` was inlined. `git apply` will not work and should not
59
+ be attempted. Port **semantically**: read the upstream change, understand the finding
60
+ behind it, then write it here in this codebase's shape.
61
+
62
+ Rules that have held so far:
63
+
64
+ 1. **Carry the reasoning, not just the code.** Upstream comments name the date, the
65
+ measurement, and the cost of the bug. Those comments are the most valuable part of the
66
+ change — a future reader who does not know why a guard exists will delete it. Rewrite
67
+ them for this package's context rather than dropping them.
68
+ 2. **Adapt anything that names the other package.** Binary names, MCP server names,
69
+ environment variables, and example issue references all differ. A copy that still says
70
+ `cnarrative` or `COAIA_TOOLS` is wrong here even if it compiles.
71
+ 3. **Put the change where this codebase already puts that kind of thing.** Shared types go
72
+ in `src/types.ts`, not a per-module types file. The memory-path guard belongs in the
73
+ `KnowledgeGraphManager` constructor here, because that covers the CLI, the MCP server,
74
+ and library consumers at once — upstream put it in its single entry point because that
75
+ is all it has.
76
+ 4. **Write a test per finding.** `tests/narrative-parity.test.js` is organised as one
77
+ `describe` per finding, named for the behaviour it holds. A ported correction with no
78
+ test is a correction that will be un-ported by the next refactor.
79
+ 5. **Update the docs in the same commit.** `test/docs.test.mjs` fails the build when
80
+ `README.md` / `llms.txt` / `llms-full.txt` disagree with the served tool surface, so
81
+ this is enforced, not optional.
82
+
83
+ ## What has been adapted rather than copied
84
+
85
+ ### The skill (`src/skill.ts`, `skills/coaiajs/`)
86
+
87
+ Upstream ships `cnarrative skill show|install`. We ship `coaia skill show|install|check`.
88
+ Four deliberate differences:
89
+
90
+ | | upstream | here | why |
91
+ |---|---|---|---|
92
+ | Content location | ~250 lines of markdown as a TypeScript string array | real `.md` files under `skills/coaiajs/`, shipped via `files` | a doc change should read as a doc diff, and markdown tooling should be able to see it |
93
+ | Tool map | hand-written table | generated from `ALL_TOOL_DEFINITIONS` at render time | a hand-written map advertises tools the server does not serve the moment one is added |
94
+ | Subject | `coaia-narrative`, `cnarrative`, `COAIA_TOOLS` | `coaiajs`, `coaia`, `coaiajs-mcp`, `COAIAJS_FEATURES` | it has to describe the surface it actually installs next to |
95
+ | Staleness | not detectable | `coaia skill check`, plus `packageVersion` in the installed frontmatter | a skill installed by an older version describes an older surface and nothing else says so |
96
+
97
+ The reference set is also larger, because this package has more surface: `wampum-belts.md`,
98
+ `reading-the-store.md`, and `beyond-narrative.md` (PDE, planning, Langfuse, pipeline) have
99
+ no upstream counterpart.
100
+
101
+ **If upstream changes its skill content, do not copy the change in.** Read what it learned
102
+ and decide whether it applies to our surface. These are two skills describing two packages.
103
+
104
+ ### The read contract subpath
105
+
106
+ Upstream publishes `coaia-narrative/contract` because its package root **is** the MCP
107
+ server bootstrap — importing it starts a stdio server, so a renderer must have a separate
108
+ door. Our root is a plain library and has no such hazard. We publish
109
+ `coaiajs/narrative/contract` anyway, because the other reason holds: a renderer should be
110
+ able to pull the store's shape without pulling the whole package.
111
+
112
+ ## Deliberately not ported
113
+
114
+ | Upstream | Why not |
115
+ |---|---|
116
+ | `index.ts` / `cli.ts` entry points | We have our own, with a different command surface and argument style |
117
+ | `generated-llm-guidance.ts` | Inlined here as `LLM_GUIDANCE_FULL` / `_QUICK` / `_SAVE_DIRECTIVE` in `src/narrative/tool-handlers.ts` |
118
+ | `src/help.ts`, `src/tool-groups.ts` | Commander provides help; the groups live in `src/narrative/tool-definitions.ts` |
119
+ | `handlers/` (push, issues, ceremony, story-engine) | Webhook event handlers for that repo's deployment, not library capability |
120
+ | `types.ts`'s `Direction = 'EAST' \| 'SOUTH' \| ...` | Unused upstream, and the name is already taken here by the PDE lowercase direction type |
121
+ | `scripts/check-schema-parity.cjs` | Bound to that repo's `schema/` fixtures |
122
+
123
+ Revisit any of these if the reason stops being true. Record the decision here when you do.
124
+
125
+ ## Where this package is deliberately ahead or different
126
+
127
+ Do not "correct" these back toward upstream:
128
+
129
+ - **`setDueDate` goes through `updateChartDueDate`.** It used to re-serialise the store by
130
+ hand with `writeFileSync`, which ignored `--memory-path` and dropped unmodelled fields.
131
+ - **The memory-path guard is in the constructor**, so it covers library consumers, not only
132
+ a CLI entry point.
133
+ - **`mcp/server.ts` catches that guard** and exits 1 with a one-line refusal rather than an
134
+ unhandled throw.
135
+ - **`src/version.ts` exports `getPackageRoot()`**, which is how anything shipped beside
136
+ `dist/` (the skill, the Custom GPT specs) is located. Do not reach for `process.cwd()`.
137
+ - **Tool counts in the docs are enforced by `test/docs.test.mjs`.** Upstream has no
138
+ equivalent; do not relax ours to match.
139
+
140
+ ## Checklist for the next port
141
+
142
+ - [ ] `git log --oneline <PORTED_THROUGH>..origin/main` in the upstream checkout; read the subjects
143
+ - [ ] `git diff --stat <PORTED_THROUGH>..origin/main -- '*.ts'`
144
+ - [ ] For each change: is it a finding, packaging, or entry-point specific?
145
+ - [ ] Port the findings semantically, carrying their reasoning as comments
146
+ - [ ] One `describe` block per finding in `tests/narrative-parity.test.js`
147
+ - [ ] `npm run build && npm test` — the docs suite will catch a stale tool count
148
+ - [ ] `coaia skill check` after a local install, if the tool surface changed
149
+ - [ ] Update **Ported through** above, and the "not ported" table if a decision changed
150
+ - [ ] Bump the version, publish, and note the upstream range in the commit body