@codyswann/lisa 3.17.2 → 3.18.0

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 (84) hide show
  1. package/all/copy-overwrite/scripts/lisa-destructive-guard.mjs +30 -1
  2. package/all/copy-overwrite/scripts/lisa-work-item.mjs +136 -4
  3. package/dist/cli/ui-ci-quality-jobs-compute.d.ts.map +1 -1
  4. package/dist/cli/ui-ci-quality-jobs-compute.js +62 -17
  5. package/dist/cli/ui-ci-quality-jobs-compute.js.map +1 -1
  6. package/dist/core/lisa-owned-hash-ledger.d.ts.map +1 -1
  7. package/dist/core/lisa-owned-hash-ledger.js +5 -0
  8. package/dist/core/lisa-owned-hash-ledger.js.map +1 -1
  9. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  10. package/dist/core/upstream-evidence-manifest.js +15 -8
  11. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  12. package/dist/health/agentic.d.ts +11 -0
  13. package/dist/health/agentic.d.ts.map +1 -1
  14. package/dist/health/agentic.js +29 -0
  15. package/dist/health/agentic.js.map +1 -1
  16. package/package.json +2 -2
  17. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  18. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  19. package/plugins/lisa/.codex-plugin/skills/lisa-github-build-intake/SKILL.md +15 -0
  20. package/plugins/lisa/hooks/threshold-ratchet.mjs +44 -4
  21. package/plugins/lisa/scripts/lifecycle-label-trust.mjs +98 -2
  22. package/plugins/lisa/skills/lisa-github-build-intake/SKILL.md +15 -0
  23. package/plugins/lisa-agy/plugin.json +1 -1
  24. package/plugins/lisa-agy/scripts/lifecycle-label-trust.mjs +98 -2
  25. package/plugins/lisa-agy/skills/lisa-github-build-intake/SKILL.md +15 -0
  26. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  28. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  29. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  30. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  31. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  32. package/plugins/lisa-copilot/hooks/threshold-ratchet.mjs +44 -4
  33. package/plugins/lisa-copilot/scripts/lifecycle-label-trust.mjs +98 -2
  34. package/plugins/lisa-copilot/skills/lisa-github-build-intake/SKILL.md +15 -0
  35. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  36. package/plugins/lisa-cursor/hooks/threshold-ratchet.mjs +44 -4
  37. package/plugins/lisa-cursor/scripts/lifecycle-label-trust.mjs +98 -2
  38. package/plugins/lisa-cursor/skills/lisa-github-build-intake/SKILL.md +15 -0
  39. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  41. package/plugins/lisa-expo-agy/plugin.json +1 -1
  42. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  44. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  45. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  46. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  47. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  49. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  50. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  51. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  52. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  53. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  54. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  56. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  57. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  58. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  59. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  60. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  61. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  62. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  63. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  64. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  65. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  66. package/plugins/lisa-rails-agy/plugin.json +1 -1
  67. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  69. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  70. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  71. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  72. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  73. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  74. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  76. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  77. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  78. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  79. package/plugins/src/base/hooks/threshold-ratchet.mjs +44 -4
  80. package/plugins/src/base/scripts/lifecycle-label-trust.mjs +98 -2
  81. package/plugins/src/base/skills/lisa-github-build-intake/SKILL.md +15 -0
  82. package/rails/copy-overwrite/scripts/check-threshold-ratchet.mjs +44 -4
  83. package/typescript/copy-contents/.husky/commit-msg +10 -3
  84. package/typescript/copy-overwrite/scripts/check-threshold-ratchet.mjs +44 -4
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-rails",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "Ruby on Rails-specific hooks — RuboCop linting/formatting and ast-grep scanning on edit",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-rails",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "Ruby on Rails-specific skills and hooks for RuboCop and ast-grep scanning on edit.",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-rails",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "Ruby on Rails-specific hooks — RuboCop linting/formatting and ast-grep scanning on edit",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-rails",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "Ruby on Rails-specific hooks — RuboCop linting/formatting and ast-grep scanning on edit",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-rails",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "Ruby on Rails-specific hooks — RuboCop linting/formatting and ast-grep scanning on edit",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-typescript",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "TypeScript-specific hooks — Prettier formatting, ESLint linting, ast-grep scanning, and error-suppression blocking on edit",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-typescript",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "TypeScript-specific hooks for formatting, linting, and ast-grep scanning on edit.",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-typescript",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "TypeScript-specific hooks — Prettier formatting, ESLint linting, ast-grep scanning, and error-suppression blocking on edit",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-typescript",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "TypeScript-specific hooks — Prettier formatting, ESLint linting, ast-grep scanning, and error-suppression blocking on edit",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-typescript",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "TypeScript-specific hooks — Prettier formatting, ESLint linting, ast-grep scanning, and error-suppression blocking on edit",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-wiki",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "LLM Wiki — a distributable, git-native markdown knowledge base for Claude Code and Codex",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-wiki",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "Distributable LLM Wiki kernel — ingest, query, lint, and maintain a git-native markdown knowledge base across Claude and Codex.",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-wiki",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "LLM Wiki — a distributable, git-native markdown knowledge base for Claude Code and Codex",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-wiki",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "LLM Wiki — a distributable, git-native markdown knowledge base for Claude Code and Codex",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-wiki",
3
- "version": "3.17.2",
3
+ "version": "3.18.0",
4
4
  "description": "LLM Wiki — a distributable, git-native markdown knowledge base for Claude Code and Codex",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -430,9 +430,49 @@ function main() {
430
430
  return 0;
431
431
  }
