@codyswann/lisa 4.84.5 → 4.84.7

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 (100) hide show
  1. package/dist/core/nightly-e2e-guard-behavior-certificate.js +2 -2
  2. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  3. package/dist/core/upstream-evidence-manifest.js +21 -4
  4. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  5. package/package.json +4 -4
  6. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  7. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  8. package/plugins/lisa/hooks/block-host-name-leak.mjs +130 -40
  9. package/plugins/lisa/hooks/block-host-name-leak.sh +5 -0
  10. package/plugins/lisa/hooks/host-name-command-context.mjs +409 -0
  11. package/plugins/lisa-agy/hooks/block-host-name-leak.mjs +130 -40
  12. package/plugins/lisa-agy/hooks/block-host-name-leak.sh +5 -0
  13. package/plugins/lisa-agy/hooks/host-name-command-context.mjs +409 -0
  14. package/plugins/lisa-agy/plugin.json +1 -1
  15. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  16. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  17. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  18. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  19. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  20. package/plugins/lisa-cdk-devin/.claude-plugin/plugin.json +1 -1
  21. package/plugins/lisa-cdk-devin/.devin-plugin/plugin.json +1 -1
  22. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  23. package/plugins/lisa-copilot/hooks/block-host-name-leak.mjs +130 -40
  24. package/plugins/lisa-copilot/hooks/block-host-name-leak.sh +5 -0
  25. package/plugins/lisa-copilot/hooks/host-name-command-context.mjs +409 -0
  26. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  27. package/plugins/lisa-cursor/hooks/block-host-name-leak.mjs +130 -40
  28. package/plugins/lisa-cursor/hooks/block-host-name-leak.sh +5 -0
  29. package/plugins/lisa-cursor/hooks/host-name-command-context.mjs +409 -0
  30. package/plugins/lisa-devin/.claude-plugin/plugin.json +1 -1
  31. package/plugins/lisa-devin/.devin-plugin/plugin.json +1 -1
  32. package/plugins/lisa-devin/hooks/block-host-name-leak.mjs +130 -40
  33. package/plugins/lisa-devin/hooks/block-host-name-leak.sh +5 -0
  34. package/plugins/lisa-devin/hooks/host-name-command-context.mjs +409 -0
  35. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  36. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  37. package/plugins/lisa-expo-agy/plugin.json +1 -1
  38. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  39. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  40. package/plugins/lisa-expo-devin/.claude-plugin/plugin.json +1 -1
  41. package/plugins/lisa-expo-devin/.devin-plugin/plugin.json +1 -1
  42. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  43. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  44. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  45. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  46. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  47. package/plugins/lisa-harper-fabric-devin/.claude-plugin/plugin.json +1 -1
  48. package/plugins/lisa-harper-fabric-devin/.devin-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-nestjs-devin/.claude-plugin/plugin.json +1 -1
  55. package/plugins/lisa-nestjs-devin/.devin-plugin/plugin.json +1 -1
  56. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  57. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  58. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  59. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  60. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  61. package/plugins/lisa-openclaw-devin/.claude-plugin/plugin.json +1 -1
  62. package/plugins/lisa-openclaw-devin/.devin-plugin/plugin.json +1 -1
  63. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  64. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  65. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  66. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  67. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  68. package/plugins/lisa-phaser-devin/.claude-plugin/plugin.json +1 -1
  69. package/plugins/lisa-phaser-devin/.devin-plugin/plugin.json +1 -1
  70. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  71. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  72. package/plugins/lisa-rails-agy/plugin.json +1 -1
  73. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  74. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  75. package/plugins/lisa-rails-devin/.claude-plugin/plugin.json +1 -1
  76. package/plugins/lisa-rails-devin/.devin-plugin/plugin.json +1 -1
  77. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  78. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  79. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  80. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  81. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  82. package/plugins/lisa-typescript-devin/.claude-plugin/plugin.json +1 -1
  83. package/plugins/lisa-typescript-devin/.devin-plugin/plugin.json +1 -1
  84. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  85. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  86. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  87. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  88. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  89. package/plugins/lisa-wiki-devin/.claude-plugin/plugin.json +1 -1
  90. package/plugins/lisa-wiki-devin/.devin-plugin/plugin.json +1 -1
  91. package/plugins/src/base/hooks/block-host-name-leak.mjs +130 -40
  92. package/plugins/src/base/hooks/block-host-name-leak.sh +5 -0
  93. package/plugins/src/base/hooks/host-name-command-context.mjs +409 -0
  94. package/scripts/generate-agy-plugin-artifacts.mjs +7 -3
  95. package/scripts/lib/host-name-expanded-command-cases.mjs +286 -0
  96. package/scripts/lib/host-name-field-occurrence-cases.mjs +60 -0
  97. package/scripts/lib/host-name-review-cases.mjs +354 -0
  98. package/scripts/lib/host-name-target-cases.mjs +298 -0
  99. package/scripts/two-channel-couplings.json +29 -6
  100. package/scripts/verify-host-name-target-scope.mjs +373 -0
