@jwilger/pi-development-system 0.8.6 → 0.8.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jwilger/pi-development-system",
3
- "version": "0.8.6",
3
+ "version": "0.8.7",
4
4
  "description": "A pi extension package representing a seasoned approach to software development using a full AI SDLC.",
5
5
  "keywords": [
6
6
  "pi-package"
@@ -1,5 +1,5 @@
1
1
  import { splitLines } from "./git-intent.ts";
2
- import { resolveGit } from "./git-invocations.ts";
2
+ import { opaqueMentions, resolveGit } from "./git-invocations.ts";
3
3
  import { stripHeredocs } from "./heredoc.ts";
4
4
 
5
5
  export type CommitExtraction =
@@ -120,7 +120,7 @@ export function extractCommits(command: string): CommitExtraction[] {
120
120
  const found = resolution.invocations.flatMap((g) =>
121
121
  g.sub === "commit" ? [extractOne(g.args, heredocFrom(lines, g.line, bodies))] : [],
122
122
  );
123
- const hidden = resolution.opaque && /\bcommit\b/.test(command);
123
+ const hidden = opaqueMentions(resolution, "commit");
124
124
  return hidden ? [...found, unknown()] : found;
125
125
  }
126
126
 
@@ -27,12 +27,13 @@ export type GitInvocation = {
27
27
  export type GitResolution = {
28
28
  readonly invocations: readonly GitInvocation[];
29
29
  /** True when git may run through something the parser cannot see into (xargs, `$CMD`, …). */
30
- readonly opaque: boolean;
30
+ /** Words of segments that may run git in a way that cannot be read (`$GIT push`, `xargs git …`). */
31
+ readonly opaque: readonly string[];
31
32
  };
32
33
 
33
34
  type Collector = {
34
35
  invocations: GitInvocation[];
35
- opaque: boolean;
36
+ opaque: string[];
36
37
  dir: string | undefined;
37
38
  line: number;
38
39
  };
@@ -58,7 +59,7 @@ function visitGit(rest: readonly string[], into: Collector): void {
58
59
  }
59
60
  const sub = rest[j];
60
61
  if (sub === undefined) return;
61
- if (sub.startsWith("$")) into.opaque = true;
62
+ if (sub.startsWith("$")) into.opaque.push(...rest);
62
63
  else {
63
64
  const args = rest.slice(j + 1);
64
65
  const line = into.line;
@@ -89,11 +90,12 @@ function visitSegment(tokens: readonly string[], into: Collector): void {
89
90
  if (head === undefined) return;
90
91
  const rest = tokens.slice(firstCommand(tokens) + 1);
91
92
  const base = basename(head);
92
- if (head.startsWith("$")) into.opaque = true;
93
+ if (head.startsWith("$")) into.opaque.push(...tokens);
93
94
  else if (base === "cd") visitCd(rest, into);
94
95
  else if (SHELLS.has(base) || base === "eval") visitScript(base, rest, into);
95
- else if (OPAQUE.has(base)) into.opaque = into.opaque || gitIndex(rest) >= 0;
96
- else if (base === "git") visitGit(rest, into);
96
+ else if (OPAQUE.has(base)) {
97
+ if (gitIndex(rest) >= 0) into.opaque.push(...rest);
98
+ } else if (base === "git") visitGit(rest, into);
97
99
  else visitWrapped(base, rest, into);
98
100
  }
99
101
 
@@ -105,7 +107,7 @@ function visitWrapped(base: string, rest: readonly string[], into: Collector): v
105
107
 
106
108
  function merge(into: Collector, other: GitResolution): void {
107
109
  into.invocations.push(...other.invocations.map((g) => ({ ...g, line: into.line })));
108
- if (other.opaque) into.opaque = true;
110
+ into.opaque.push(...other.opaque);
109
111
  }
110
112
 
111
113
  /**
@@ -113,7 +115,7 @@ function merge(into: Collector, other: GitResolution): void {
113
115
  * `timeout`, `if … then`), `bash -c`/`eval` scripts and `$(…)` substitutions. Heredoc bodies are data.
114
116
  */
115
117
  export function resolveGit(command: string): GitResolution {
116
- const into: Collector = { invocations: [], opaque: false, dir: undefined, line: 0 };
118
+ const into: Collector = { invocations: [], opaque: [], dir: undefined, line: 0 };
117
119
  let heredocEnd: string | undefined;
118
120
  // Heredoc bodies are data (an apostrophe in one must not unbalance quote tracking).
119
121
  const lines = splitLines(stripHeredocs(command).rest);
@@ -129,3 +131,7 @@ export function resolveGit(command: string): GitResolution {
129
131
  }
130
132
  return into;
131
133
  }
134
+
135
+ /** Whether something unreadable in the command may be running `git <subcommand>`. */
136
+ export const opaqueMentions = (resolution: GitResolution, subcommand: string): boolean =>
137
+ resolution.opaque.includes(subcommand);
@@ -1,4 +1,4 @@
1
- import { resolveGit } from "./git-invocations.ts";
1
+ import { opaqueMentions, resolveGit } from "./git-invocations.ts";
2
2
 
3
3
  export type PushTarget = {
4
4
  readonly remote: string | undefined;
@@ -73,7 +73,7 @@ export function pushTargets(command: string): PushTarget[] {
73
73
  g.sub === "push" && !isDryRun(g.args) ? [toTarget(g.args, g.dir)] : [],
74
74
  );
75
75
  // git run through something opaque (xargs, `$CMD`): a push cannot be ruled out, so assume the worst.
76
- const opaquePush = resolution.opaque && /\bpush\b/.test(command);
76
+ const opaquePush = opaqueMentions(resolution, "push");
77
77
  return opaquePush
78
78
  ? [
79
79
  ...targets,