432
432
 
433
- const isDirectRun =
434
- process.argv[1] &&
435
- fileURLToPath(import.meta.url) === path.resolve(process.argv[1]);
436
- if (isDirectRun) {
433
+ /**
434
+ * True when `moduleUrl` names the module node was asked to run.
435
+ *
436
+ * The one implementation of this lives at `scripts/lib/invoked-as-script.mjs`,
437
+ * and every other shipped entry point imports it. This file cannot: it is
438
+ * materialized from `plugins/src/base/hooks/`, where it also runs as an
439
+ * agent-time hook, and a plugin payload has no `./lib/` to import from. So the
440
+ * rule is written out here rather than pointed at — the same accommodation
441
+ * `preflight-secrets.mjs` makes, for the same reason.
442
+ *
443
+ * Both sides are realpath'd. The previous spelling compared
444
+ * `fileURLToPath(import.meta.url)` against `path.resolve(process.argv[1])`, and
445
+ * `resolve` makes a path absolute without following symlinks. `import.meta.url`
446
+ * is the REAL path — node resolves ESM through realpath unless
447
+ * `--preserve-symlinks` or `--preserve-symlinks-main` is set — while `argv[1]`
448
+ * is whatever the caller typed. Reached through a symlinked checkout, a git
449
+ * worktree, or a `/tmp` path on macOS (`/tmp` being a symlink to `/private/tmp`),
450
+ * the two disagreed, `main()` never ran, and the process exited 0.
451
+ *
452
+ * For a CHECK that is a fail-OPEN, not a mild degradation: no output, exit 0,
453
+ * the npm script "succeeds", and the ratchet silently stops having an opinion.
454
+ * It was measured, not theorised — every control in the #2531 promotion tests
455
+ * no-opped until the fixture directory was realpath'd.
456
+ *
457
+ * Realpathing BOTH sides rather than only `argv[1]` matters under
458
+ * `--preserve-symlinks-main`, which tells node not to resolve the main entry:
459
+ * normalizing one side then compares a real path against a symlinked one and
460
+ * answers `false` for an entry point that WAS invoked directly. Any resolution
461
+ * error returns `false` — node loaded the entry from that path moments ago, so
462
+ * a path that will not resolve now is not the path this module came through.
463
+ * @param {string} moduleUrl - The caller's own `import.meta.url`.
464
+ * @param {string | undefined} [argv1] - Entry path; defaults to `process.argv[1]`.
465
+ * @returns {boolean} Whether the caller should run its CLI body.
466
+ */
467
+ export function invokedAsScript(moduleUrl, argv1 = process.argv[1]) {
468
+ if (!argv1) return false;
469
+ try {
470
+ return fs.realpathSync(argv1) === fs.realpathSync(fileURLToPath(moduleUrl));
471
+ } catch {
472
+ return false;
473
+ }
474
+ }
475
+
476
+ if (invokedAsScript(import.meta.url)) {
437
477
  process.exit(main());
438
478
  }
@@ -39,6 +39,9 @@
39
39
  * `status:` PREFIX and terminality is resolved from live config.
40
40
  */
41
41
 
42
+ import { realpathSync } from "node:fs";
43
+ import { fileURLToPath } from "node:url";
44
+
42
45
  /** Lifecycle labels are identified by this prefix, never by a pinned set. */
43
46
  export const LIFECYCLE_LABEL_PREFIX = "status:";
44
47
 
@@ -217,6 +220,62 @@ export function terminalLifecycleLabels(config) {
217
220
  return [DEFAULT_TERMINAL_LIFECYCLE_LABEL];
218
221
  }
219
222
 
223
+ /** The claimed role's label when config names none. */
224
+ const DEFAULT_CLAIMED_LIFECYCLE_LABEL = "status:in-progress";
225
+
226
+ /**
227
+ * The lifecycle label that means "somebody is already on this", from config.
228
+ * @param {unknown} config a parsed `.lisa.config.json`-shaped object
229
+ * @returns {string} the claimed role's label
230
+ */
231
+ export function claimedLifecycleLabel(config) {
232
+ const claimed = readPath(config, ["github", "labels", "build", "claimed"]);
233
+ return typeof claimed === "string" && claimed.trim().length > 0
234
+ ? claimed.trim()
235
+ : DEFAULT_CLAIMED_LIFECYCLE_LABEL;
236
+ }
237
+
238
+ /**
239
+ * Whether intake may claim this issue, and why not when it may not.
240
+ *
241
+ * The scan filters on the ready role alone, so an issue carrying BOTH ready and
242
+ * claimed comes back as a candidate. Trust resolution then rescues the case
243
+ * where a bot applied the claim — but says nothing about the case where a
244
+ * *human* did, which is the strongest claim signal there is and the one that
245
+ * was being ignored. An issue a person marked in-progress is somebody's active
246
+ * work; dispatching a second agent onto it is how two branches end up fixing
247
+ * the same thing.
248
+ *
249
+ * Returned as a verdict rather than left to the skill's prose. This repository
250
+ * has measured the difference: executable controls hold, prose rules are
251
+ * followed by roughly nobody, including their own author. The scan already
252
+ * calls this classifier, so the answer arrives where the decision is made.
253
+ *
254
+ * A claim is only believed when TRUSTED, which is what keeps this from undoing
255
+ * the bot fix: a reflexive bot label leaves the issue claimable exactly as if
256
+ * it were absent.
257
+ * @param {object} options inputs
258
+ * @param {readonly string[]} options.trusted labels the classifier believes
259
+ * @param {unknown} options.config a parsed `.lisa.config.json`-shaped object
260
+ * @returns {{claimable: boolean, reason: string|null}} the verdict
261
+ */
262
+ export function resolveClaimability({ trusted, config }) {
263
+ const claimed = claimedLifecycleLabel(config);
264
+ const normalizedClaimed = claimed.toLowerCase();
265
+ const hasTrustedClaim = (trusted ?? []).some(
266
+ label => String(label).trim().toLowerCase() === normalizedClaimed
267
+ );
268
+ if (!hasTrustedClaim) {
269
+ return { claimable: true, reason: null };
270
+ }
271
+ return {
272
+ claimable: false,
273
+ reason:
274
+ `already carries a trusted "${claimed}", so somebody is working it; ` +
275
+ `intake must not dispatch a second agent onto the same issue`,
276
+ };
277
+ }
278
+
220
279
  /**
221
280
  * Detect lifecycle labels that contradict native state, in BOTH directions.
222
281
  *
@@ -482,11 +541,48 @@ async function main() {
482
541
  terminalLabels: terminalLifecycleLabels(payload.config),
483
542
  excludeLabels: trust.untrusted.map(entry => entry.label),
484
543
  });
544
+ // Computed from `trust.trusted`, never from the raw label set: a bot-applied
545
+ // claim must leave the issue claimable exactly as if it were absent, which is
546
+ // the whole point of the trust pass above.
547
+ const claim = resolveClaimability({
548
+ trusted: trust.trusted,
549
+ config: payload.config,
550
+ });
485
551
 
486
- process.stdout.write(`${JSON.stringify({ ...trust, ...drift }, null, 2)}\n`);
552
+ process.stdout.write(
553
+ `${JSON.stringify({ ...trust, ...drift, ...claim }, null, 2)}\n`
554
+ );
555
+ }
556
+
557
+ /**
558
+ * True when `moduleUrl` names the module node was asked to run.
559
+ *
560
+ * Both sides are realpath'd. The previous spelling compared `import.meta.url`
561
+ * against a `file://` string built from `process.argv[1]`, which compares a
562
+ * real path against whatever the caller typed — so reached through a symlinked
563
+ * checkout, a git worktree, or a `/tmp` path on macOS the two disagreed and
564
+ * `main()` never ran. This module writes its verdict to stdout, so a no-op
565
+ * leaves the caller parsing an empty payload: no untrusted labels, no
566
+ * unclaimable verdict, everything believed. A guard that fails open on the
567
+ * component whose job is deciding what to believe.
568
+ *
569
+ * Written out rather than imported: this is a plugin payload, which has no
570
+ * `./lib/` to resolve against. Same rule and same reasoning as
571
+ * `scripts/lib/invoked-as-script.mjs`.
572
+ * @param {string} moduleUrl - The caller's own `import.meta.url`.
573
+ * @param {string | undefined} [argv1] - Entry path; defaults to `process.argv[1]`.
574
+ * @returns {boolean} Whether the caller should run its CLI body.
575
+ */
576
+ export function invokedAsScript(moduleUrl, argv1 = process.argv[1]) {
577
+ if (!argv1) return false;
578
+ try {
579
+ return realpathSync(argv1) === realpathSync(fileURLToPath(moduleUrl));
580
+ } catch {
581
+ return false;
582
+ }
487
583
  }
488
584
 
489
- if (import.meta.url === `file://${process.argv[1]}`) {
585
+ if (invokedAsScript(import.meta.url)) {
490
586
  main().catch(error => {
491
587
  process.stderr.write(`${error.message}\n`);
492
588
  process.exitCode = 1;
@@ -216,6 +216,21 @@ The classifier returns `trusted`, `untrusted`, `unknownProvenance`, and a per-la
216
216
  - a candidate whose `$READY` is **untrusted** is **not claimable** — skip it and leave it for a human to flip genuinely ready; report it in the summary rather than dispatching it;
217
217
  - a candidate whose `$CLAIMED` is **untrusted** is **not claimed** — if its `$READY` is trusted it stays a normal candidate, exactly as if the bot label were absent.
218
218
 
219
+ #### 2c. A trusted claim is a skip reason
220
+
221
+ The scan filters on `--label "$READY"` alone, so an issue carrying **both** `$READY` and `$CLAIMED` comes back as a candidate. The rules above rescue the case where a *bot* applied the claim; they say nothing about the case where a **human** did — which is the strongest claim signal there is, and the one that was being ignored. An issue a person marked in-progress is somebody's active work, and dispatching a second agent onto it is how two branches end up fixing the same thing.
222
+
223
+ The classifier answers this directly, so the skill does not have to reason about it:
224
+
225
+ ```json
226
+ { "claimable": false,
227
+ "reason": "already carries a trusted \"status:in-progress\", so somebody is working it; intake must not dispatch a second agent onto the same issue" }
228
+ ```
229
+
230
+ **A candidate with `claimable: false` is skipped and reported with its `reason`.** It is not an error and not a stall — it is the queue working. Never strip the claim to make it claimable: that is the label-flap the section above refuses, aimed at a human this time.
231
+
232
+ `claimable` is computed from the **trusted** set, not the raw labels, which is what keeps it from undoing 2b — a bot-applied claim leaves the issue claimable exactly as if it were absent.
233
+
219
234
  **Never unlabel to correct this.** The bot re-applies its label on each subsequent review event, so reverting produces a label-flap loop that is worse than the defect. The guard is that intake stops *believing* the label; it writes nothing. Distrust is idempotent and cannot race.
220
235
 
221
236
  A label whose provenance cannot be established (applied at creation, which GitHub records no `labeled` event for) is trusted but listed in `unknownProvenance` — failing closed there would ignore the human `status:ready` that opens the queue. Report that list; do not silently drop it.
@@ -433,9 +433,49 @@ function main() {
433
433
  return 0;
434
434
  }
435
435
 
436
- const isDirectRun =
437
- process.argv[1] &&
438
- fileURLToPath(import.meta.url) === path.resolve(process.argv[1]);
439
- if (isDirectRun) {
436
+ /**
437
+ * True when `moduleUrl` names the module node was asked to run.
438
+ *
439
+ * The one implementation of this lives at `scripts/lib/invoked-as-script.mjs`,
440
+ * and every other shipped entry point imports it. This file cannot: it is
441
+ * materialized from `plugins/src/base/hooks/`, where it also runs as an
442
+ * agent-time hook, and a plugin payload has no `./lib/` to import from. So the
443
+ * rule is written out here rather than pointed at — the same accommodation
444
+ * `preflight-secrets.mjs` makes, for the same reason.
445
+ *
446
+ * Both sides are realpath'd. The previous spelling compared
447
+ * `fileURLToPath(import.meta.url)` against `path.resolve(process.argv[1])`, and
448
+ * `resolve` makes a path absolute without following symlinks. `import.meta.url`
449
+ * is the REAL path — node resolves ESM through realpath unless
450
+ * `--preserve-symlinks` or `--preserve-symlinks-main` is set — while `argv[1]`
451
+ * is whatever the caller typed. Reached through a symlinked checkout, a git
452
+ * worktree, or a `/tmp` path on macOS (`/tmp` being a symlink to `/private/tmp`),
453
+ * the two disagreed, `main()` never ran, and the process exited 0.
454
+ *
455
+ * For a CHECK that is a fail-OPEN, not a mild degradation: no output, exit 0,
456
+ * the npm script "succeeds", and the ratchet silently stops having an opinion.
457
+ * It was measured, not theorised — every control in the #2531 promotion tests
458
+ * no-opped until the fixture directory was realpath'd.
459
+ *
460
+ * Realpathing BOTH sides rather than only `argv[1]` matters under
461
+ * `--preserve-symlinks-main`, which tells node not to resolve the main entry:
462
+ * normalizing one side then compares a real path against a symlinked one and
463
+ * answers `false` for an entry point that WAS invoked directly. Any resolution
464
+ * error returns `false` — node loaded the entry from that path moments ago, so
465
+ * a path that will not resolve now is not the path this module came through.
466
+ * @param {string} moduleUrl - The caller's own `import.meta.url`.
467
+ * @param {string | undefined} [argv1] - Entry path; defaults to `process.argv[1]`.
468
+ * @returns {boolean} Whether the caller should run its CLI body.
469
+ */
470
+ export function invokedAsScript(moduleUrl, argv1 = process.argv[1]) {
471
+ if (!argv1) return false;
472
+ try {
473
+ return fs.realpathSync(argv1) === fs.realpathSync(fileURLToPath(moduleUrl));
474
+ } catch {
475
+ return false;
476
+ }
477
+ }
478
+
479
+ if (invokedAsScript(import.meta.url)) {
440
480
  process.exit(main());
441
481
  }
@@ -54,15 +54,22 @@ fi
54
54
 
55
55
  # Check for Co-Authored-By line (skip for merge commits)
56
56
  COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
57
+ # `printf '%s\n'`, never `echo "$COMMIT_MSG"`. Under a POSIX/XSI `echo` the
58
+ # backslash escapes are interpreted, and `\c` means "stop output here" — so a
59
+ # message containing `\copy`, `\cite`, or a Windows path like `C:\config` is
60
+ # silently truncated at that point before grep ever sees it. The
61
+ # `Co-Authored-By:` trailer is always the last line, so it is always the part
62
+ # lost, and the hook then rejects a commit whose trailer is present and
63
+ # correctly formatted while pointing the author at the trailer.
57
64
 
58
65
  # Skip AI co-authorship check for merge commits (e.g., from git pull)
59
- if echo "$COMMIT_MSG" | grep -qE "^Merge (branch|pull request|remote-tracking)"; then
66
+ if printf '%s\n' "$COMMIT_MSG" | grep -qE "^Merge (branch|pull request|remote-tracking)"; then
60
67
  echo "🔀 Merge commit detected, skipping AI co-authorship check"
61
68
  exit 0
62
69
  fi
63
70
 
64
71
  # Skip AI co-authorship check for automated release commits (e.g., from standard-version in CI)
65
- if echo "$COMMIT_MSG" | grep -qE "^chore\(release\):"; then
72
+ if printf '%s\n' "$COMMIT_MSG" | grep -qE "^chore\(release\):"; then
66
73
  echo "🚀 Release commit detected, skipping AI co-authorship check"
67
74
  exit 0
68
75
  fi
@@ -72,7 +79,7 @@ echo "🤖 Checking for AI co-authorship..."
72
79
  # Accept attribution from any supported coding agent (Claude or Codex),
73
80
  # case-insensitively. Claude Code emits "Co-Authored-By: Claude"; the Codex CLI
74
81
  # emits "Co-authored-by: Codex <noreply@openai.com>".
75
- if ! echo "$COMMIT_MSG" | grep -Eiq "Co-authored-by:.*(Claude|Codex)"; then
82
+ if ! printf '%s\n' "$COMMIT_MSG" | grep -Eiq "Co-authored-by:.*(Claude|Codex)"; then
76
83
  echo ""
77
84
  echo "❌ Commit message must include AI co-authorship!"
78
85
  echo ""
@@ -433,9 +433,49 @@ function main() {
433
433
  return 0;
434
434
  }
435
435
 
436
- const isDirectRun =
437
- process.argv[1] &&
438
- fileURLToPath(import.meta.url) === path.resolve(process.argv[1]);
439
- if (isDirectRun) {
436
+ /**
437
+ * True when `moduleUrl` names the module node was asked to run.
438
+ *
439
+ * The one implementation of this lives at `scripts/lib/invoked-as-script.mjs`,
440
+ * and every other shipped entry point imports it. This file cannot: it is
441
+ * materialized from `plugins/src/base/hooks/`, where it also runs as an
442
+ * agent-time hook, and a plugin payload has no `./lib/` to import from. So the
443
+ * rule is written out here rather than pointed at — the same accommodation
444
+ * `preflight-secrets.mjs` makes, for the same reason.
445
+ *
446
+ * Both sides are realpath'd. The previous spelling compared
447
+ * `fileURLToPath(import.meta.url)` against `path.resolve(process.argv[1])`, and
448
+ * `resolve` makes a path absolute without following symlinks. `import.meta.url`
449
+ * is the REAL path — node resolves ESM through realpath unless
450
+ * `--preserve-symlinks` or `--preserve-symlinks-main` is set — while `argv[1]`
451
+ * is whatever the caller typed. Reached through a symlinked checkout, a git
452
+ * worktree, or a `/tmp` path on macOS (`/tmp` being a symlink to `/private/tmp`),
453
+ * the two disagreed, `main()` never ran, and the process exited 0.
454
+ *
455
+ * For a CHECK that is a fail-OPEN, not a mild degradation: no output, exit 0,
456
+ * the npm script "succeeds", and the ratchet silently stops having an opinion.
457
+ * It was measured, not theorised — every control in the #2531 promotion tests
458
+ * no-opped until the fixture directory was realpath'd.
459
+ *
460
+ * Realpathing BOTH sides rather than only `argv[1]` matters under
461
+ * `--preserve-symlinks-main`, which tells node not to resolve the main entry:
462
+ * normalizing one side then compares a real path against a symlinked one and
463
+ * answers `false` for an entry point that WAS invoked directly. Any resolution
464
+ * error returns `false` — node loaded the entry from that path moments ago, so
465
+ * a path that will not resolve now is not the path this module came through.
466
+ * @param {string} moduleUrl - The caller's own `import.meta.url`.
467
+ * @param {string | undefined} [argv1] - Entry path; defaults to `process.argv[1]`.
468
+ * @returns {boolean} Whether the caller should run its CLI body.
469
+ */
470
+ export function invokedAsScript(moduleUrl, argv1 = process.argv[1]) {
471
+ if (!argv1) return false;
472
+ try {
473
+ return fs.realpathSync(argv1) === fs.realpathSync(fileURLToPath(moduleUrl));
474
+ } catch {
475
+ return false;
476
+ }
477
+ }
478
+
479
+ if (invokedAsScript(import.meta.url)) {
440
480
  process.exit(main());
441
481
  }