@@ -53,6 +53,24 @@
53
53
  * tempted to add it to `plugins/materialized-artifacts.json` should have a
54
54
  * reason why a host project should be refused its own name.
55
55
  *
56
+ * WHERE IT APPLIES: THE TARGET, NOT THE CHECKOUT (#4462)
57
+ *
58
+ * Not materializing it was not enough. The guard is registered by the PLUGIN,
59
+ * so it runs in every project the plugin is enabled in, and every host has the
60
+ * denylist at `node_modules/@codyswann/lisa/dist/`. Inside a host it refused
61
+ * that host's own tracker writes — including the `Work-Item: <owner>/<repo>#<n>`
62
+ * line the work-item gate REQUIRES in every pull-request body, so the two Lisa
63
+ * guards contradicted each other and every agent-opened host PR failed
64
+ * traceability.
65
+ *
66
+ * So the guard resolves the active gh call's explicit repository or API
67
+ * endpoint, then GH_REPO, the locally selected gh default, or one unambiguous
68
+ * Git remote. Literal cd and environment assignments use the command's actual
69
+ * directory; the project root still locates the detector. Body text is never
70
+ * routing. Unsupported shell syntax, unresolved expansions and ambiguous
71
+ * repositories earn no host exemption. This is bounded command inspection,
72
+ * not shell execution or a claim to close every shell/identity leak class.
73
+ *
56
74
  * FAILING OPEN, LOUDLY
57
75
  *
58
76
  * When the denylist cannot be loaded this permits the write and says so on
@@ -65,6 +83,13 @@
65
83
  import { existsSync, readFileSync, realpathSync } from "node:fs";
66
84
  import path from "node:path";
67
85
  import { fileURLToPath, pathToFileURL } from "node:url";
86
+ import {
87
+ commandRepository,
88
+ ghCommands,
89
+ repositoryFromSpec,
90
+ } from "./host-name-command-context.mjs";
91
+
92
+ export { repositoryFromSpec };
68
93
 
69
94
  /** Claude Code's refusal code. Every other non-zero exit is a hook error. */
70
95
  const EXIT_BLOCKED = 2;
@@ -110,10 +135,17 @@ const TEXT_FLAGS = new Set([
110
135
  "-m",
111
136
  ]);
112
137
  /** `gh api` field flags: `key=value`, or `key=@path` to read a file. */
113
- const FIELD_FLAGS = new Set(["-f", "--field", "--raw-field"]);
138
+ const FIELD_FLAGS = new Set(["-f", "-F", "--field", "--raw-field"]);
114
139
  /** Field names whose value is published prose rather than metadata. */
115
140
  const PROSE_FIELDS = new Set(["body", "title", "text", "message"]);
116
141
 
142
+ /**
143
+ * The repositories this guard protects, lowercased `owner/repo`.
144
+ *
145
+ * Only this one: it is public and ships `dist/` to npm. A host's own tracker
146
+ * is not on the list, which is the point (#4462).
147
+ */
148
+ const GUARDED_REPOSITORIES = new Set(["codyswanngt/lisa"]);
117
149
  /**
118
150
  * Vendor endpoints quoted from guard source, which are not host identities.
119
151
  *
@@ -173,30 +205,10 @@ export function tokenize(command) {
173
205
  * @returns True when the command publishes text.
174
206
  */
175
207
  export function isOutboundTrackerWrite(tokens) {
176
- const gh = tokens.indexOf("gh");
177
- if (gh === -1) return false;
178
- const rest = tokens.slice(gh + 1).filter(token => !token.startsWith("-"));
179
- const [noun, verb] = rest;
180
- if (noun === "api") return isMutatingApiCall(tokens);
181
- return WRITE_NOUNS.has(noun ?? "") && WRITE_VERBS.has(verb ?? "");
182
- }
183
-
184
- /**
185
- * Whether a `gh api` call mutates.
186
- *
187
- * `gh api` defaults to GET, and to POST when any field flag is present — so a
188
- * field flag alone makes it a write even with no explicit method.
189
- * @param tokens - Command tokens.
190
- * @returns True when the call changes state.
191
- */
192
- function isMutatingApiCall(tokens) {
193
- const method = tokens.findIndex(
194
- token => token === "-X" || token === "--method"
195
- );
196
- if (method !== -1) {
197
- return MUTATING_METHODS.has((tokens[method + 1] ?? "").toUpperCase());
198
- }
199
- return tokens.some(token => FIELD_FLAGS.has(token));
208
+ return ghCommands(
209
+ tokens.map(token => JSON.stringify(token)).join(" "),
210
+ process.cwd()
211
+ ).some(context => context.writes);
200
212
  }
201
213
 
202
214
  /**
@@ -212,6 +224,32 @@ function valueAt(tokens, index) {
212
224
  return tokens[index + 1] ?? "";
213
225
  }
214
226
 
227
+ /**
228
+ * Resolve the target of one tokenized command without treating prose as routing.
229
+ * @param tokens Command tokens.
230
+ * @param cwd Actual command working directory.
231
+ * @returns Verified owner/repository, or unknown.
232
+ */
233
+ export function targetRepository(tokens, cwd) {
234
+ const context = ghCommands(
235
+ tokens.map(token => JSON.stringify(token)).join(" "),
236
+ cwd
237
+ )[0];
238
+ return context === undefined ? undefined : commandRepository(context);
239
+ }
240
+
241
+ /**
242
+ * Whether the guard applies to a write landing in this repository.
243
+ *
244
+ * An undetermined target is guarded: not knowing where text is going is no
245
+ * reason to stop protecting the one place it must not go.
246
+ * @param target - `owner/repo`, or undefined.
247
+ * @returns True when the write must be checked.
248
+ */
249
+ export function isGuardedTarget(target) {
250
+ return target === undefined || GUARDED_REPOSITORIES.has(target);
251
+ }
252
+
215
253
  /**
216
254
  * Read a file the command names, if it is readable.
217
255
  * @param candidate - Path as written on the command line.
@@ -236,16 +274,30 @@ function readIfPresent(candidate, cwd) {
236
274
  * from so the refusal can point at the thing to edit.
237
275
  * @param tokens - Command tokens.
238
276
  * @param cwd - Directory the command runs in.
277
+ * @param noun - The active gh noun, so api fields retain their own meaning.
239
278
  * @returns Sources of publishable text.
240
279
  */
241
- export function publishableText(tokens, cwd) {
280
+ export function publishableText(tokens, cwd, noun) {
242
281
  return tokens.flatMap((token, index) => {
243
282
  const bare = token.startsWith("-") ? token.split("=")[0] : token;
244
- if (TEXT_FLAGS.has(bare)) {
283
+ if (noun !== "api" && TEXT_FLAGS.has(bare)) {
245
284
  return [{ origin: bare, text: valueAt(tokens, index) }];
246
285
  }
247
286
  if (FILE_FLAGS.has(bare)) {
248
- const file = valueAt(tokens, index).replace(/^@/u, "");
287
+ const value = valueAt(tokens, index);
288
+ // On `gh api`, `-F` is `--field`: `key=@path` or `key=value`. Read as a
289
+ // bare path, `body=@file` named no file and published unchecked (#4462).
290
+ if (
291
+ (noun === "api" || (noun === undefined && bare === "-F")) &&
292
+ /^[\w.[\]-]+=/u.test(value)
293
+ ) {
294
+ const field = fieldSource(value, cwd);
295
+ if (noun === "api") return [field];
296
+ // An unresolved noun may become api or issue/pr. Inspect both possible
297
+ // meanings of -F without evaluating the expansion or certifying routing.
298
+ return [field, { origin: value, text: readIfPresent(value, cwd) }];
299
+ }
300
+ const file = value.replace(/^@/u, "");
249
301
  return [{ origin: file, text: readIfPresent(file, cwd) }];
250
302
  }
251
303
  if (FIELD_FLAGS.has(bare))
@@ -353,19 +405,57 @@ means "no known name appeared", not "this text is safe".`;
353
405
  * @returns The exit code and any message.
354
406
  */
355
407
  export async function evaluate(command, projectDir) {
356
- const tokens = tokenize(command);
357
- if (!isOutboundTrackerWrite(tokens)) return { code: EXIT_ALLOWED };
358
- const detector = await loadDetector(projectDir);
359
- if (detector === undefined) {
360
- return {
361
- code: EXIT_ALLOWED,
362
- warning:
363
- "block-host-name-leak: host-name denylist not found (no built dist/ or installed package); host-identity enforcement is NOT active",
364
- };
408
+ let detector;
409
+ const findings = [];
410
+ for (const context of ghCommands(command, process.cwd())) {
411
+ if (!context.writes || !isGuardedTarget(commandRepository(context)))
412
+ continue;
413
+ detector ??= await loadDetector(projectDir);
414
+ if (detector === undefined) {
415
+ return {
416
+ code: EXIT_ALLOWED,
417
+ warning:
418
+ "block-host-name-leak: host-name denylist not found (no built dist/ or installed package); host-identity enforcement is NOT active",
419
+ };
420
+ }
421
+ // Without a known cwd a relative file cannot be inspected honestly. Keep
422
+ // protection, and name the unread input instead of claiming the text clean.
423
+ if (
424
+ context.cwd === undefined &&
425
+ [
426
+ ...context.flags,
427
+ ...(context.noun === "api" || context.noun === undefined
428
+ ? context.fieldOccurrences
429
+ : []),
430
+ ].some(([flag, item]) => {
431
+ const field =
432
+ (context.noun === "api" || context.noun === undefined) &&
433
+ FIELD_FLAGS.has(flag)
434
+ ? /^([^=]+)=@(.+)$/u.exec(item.value)
435
+ : null;
436
+ const files = [
437
+ field !== null && PROSE_FIELDS.has(field[1]) ? field[2] : undefined,
438
+ FILE_FLAGS.has(flag) && (context.noun !== "api" || field === null)
439
+ ? item.value.replace(/^@/, "")
440
+ : undefined,
441
+ ];
442
+ return files.some(file => file !== undefined && !path.isAbsolute(file));
443
+ })
444
+ ) {
445
+ return {
446
+ code: EXIT_BLOCKED,
447
+ message:
448
+ "BLOCKED: the working directory for this tracker write's body file could not be resolved. Use a literal directory and readable body file so the host-name guard can inspect it.",
449
+ };
450
+ }
451
+ findings.push(
452
+ ...publishableText(
453
+ context.tokens,
454
+ context.cwd ?? projectDir,
455
+ context.noun
456
+ ).flatMap(source => findingsIn(source, detector))
457
+ );
365
458
  }
366
- const findings = publishableText(tokens, projectDir).flatMap(source =>
367
- findingsIn(source, detector)
368
- );
369
459
  if (findings.length === 0) return { code: EXIT_ALLOWED };
370
460
  return { code: EXIT_BLOCKED, message: formatRefusal(findings) };
371
461
  }
@@ -56,6 +56,11 @@ if [ ! -r "$classifier" ]; then
56
56
  exit 0
57
57
  fi
58
58
 
59
+ if [ ! -r "$hook_dir/host-name-command-context.mjs" ]; then
60
+ printf 'block-host-name-leak: command-context helper missing; host-identity enforcement is NOT active\n' >&2
61
+ exit 0
62
+ fi
63
+
59
64
  status=0
60
65
  node "$classifier" "$command_str" "$project_dir" || status=$?
61
66
  exit "$status"
@@ -0,0 +1,409 @@
1
+ /** Bounded literal command/target resolution for the host-name guard; never a shell. */
2
+ import { execFileSync } from "node:child_process";
3
+ import { statSync } from "node:fs";
4
+ import path from "node:path";
5
+
6
+ const VALUE_FLAGS = new Set([
7
+ "--repo",
8
+ "-R",
9
+ "--body",
10
+ "-b",
11
+ "--title",
12
+ "-t",
13
+ "--message",
14
+ "-m",
15
+ "--body-file",
16
+ "--input",
17
+ "-f",
18
+ "-F",
19
+ "--field",
20
+ "--raw-field",
21
+ "-X",
22
+ "--method",
23
+ "-H",
24
+ "--header",
25
+ "--hostname",
26
+ "-q",
27
+ "--jq",
28
+ "--template",
29
+ "-p",
30
+ "--preview",
31
+ "--base",
32
+ "--head",
33
+ "--assignee",
34
+ "--label",
35
+ "--milestone",
36
+ "--project",
37
+ "--reviewer",
38
+ ]);
39
+ const FIELD_FLAGS = new Set(["-f", "-F", "--field", "--raw-field"]);
40
+ const METHODS = new Set(["POST", "PATCH", "PUT"]);
41
+ const SHORT_VALUES = /^(-[RbBtTmMfFXHqp])(.+)$/u;
42
+
43
+ /**
44
+ * Read literal words and command separators, retaining expansion uncertainty.
45
+ * @param {string} command Raw Bash command.
46
+ * @returns {object[]} Literal words and separators.
47
+ */
48
+ function words(command) {
49
+ const result = [];
50
+ let value = "",
51
+ quote = "",
52
+ literal = true,
53
+ started = false;
54
+ const flush = () => {
55
+ if (started) result.push({ value, literal });
56
+ value = "";
57
+ literal = true;
58
+ started = false;
59
+ };
60
+ for (let i = 0; i < command.length; i += 1) {
61
+ const char = command[i];
62
+ if (char === "\\" && quote !== "'") {
63
+ const next = command[++i];
64
+ if (next === undefined) literal = false;
65
+ else if (next !== "\n") {
66
+ if (quote === '"' && !/[$`"\\]/u.test(next)) value += "\\";
67
+ value += next;
68
+ }
69
+ if (next !== "\n") started = true;
70
+ } else if (quote !== "") {
71
+ if (char === quote) quote = "";
72
+ else {
73
+ value += char;
74
+ if (quote === '"' && /[$`]/u.test(char)) literal = false;
75
+ }
76
+ started = true;
77
+ } else if (char === '"' || char === "'") {
78
+ quote = char;
79
+ started = true;
80
+ } else if (/[;&|\n()<>]/u.test(char)) {
81
+ flush();
82
+ const operator =
83
+ char === command[i + 1] && /[&|]/u.test(char)
84
+ ? char + command[++i]
85
+ : char;
86
+ result.push({ operator });
87
+ } else if (/\s/u.test(char)) flush();
88
+ else {
89
+ value += char;
90
+ started = true;
91
+ if (/[$`*?[\]~]/u.test(char)) literal = false;
92
+ }
93
+ }
94
+ if (quote !== "") literal = false;
95
+ flush();
96
+ return result;
97
+ }
98
+
99
+ /**
100
+ * Split option values without treating body text as a second option/endpoint.
101
+ * @param {object[]} input Active gh arguments only.
102
+ * @returns {object} Parsed flags, positional words and normalized tokens.
103
+ */
104
+ function argumentsOf(input) {
105
+ const flags = new Map(),
106
+ fieldOccurrences = [],
107
+ positional = [],
108
+ tokens = [];
109
+ // Any expansion can add/replace routing arguments after shell word splitting.
110
+ // Never evaluate it or certify a target from the remaining literal words.
111
+ let certain = input.every(word => word.literal);
112
+ for (let i = 0; i < input.length; i += 1) {
113
+ const word = input[i];
114
+ if (word.value === "--") {
115
+ positional.push(...input.slice(i + 1));
116
+ tokens.push(...input.slice(i).map(item => item.value));
117
+ break;
118
+ }
119
+ const equals = word.value.indexOf("=");
120
+ const directFlag = equals > 0 ? word.value.slice(0, equals) : word.value;
121
+ const attached = VALUE_FLAGS.has(directFlag)
122
+ ? null
123
+ : SHORT_VALUES.exec(word.value);
124
+ const flag =
125
+ attached?.[1] ??
126
+ (equals > 0 && word.value.startsWith("-") ? directFlag : word.value);
127
+ tokens.push(flag);
128
+ if (VALUE_FLAGS.has(flag)) {
129
+ const value = attached
130
+ ? { ...word, value: attached[2] }
131
+ : equals > 0
132
+ ? { ...word, value: word.value.slice(equals + 1) }
133
+ : input[++i];
134
+ if (value === undefined) {
135
+ certain = false;
136
+ continue;
137
+ }
138
+ // Alias spellings share one Cobra option; the last occurrence wins.
139
+ flags.set(
140
+ flag === "-R" ? "--repo" : flag === "-X" ? "--method" : flag,
141
+ value
142
+ );
143
+ // API fields are additive even though routing options use last values.
144
+ if (FIELD_FLAGS.has(flag)) fieldOccurrences.push([flag, value]);
145
+ tokens.push(value.value);
146
+ } else if (!word.value.startsWith("-")) positional.push(word);
147
+ else if (!word.literal) certain = false;
148
+ }
149
+ const nounWord = positional[0],
150
+ verbWord = positional[1];
151
+ const noun = nounWord?.literal ? nounWord.value : undefined,
152
+ verb = verbWord?.value;
153
+ // Command-name expansions can supply several argv words. A following
154
+ // read-looking literal does not prove that the expanded command is a read.
155
+ const uncertainName =
156
+ nounWord?.literal === false ||
157
+ (["issue", "pr"].includes(noun) && verbWord?.literal === false);
158
+ const method = flags.get("--method");
159
+ const writes =
160
+ uncertainName ||
161
+ (noun === "api"
162
+ ? method
163
+ ? !method.literal || METHODS.has(method.value.toUpperCase())
164
+ : [...FIELD_FLAGS].some(flag => flags.has(flag)) ||
165
+ Boolean(flags.get("--input")?.value)
166
+ : ["issue", "pr"].includes(noun) &&
167
+ ["create", "comment", "edit"].includes(verb));
168
+ return {
169
+ flags,
170
+ fieldOccurrences,
171
+ positional,
172
+ tokens: ["gh", ...tokens],
173
+ noun,
174
+ writes,
175
+ certain,
176
+ };
177
+ }
178
+
179
+ /**
180
+ * Normalize only repository shapes gh/git actually accept; unresolved syntax is unknown.
181
+ * @param {string} spec Repository argument, URL or Git remote.
182
+ * @returns {string|undefined} Lowercased owner/repository, or unknown.
183
+ */
184
+ export function repositoryFromSpec(spec) {
185
+ if (typeof spec !== "string" || /[\s${}`*?#[\]]/u.test(spec))
186
+ return undefined;
187
+ const normalized = spec
188
+ .trim()
189
+ .replace(/\.git\/?$/u, "")
190
+ .replace(/\/$/u, "");
191
+ const matched =
192
+ /^(?:(?:https?:\/\/|ssh:\/\/git@)[^/]+\/|git@[^:]+:|[^/:]+\/)?([\w.-]+)\/([\w.-]+)$/u.exec(
193
+ normalized
194
+ );
195
+ return matched ? `${matched[1]}/${matched[2]}`.toLowerCase() : undefined;
196
+ }
197
+
198
+ /**
199
+ * Resolve literal cd and leading environment assignments across simple command lists.
200
+ * Pipelines, conditionals and other shell syntax never earn a target exemption.
201
+ * @param {string} command Raw Bash command.
202
+ * @param {string} initialCwd The actual hook process cwd, separate from detector root.
203
+ * @param {object} env The actual inherited environment.
204
+ * @returns {object[]} Active gh calls with their bounded command contexts.
205
+ */
206
+ export function ghCommands(command, initialCwd, env = process.env) {
207
+ const calls = [];
208
+ const inherited = { ...env };
209
+ let cwd = initialCwd,
210
+ segment = [],
211
+ uncertain = false;
212
+ const consume = () => {
213
+ if (segment.length === 0) return;
214
+ const local = { ...inherited };
215
+ let index = segment[0].value === "env" ? 1 : 0;
216
+ while (/^[A-Za-z_][A-Za-z_0-9]*=/u.test(segment[index]?.value ?? "")) {
217
+ const item = segment[index++],
218
+ split = item.value.indexOf("=");
219
+ local[item.value.slice(0, split)] = item.literal
220
+ ? item.value.slice(split + 1)
221
+ : undefined;
222
+ if (!item.literal) uncertain = true;
223
+ }
224
+ const executable = segment[index]?.value;
225
+ if (executable === "cd") {
226
+ const args = segment.slice(index + 1).filter(item => item.value !== "--");
227
+ const directory =
228
+ args.length === 1 && args[0].literal && !args[0].value.startsWith("-")
229
+ ? args[0].value
230
+ : undefined;
231
+ try {
232
+ const resolved =
233
+ directory === undefined ||
234
+ (!path.isAbsolute(directory) &&
235
+ !/^\.\.?(?:\/|$)/u.test(directory) &&
236
+ (uncertain || local.CDPATH))
237
+ ? undefined
238
+ : path.isAbsolute(directory)
239
+ ? directory
240
+ : cwd === undefined
241
+ ? undefined
242
+ : path.resolve(cwd, directory);
243
+ cwd =
244
+ resolved !== undefined && statSync(resolved).isDirectory()
245
+ ? resolved
246
+ : undefined;
247
+ } catch {
248
+ cwd = undefined;
249
+ }
250
+ } else if (executable === "export") {
251
+ for (const item of segment.slice(index + 1)) {
252
+ const split = item.value.indexOf("=");
253
+ if (split < 1 || !item.literal) {
254
+ uncertain = true;
255
+ continue;
256
+ }
257
+ inherited[item.value.slice(0, split)] = item.value.slice(split + 1);
258
+ }
259
+ } else if (executable !== undefined && path.basename(executable) === "gh") {
260
+ calls.push({
261
+ ...argumentsOf(segment.slice(index + 1)),
262
+ cwd,
263
+ env: local,
264
+ certainContext: !uncertain,
265
+ });
266
+ } else {
267
+ // A function/source/pushd or unsupported launcher may change the shell
268
+ // context. Do not grant later writes an exemption based on the old cwd.
269
+ uncertain = true;
270
+ cwd = undefined;
271
+ const nested = segment.findIndex(item => item.value === "gh");
272
+ if (nested !== -1)
273
+ calls.push({
274
+ ...argumentsOf(segment.slice(nested + 1)),
275
+ cwd,
276
+ env: local,
277
+ certainContext: false,
278
+ });
279
+ }
280
+ segment = [];
281
+ };
282
+ for (const word of words(command)) {
283
+ if (word.operator === undefined) segment.push(word);
284
+ else {
285
+ consume();
286
+ if (!["&&", ";", "\n"].includes(word.operator)) {
287
+ uncertain = true;
288
+ cwd = undefined;
289
+ }
290
+ }
291
+ }
292
+ consume();
293
+ return calls;
294
+ }
295
+
296
+ /**
297
+ * Read gh's local selected default, falling back only to one unambiguous remote.
298
+ * All reads share a five-second ceiling and execute no shell or network query.
299
+ * @param {object} context One gh command context.
300
+ * @returns {string|undefined} Verified repository, or unknown.
301
+ */
302
+ function localRepository(context) {
303
+ if (!context.certainContext) return undefined;
304
+ if (context.env.GH_REPO) return repositoryFromSpec(context.env.GH_REPO);
305
+ if (context.cwd === undefined) return undefined;
306
+ const deadline = Date.now() + 5000;
307
+ const read = (command, args) => {
308
+ const remaining = deadline - Date.now();
309
+ if (remaining <= 0) throw new Error("Repository lookup deadline expired");
310
+ return execFileSync(command, args, {
311
+ cwd: context.cwd,
312
+ env: { ...context.env, GH_PROMPT_DISABLED: "1" },
313
+ timeout: remaining,
314
+ encoding: "utf8",
315
+ stdio: ["ignore", "pipe", "pipe"],
316
+ }).trim();
317
+ };
318
+ try {
319
+ const selected = read("gh", ["repo", "set-default", "--view"]);
320
+ if (selected !== "") return repositoryFromSpec(selected);
321
+ const remotes = read("git", ["remote"]).split("\n").filter(Boolean);
322
+ if (remotes.length !== 1) return undefined;
323
+ return repositoryFromSpec(read("git", ["remote", "get-url", remotes[0]]));
324
+ } catch {
325
+ // probe-direction: fail-closed — failed lookup grants no host exemption;
326
+ // the caller retains its inspection path for an undetermined target.
327
+ return undefined;
328
+ }
329
+ }
330
+
331
+ /**
332
+ * Resolve only active command arguments; prose cannot masquerade as routing.
333
+ * @param {object} context One parsed gh call.
334
+ * @returns {string|undefined} Verified owner/repository, or unknown.
335
+ */
336
+ export function commandRepository(context) {
337
+ if (!context.certain || !context.certainContext) return undefined;
338
+ if (context.noun !== "api") {
339
+ // gh 2.88.1 issue comment/edit and PR finder resolve a URL selector before
340
+ // BaseRepo (--repo/GH_REPO/local default). Body option values are not here.
341
+ const selectors = context.positional.slice(2);
342
+ const batch =
343
+ context.noun === "issue" && context.positional[1]?.value === "edit";
344
+ if (
345
+ (batch && selectors.length > 1) ||
346
+ (["comment", "edit"].includes(context.positional[1]?.value) &&
347
+ selectors.some(item => /^https?:\/\//u.test(item.value)))
348
+ ) {
349
+ if (!batch && selectors.length !== 1) return undefined;
350
+ let repository, identity;
351
+ for (const item of selectors) {
352
+ // ParseIssuesFromArgs lets numeric selectors inherit the common URL repo.
353
+ if (batch && /^#?[+-]?\d+$/u.test(item.value)) {
354
+ const number = BigInt(item.value.replace(/^#/u, ""));
355
+ if (BigInt.asIntN(64, number) !== number) return undefined;
356
+ continue;
357
+ }
358
+ const selected =
359
+ /^https?:\/\/[^/]+\/([\w.-]+)\/([\w.-]+)\/(issues|pull)\/\d+(?:[/?#].*)?$/u.exec(
360
+ item.value
361
+ );
362
+ if (!selected || (context.noun === "pr" && selected[3] !== "pull"))
363
+ return undefined;
364
+ try {
365
+ const host = new URL(item.value).hostname
366
+ .replace(/^www\./u, "")
367
+ .toLowerCase();
368
+ const repo = batch
369
+ ? `${selected[1]}/${selected[2]}`.toLowerCase()
370
+ : repositoryFromSpec(`${selected[1]}/${selected[2]}`);
371
+ const current = `${host}/${repo}`;
372
+ if (
373
+ !host ||
374
+ !repo ||
375
+ (identity !== undefined && identity !== current)
376
+ )
377
+ return undefined;
378
+ identity = current;
379
+ repository = repo;
380
+ } catch {
381
+ // probe-direction: fail-closed — invalid URL grants no host exemption;
382
+ // the caller retains its inspection path for an undetermined target.
383
+ return undefined;
384
+ }
385
+ }
386
+ if (repository !== undefined) return repository;
387
+ }
388
+ const explicit = context.flags.get("--repo") ?? context.flags.get("-R");
389
+ return explicit
390
+ ? explicit.literal
391
+ ? repositoryFromSpec(explicit.value)
392
+ : undefined
393
+ : localRepository(context);
394
+ }
395
+ const endpoint = context.positional[1];
396
+ if (!endpoint?.literal) return undefined;
397
+ let value = endpoint.value;
398
+ if (/\{(?:owner|repo)\}/u.test(value)) {
399
+ const repository = localRepository(context);
400
+ if (repository === undefined) return undefined;
401
+ const [owner, repo] = repository.split("/");
402
+ value = value.replaceAll("{owner}", owner).replaceAll("{repo}", repo);
403
+ }
404
+ const found =
405
+ /^(?:https?:\/\/[^/]+\/)?\/?repos\/([\w.-]+)\/([\w.-]+)(?:\/|$)/u.exec(
406
+ value
407
+ );
408
+ return found ? repositoryFromSpec(`${found[1]}/${found[2]}`) : undefined;
409
+ }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa",
3
- "version": "4.84.5",
3
+ "version": "4.84.7",
4
4
  "description": "Universal governance — agents, skills, commands, hooks, and rules for all projects",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "4.84.5",
3
+ "version": "4.84.7",
4
4
  "description": "AWS CDK-specific plugin",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "4.84.5",
3
+ "version": "4.84.7",
4
4
  "description": "AWS CDK-specific Lisa plugin.",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa-cdk",
3
- "version": "4.84.5",
3
+ "version": "4.84.7",
4
4
  "description": "AWS CDK-specific plugin",
5
5
  "author": {
6
6
  "name": "Cody Swann"