breakaway 1.0.2-main.3 → 1.0.2-main.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "breakaway",
3
- "version": "1.0.2-main.3",
3
+ "version": "1.0.2-main.5",
4
4
  "description": "The task board for you and your coding agents: a Cloudflare Worker, its web app, Taskwarrior sync, and the CLI (npx breakaway).",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "type": "module",
@@ -14,10 +14,10 @@ const DEFAULT_DIR = '~/.config/breakaway';
14
14
  export { routinePrompt };
15
15
 
16
16
  /**
17
- * The CLI on npm (BRK-7), as a repository runs it: `npx breakaway`. Pinned to the `next` channel until the first stable
18
- * release exists; then this becomes the major (`breakaway@1`), so a breaking change never reaches a repository by itself.
17
+ * The CLI on npm (BRK-7), as a repository runs it: `npx breakaway`, pinned to the major (BRK-47), so a breaking change
18
+ * never reaches a repository by itself. It was the `next` channel until the first stable release.
19
19
  */
20
- export const CLI_PACKAGE = 'breakaway@next';
20
+ export const CLI_PACKAGE = 'breakaway@1';
21
21
  /**
22
22
  * Where the CLI starts: the command, and the two session hooks. repos init no longer copies them (BRK-7): an old copy
23
23
  * is replaced by npx, and these still version the CLI and say which files an old copy holds.
@@ -49,6 +49,11 @@ const ADAPTED = ['taskrc', 'scripts/task', SKILL];
49
49
  * sit at the root, so the paths `read` takes are the board's; what is written keeps this folder.
50
50
  */
51
51
  const TARGET_DIR = 'tools/tasks/';
52
+ /**
53
+ * The record of what repos init wrote into a repository (BRK-79): `--update` replaces a copied file only when it's
54
+ * listed here, or sits in TARGET_DIR, breakaway's own folder. Anything else at a path it copies to is the repository's.
55
+ */
56
+ export const MANIFEST = `${TARGET_DIR}copied.json`;
52
57
  const GITIGNORE = ['.task/', '.task-session', '.env'];
53
58
  /** Pinned to LF so the shell scripts run on a checkout with core.autocrlf=true (BRK-41). */
54
59
  const GITATTRIBUTES = ['scripts/task text eol=lf', '.envrc text eol=lf'];
@@ -134,7 +139,10 @@ export function sessionHooks(pkg = CLI_PACKAGE) {
134
139
  };
135
140
  }
136
141
 
137
- /** settings.json with the session hooks' commands (either form) set to the current one; the rest is untouched. */
142
+ /**
143
+ * settings.json with the session hooks' commands set to the current one, whichever form they had: the copy's, or npx
144
+ * with an earlier channel or version of the package (`breakaway@next` before BRK-47). The rest is untouched.
145
+ */
138
146
  export function rewireHooks(text) {
139
147
  let out = text;
140
148
  for (const name of ['session', 'wait'])
@@ -143,7 +151,28 @@ export function rewireHooks(text) {
143
151
  const now = JSON.stringify(hookCommand(name)).slice(1, -1);
144
152
  out = out.split(was).join(now);
145
153
  }
146
- return out;
154
+ const current = (_, name) => JSON.stringify(hookCommand(name === 'message-wait' ? 'wait' : name)).slice(1, -1);
155
+ return (
156
+ out
157
+ .replace(/npx --yes breakaway(?:@[^\s"\\]+)? hook (session|wait)\b/gu, current)
158
+ // The old CLI copy's hook scripts, from before BRK-7, quoted or not (BRK-79): its copy is about to go.
159
+ .replace(
160
+ /node (\\")?(?:\$CLAUDE_PROJECT_DIR\/)?(?:tools\/tasks\/cli\/)?scripts\/tasks\/(session-hook|message-wait)\.mjs\1/gu,
161
+ (_, _q, name) => current(_, name === 'session-hook' ? 'session' : name),
162
+ )
163
+ );
164
+ }
165
+
166
+ /**
167
+ * The paths a repository's AGENTS.md says came from the board, in its "Copied files." bullet as any version of repos
168
+ * init wrote it; a folder ends in `/`. None when AGENTS.md is the repository's own (BRK-79).
169
+ */
170
+ export function declaredCopies(agents) {
171
+ const line = String(agents ?? '')
172
+ .split('\n')
173
+ .find((l) => /^- \*\*Copied files\.\*\*/u.test(l));
174
+ if (!line) return [];
175
+ return [...line.split(/ come from \[/u)[0].matchAll(/`([^`]+)`/gu)].map((m) => m[1]);
147
176
  }
148
177
 
149
178
  /** A short SHA-256 of `paths` and their text: changes whenever one of them does. */
@@ -261,10 +290,20 @@ export function promptSections(given = {}) {
261
290
  }
262
291
 
263
292
  /** The `tasks` skill for another repository: links into the board's docs point at them on GitHub. */
264
- export function skillFor(text, board) {
265
- return String(text)
293
+ export function skillFor(text, board, repo = null) {
294
+ const linked = String(text)
266
295
  .replace(/\]\((?:\.\.\/)+((?:docs|tools)\/[^)]+)\)/gu, `](https://github.com/${board}/blob/main/$1)`)
267
296
  .replace(/\]\(((?:\.\.\/)+)prompts\//gu, ']($1tools/tasks/prompts/');
297
+ if (!repo) return linked;
298
+ // The skill is breakaway's own: in another repository it names that repository's work, areas, and prompt (BRK-79).
299
+ const prompt = promptPathOf(repo);
300
+ return linked
301
+ .replace(/breakaway's work is on the board/gu, "This repository's work is on the board")
302
+ .replace(/breakaway's areas: [^.\n]+\./gu, `This repository's areas: ${areaList(repo)}.`)
303
+ .replace(
304
+ /\[`prompts\/breakaway\.md`\]\(((?:\.\.\/)+)tools\/tasks\/prompts\/breakaway\.md\)/gu,
305
+ (_, up) => `[\`${prompt}\`](${up}${prompt})`,
306
+ );
268
307
  }
269
308
 
270
309
  /** A starter AGENTS.md: how this repository works with the board. The owner adds how to build here. */
@@ -273,9 +312,9 @@ export function agentsMd(repo, board, dir = DEFAULT_DIR) {
273
312
 
274
313
  <!-- Started by \`npx breakaway repos init\` (breakaway's task board). Add how to build here: setup, tests, style, and anything agents must never do. -->
275
314
 
276
- - **Work lives on the task board.** This repository's tasks are in the areas ${areaList(repo)}. Use the \`tasks\` skill (\`${SKILL}\`) and the CLI, \`npx breakaway\` (the \`breakaway\` package on npm), to claim, comment, and hand over. It works in this checkout's repository, so \`list\` and \`next\` show only this repository's tasks. The skill is breakaway's copy: where it names breakaway's own files or rules, the board's part applies and the rest doesn't.
315
+ - **Work lives on the task board.** This repository's tasks are in the areas ${areaList(repo)}. Use the \`tasks\` skill (\`${SKILL}\`) and the CLI, \`npx breakaway\` (the \`breakaway\` package on npm), to claim, comment, and hand over. It works in this checkout's repository, so \`list\` and \`next\` show only this repository's tasks. The skill is breakaway's, written for this repository's areas and prompt: where it names breakaway's own files or rules, the board's part applies and the rest doesn't.
277
316
  - **Agents started by the board** follow [\`${promptPathOf(repo)}\`](${promptPathOf(repo)}), which starts with the board's core, \`tools/tasks/prompts/core.md\`.
278
- - **Copied files.** \`tools/tasks/\`, the release helpers in \`scripts/\`, and \`${SKILL}\` come from [${board}](https://github.com/${board}). Don't edit them here: change them there. \`.claude/settings.json\` holds the session hooks that show a cloud agent's output on its task, and they run through \`npx\`, so this repository carries no copy of the CLI.
317
+ - **Copied files.** \`tools/tasks/\`, the release helpers in \`scripts/\`, and \`${SKILL}\` come from [${board}](https://github.com/${board}). Don't edit them here: change them there. \`${MANIFEST}\` lists every file it copied, and \`repos init --update\` replaces only those: a file it doesn't list is this repository's own, even at a path breakaway copies to. \`.claude/settings.json\` holds the session hooks that show a cloud agent's output on its task, and they run through \`npx\`, so this repository carries no copy of the CLI.
279
318
  - **Taskwarrior** (optional): \`scripts/task\`, or plain \`task\` with direnv after \`direnv allow\`, uses the board with this checkout's own \`.task/\` database, in the \`${repo.slug}\` context. \`npx breakaway setup\` connects the machine once.
280
319
  - **Changes reach \`${repo.defaultBranch || 'main'}\` through pull requests**, which the owner merges. Never merge, force-push, or rewrite \`${repo.defaultBranch || 'main'}\`.
281
320
  - **Never put a secret or token** in a file, task, comment, or pull request. The board's token lives in \`${dir}/tasks.env\` (or \`$BREAKAWAY_HOME/tasks.env\`) or the cloud environment's credentials, never in this repository.
@@ -338,13 +377,46 @@ export function initPlan({
338
377
  if (readTarget(path) !== null) skipped.push(path);
339
378
  else files.push({ path, content, ...extra });
340
379
  };
341
- /** A file copied from the board: added when it's missing, and with `update`, replaced when it differs. */
380
+ // What an earlier run recorded writing (BRK-79): null for a repository set up before the record existed.
381
+ const recorded = (() => {
382
+ try {
383
+ const files = JSON.parse(readTarget(MANIFEST) ?? 'null')?.files;
384
+ return Array.isArray(files) ? new Set(files) : null;
385
+ } catch {
386
+ return null;
387
+ }
388
+ })();
389
+ // Set up before the record: the AGENTS.md repos init wrote says the copied files came from the board, and a
390
+ // repository's own AGENTS.md doesn't, so only then are files at the copied paths breakaway's.
391
+ const declared = recorded === null ? declaredCopies(readTarget('AGENTS.md')) : [];
392
+ /** Whether repos init wrote `path` here: in breakaway's own folder, on the record, or in AGENTS.md's copied files. */
393
+ const owns = (path) =>
394
+ path.startsWith(TARGET_DIR) ||
395
+ Boolean(recorded?.has(path)) ||
396
+ declared.some((d) => (d.endsWith('/') ? path.startsWith(d) : path === d));
397
+ const ours = new Set();
398
+ const theirs = [];
399
+ /**
400
+ * A file copied from the board: added when it's missing, and with `update`, replaced when it differs, but only when
401
+ * repos init wrote it (the record lists it, or it's in breakaway's own folder). A repository's own file at a path
402
+ * breakaway copies to is left alone (BRK-79).
403
+ */
342
404
  const copy = (path, content, extra = {}) => {
343
405
  const there = readTarget(path);
344
- if (there === null) files.push({ path, content, ...extra });
345
- else if (!update) skipped.push(path);
346
- else if (there === content) current.push(path);
347
- else files.push({ path, content, ...extra, changed: true });
406
+ if (there === null) {
407
+ files.push({ path, content, ...extra });
408
+ ours.add(path);
409
+ } else if (there === content) {
410
+ (update ? current : skipped).push(path);
411
+ ours.add(path);
412
+ } else if (!update) skipped.push(path);
413
+ else if (owns(path)) {
414
+ files.push({ path, content, ...extra, changed: true });
415
+ ours.add(path);
416
+ } else {
417
+ skipped.push(path);
418
+ theirs.push(path);
419
+ }
348
420
  };
349
421
 
350
422
  const prompt = promptPathOf(repo);
@@ -357,7 +429,14 @@ export function initPlan({
357
429
  }
358
430
  for (const path of COPIED) copy(TARGET_DIR + path, read(path));
359
431
  copy(`${TARGET_DIR}taskrc`, withRepoInTaskrc(read('taskrc'), repo.slug, Boolean(repo.isDefault)));
360
- for (const path of importClosure(RELEASE_ENTRIES, read)) copy(path, read(path));
432
+ // A release helper the repository keeps as its own doesn't bring the files breakaway's version imports (BRK-79).
433
+ const kept = (entry) => {
434
+ const there = readTarget(entry);
435
+ return there === null || there === read(entry) || (update && owns(entry));
436
+ };
437
+ const needed = new Set(importClosure(RELEASE_ENTRIES.filter(kept), read));
438
+ for (const path of importClosure(RELEASE_ENTRIES, read))
439
+ if (needed.has(path) || readTarget(path) !== null) copy(path, read(path));
361
440
  if (HOOKS_FROM_COPY) for (const path of importClosure(HOOK_ENTRIES, read)) copy(HOOKS_DIR + path, read(path));
362
441
  // An old copy of the CLI is replaced by npx: with update, its files go. The src/ files it imported may be the
363
442
  // repository's own by now, so those are only named.
@@ -389,7 +468,7 @@ export function initPlan({
389
468
  );
390
469
  }
391
470
  if (readTarget('.claude/skills') === null) files.push({ path: '.claude/skills', link: '../.agents/skills' });
392
- copy(SKILL, skillFor(read(SKILL), board));
471
+ copy(SKILL, skillFor(read(SKILL), board, repo));
393
472
  add('AGENTS.md', agentsMd(repo, board, configDir));
394
473
  if (!skipped.includes('AGENTS.md')) todo.push('AGENTS.md: add how to build in this repository');
395
474
 
@@ -443,5 +522,43 @@ export function initPlan({
443
522
  append: attributes !== null,
444
523
  });
445
524
  }
525
+ // A file the repository still runs stays, with the old copy it belongs to (BRK-79): package.json, or settings the
526
+ // rewiring above couldn't move to npx.
527
+ const settingsNow =
528
+ files.find((f) => f.path === '.claude/settings.json')?.content ?? readTarget('.claude/settings.json');
529
+ const uses = [
530
+ ['package.json', readTarget('package.json')],
531
+ ['.claude/settings.json', settingsNow],
532
+ ];
533
+ for (const group of [(p) => p.startsWith('scripts/'), (p) => p.startsWith(HOOKS_DIR)]) {
534
+ const inGroup = removals.filter(group);
535
+ const used = uses.flatMap(([file, text]) =>
536
+ inGroup.filter((p) => String(text ?? '').includes(p)).map((p) => `${file} still runs ${p}`),
537
+ );
538
+ if (!used.length) continue;
539
+ for (const p of inGroup) removals.splice(removals.indexOf(p), 1);
540
+ notes.push(
541
+ `${used.join('; ')}, so its copy stays: switch it to npx breakaway (\`${hookCommand('session')}\` for the hooks), then run --update again to remove the copy.`,
542
+ );
543
+ }
544
+ if (theirs.length)
545
+ notes.push(
546
+ `${theirs.join(', ')} ${theirs.length > 1 ? 'are' : 'is'} at a path breakaway copies to, but repos init has no record of writing ${theirs.length > 1 ? 'them' : 'it'}, so ${theirs.length > 1 ? 'they are left as they are' : 'it is left as it is'}. If one is breakaway's older copy, delete it and run --update again.`,
547
+ );
548
+ // The record of what is breakaway's here; a run without --update leaves an existing one alone.
549
+ const record = `${JSON.stringify(
550
+ {
551
+ about: `Files repos init copied from ${board} and keeps in step with it (npx breakaway repos init <slug> --update). A file not listed is this repository's own, even at a path breakaway copies to.`,
552
+ from: board,
553
+ files: [...ours].sort(),
554
+ },
555
+ null,
556
+ 2,
557
+ )}\n`;
558
+ const recordThere = readTarget(MANIFEST);
559
+ if (recordThere === null) files.push({ path: MANIFEST, content: record });
560
+ else if (recordThere === record) current.push(MANIFEST);
561
+ else if (update) files.push({ path: MANIFEST, content: record, changed: true });
562
+ else skipped.push(MANIFEST);
446
563
  return { files, removals, skipped, current, notes, todo };
447
564
  }
@@ -5,5 +5,5 @@
5
5
  * bump CLI_VERSION and set CLI_FINGERPRINT to the value it prints. Constants only: the board's Worker imports it,
6
6
  * so it lives in the board's package (CLD-135) and the CLI imports it from here.
7
7
  */
8
- export const CLI_VERSION = 36;
9
- export const CLI_FINGERPRINT = '252bee7de1e280f7';
8
+ export const CLI_VERSION = 38;
9
+ export const CLI_FINGERPRINT = 'e5cf577cb5354653';