@yagni-app/code 0.2.1 → 0.3.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.
Files changed (98) hide show
  1. package/dist/cli.d.ts +30 -0
  2. package/dist/cli.js +147 -3
  3. package/dist/connectClaudeCode.d.ts +77 -0
  4. package/dist/connectClaudeCode.js +228 -0
  5. package/dist/connectCodex.d.ts +75 -0
  6. package/dist/connectCodex.js +201 -0
  7. package/dist/doctor.d.ts +1 -1
  8. package/dist/doctor.js +1 -1
  9. package/dist/extension/advisor.d.ts +4 -4
  10. package/dist/extension/advisor.js +6 -7
  11. package/dist/extension/approvedPrefixes.d.ts +103 -0
  12. package/dist/extension/approvedPrefixes.js +282 -0
  13. package/dist/extension/askAdvisorTool.d.ts +20 -5
  14. package/dist/extension/askAdvisorTool.js +126 -20
  15. package/dist/extension/askYagniTool.d.ts +23 -0
  16. package/dist/extension/askYagniTool.js +91 -2
  17. package/dist/extension/branding.d.ts +34 -3
  18. package/dist/extension/branding.js +114 -13
  19. package/dist/extension/chipEditor.d.ts +30 -9
  20. package/dist/extension/chipEditor.js +173 -59
  21. package/dist/extension/claudeRules.d.ts +0 -2
  22. package/dist/extension/claudeRules.js +0 -8
  23. package/dist/extension/cmux/dispatcher.d.ts +25 -0
  24. package/dist/extension/cmux/dispatcher.js +266 -0
  25. package/dist/extension/cmux/hooks.d.ts +12 -0
  26. package/dist/extension/cmux/hooks.js +192 -0
  27. package/dist/extension/cmux/index.d.ts +3 -0
  28. package/dist/extension/cmux/index.js +155 -0
  29. package/dist/extension/cmux/naming.d.ts +5 -0
  30. package/dist/extension/cmux/naming.js +23 -0
  31. package/dist/extension/cmux/state.d.ts +33 -0
  32. package/dist/extension/cmux/state.js +142 -0
  33. package/dist/extension/config.d.ts +44 -1
  34. package/dist/extension/config.js +37 -4
  35. package/dist/extension/costHud.d.ts +16 -22
  36. package/dist/extension/costHud.js +8 -47
  37. package/dist/extension/crashReport.js +1 -3
  38. package/dist/extension/execPolicy.d.ts +135 -0
  39. package/dist/extension/execPolicy.js +936 -0
  40. package/dist/extension/flywheel.d.ts +44 -0
  41. package/dist/extension/flywheel.js +53 -0
  42. package/dist/extension/footer.d.ts +118 -0
  43. package/dist/extension/footer.js +308 -0
  44. package/dist/extension/guardian.d.ts +139 -0
  45. package/dist/extension/guardian.js +237 -0
  46. package/dist/extension/index.d.ts +35 -7
  47. package/dist/extension/index.js +338 -33
  48. package/dist/extension/mineBeat.d.ts +95 -0
  49. package/dist/extension/mineBeat.js +193 -0
  50. package/dist/extension/permission.d.ts +124 -10
  51. package/dist/extension/permission.js +603 -52
  52. package/dist/extension/pipeline/childRegistry.d.ts +41 -0
  53. package/dist/extension/pipeline/childRegistry.js +118 -0
  54. package/dist/extension/pipeline/finish.js +5 -1
  55. package/dist/extension/pipeline/goCommand.d.ts +1 -1
  56. package/dist/extension/pipeline/goCommand.js +40 -9
  57. package/dist/extension/pipeline/goStatusCommands.d.ts +10 -0
  58. package/dist/extension/pipeline/goStatusCommands.js +61 -1
  59. package/dist/extension/pipeline/personas.js +26 -1
  60. package/dist/extension/pipeline/resilience.d.ts +2 -1
  61. package/dist/extension/pipeline/resilience.js +21 -2
  62. package/dist/extension/pipeline/runRegistry.d.ts +23 -1
  63. package/dist/extension/pipeline/runRegistry.js +57 -1
  64. package/dist/extension/pipeline/runner.js +4 -0
  65. package/dist/extension/pipeline/verify.d.ts +4 -0
  66. package/dist/extension/pipeline/verify.js +48 -26
  67. package/dist/extension/recordDecisionTool.d.ts +8 -0
  68. package/dist/extension/recordDecisionTool.js +24 -0
  69. package/dist/extension/redact.d.ts +20 -0
  70. package/dist/extension/redact.js +64 -0
  71. package/dist/extension/rerouteNotice.d.ts +3 -4
  72. package/dist/extension/rerouteNotice.js +20 -11
  73. package/dist/extension/subagentRender.d.ts +129 -0
  74. package/dist/extension/subagentRender.js +441 -0
  75. package/dist/extension/subagents.d.ts +11 -8
  76. package/dist/extension/subagents.js +162 -37
  77. package/dist/extension/ticketTools.d.ts +37 -0
  78. package/dist/extension/ticketTools.js +117 -0
  79. package/dist/extension/todos.d.ts +28 -1
  80. package/dist/extension/todos.js +76 -1
  81. package/dist/extension/tokenProvider.js +46 -5
  82. package/dist/extension/ultra.d.ts +27 -0
  83. package/dist/extension/ultra.js +76 -0
  84. package/dist/launch.d.ts +7 -0
  85. package/dist/launch.js +24 -12
  86. package/dist/login.d.ts +4 -2
  87. package/dist/login.js +19 -4
  88. package/dist/padding.d.ts +22 -0
  89. package/dist/padding.js +25 -0
  90. package/dist/promptEnrichment.d.ts +40 -0
  91. package/dist/promptEnrichment.js +85 -0
  92. package/dist/signalForward.d.ts +60 -0
  93. package/dist/signalForward.js +130 -0
  94. package/dist/token.d.ts +25 -0
  95. package/dist/token.js +45 -0
  96. package/package.json +6 -5
  97. package/dist/extension/boostCommand.d.ts +0 -144
  98. package/dist/extension/boostCommand.js +0 -263
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Ultra mode (/ultra) — an explicit, session-scoped dial for aggressive
3
+ * multi-agent orchestration ("the diamond": fan out → reduce → synthesize).
4
+ *
5
+ * Off by default so the trial-default behavior is unchanged; toggling on swaps
6
+ * the driver's delegation paragraph for the diamond directive (branding.ts's
7
+ * YAGNI_IDENTITY_ULTRA) and widens the subagent tool's per-call fan-out
8
+ * ceiling (subagents.ts). The two halves take effect at different moments:
9
+ * the fan-out ceiling is probed live on every subagent call, but the identity
10
+ * is read in index.ts's before_agent_start handler, which pi fires only when
11
+ * a NEW user prompt is submitted — a toggle mid-run leaves the running task on
12
+ * its existing instructions until the next message (the handler notifies when
13
+ * that is the case). Ultra is a prompt + ceiling change only: it never touches
14
+ * the permission mode, the model tier, or the /go pipeline.
15
+ */
16
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
17
+ export interface UltraHolder {
18
+ get(): boolean;
19
+ set(on: boolean): void;
20
+ }
21
+ export declare function createUltraHolder(initial?: boolean): UltraHolder;
22
+ /**
23
+ * Wire the /ultra command onto a shared holder. No argument toggles; `on` /
24
+ * `off` set explicitly; `status` reports without changing anything.
25
+ */
26
+ export declare function registerUltraCommand(pi: ExtensionAPI, holder: UltraHolder): void;
27
+ //# sourceMappingURL=ultra.d.ts.map
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Ultra mode (/ultra) — an explicit, session-scoped dial for aggressive
3
+ * multi-agent orchestration ("the diamond": fan out → reduce → synthesize).
4
+ *
5
+ * Off by default so the trial-default behavior is unchanged; toggling on swaps
6
+ * the driver's delegation paragraph for the diamond directive (branding.ts's
7
+ * YAGNI_IDENTITY_ULTRA) and widens the subagent tool's per-call fan-out
8
+ * ceiling (subagents.ts). The two halves take effect at different moments:
9
+ * the fan-out ceiling is probed live on every subagent call, but the identity
10
+ * is read in index.ts's before_agent_start handler, which pi fires only when
11
+ * a NEW user prompt is submitted — a toggle mid-run leaves the running task on
12
+ * its existing instructions until the next message (the handler notifies when
13
+ * that is the case). Ultra is a prompt + ceiling change only: it never touches
14
+ * the permission mode, the model tier, or the /go pipeline.
15
+ */
16
+ export function createUltraHolder(initial = false) {
17
+ let on = initial;
18
+ return {
19
+ get: () => on,
20
+ set: (v) => {
21
+ on = v;
22
+ },
23
+ };
24
+ }
25
+ /** Status chip shown while ultra is on (same footer surface as the /mode chip). */
26
+ const ULTRA_STATUS = "◆ ultra";
27
+ const ULTRA_ON_COPY = "Ultra mode ON: meaningful work fans out to parallel subagents, adversarial " +
28
+ "verification agents try to break the result, then the agent synthesizes. " +
29
+ "Expect more subagent spend per task.";
30
+ const ULTRA_OFF_COPY = "Ultra mode OFF: back to delegate-when-useful.";
31
+ /**
32
+ * Appended when the toggle lands mid-run: the identity swap only applies when
33
+ * the next prompt is submitted (see the module docblock), so without this note
34
+ * the chip flips while the running task visibly keeps its old behavior — which
35
+ * reads as ultra mode being broken.
36
+ */
37
+ const MID_RUN_NOTE = " The task currently running keeps its existing instructions; the change takes full effect on your next message.";
38
+ /**
39
+ * Wire the /ultra command onto a shared holder. No argument toggles; `on` /
40
+ * `off` set explicitly; `status` reports without changing anything.
41
+ */
42
+ export function registerUltraCommand(pi, holder) {
43
+ pi.registerCommand("ultra", {
44
+ description: "Toggle ultra mode: aggressive fan-out/verify/synthesize orchestration. /ultra on | off | status.",
45
+ handler: async (args, ctx) => {
46
+ const notify = (m, t) => {
47
+ if (ctx.hasUI)
48
+ ctx.ui.notify(m, t);
49
+ };
50
+ const arg = args.trim().toLowerCase();
51
+ if (arg && arg !== "on" && arg !== "off" && arg !== "status") {
52
+ notify(`Unknown argument "${arg}". Use /ultra, /ultra on, /ultra off, or /ultra status.`, "warning");
53
+ return;
54
+ }
55
+ if (arg === "status") {
56
+ notify(holder.get() ? ULTRA_ON_COPY : ULTRA_OFF_COPY, "info");
57
+ return;
58
+ }
59
+ const next = arg === "on" ? true : arg === "off" ? false : !holder.get();
60
+ holder.set(next);
61
+ try {
62
+ if (ctx.hasUI)
63
+ ctx.ui.setStatus?.("yagni-ultra", next ? ULTRA_STATUS : undefined);
64
+ }
65
+ catch {
66
+ // The chip is chrome; never let it break /ultra.
67
+ }
68
+ // Guarded probe: test fakes (and any minimal harness ctx) may not carry
69
+ // isIdle, and its absence must read as idle, never as busy.
70
+ const midRun = typeof ctx.isIdle === "function" && !ctx.isIdle();
71
+ const copy = next ? ULTRA_ON_COPY : ULTRA_OFF_COPY;
72
+ notify(midRun ? copy + MID_RUN_NOTE : copy, "info");
73
+ },
74
+ });
75
+ }
76
+ //# sourceMappingURL=ultra.js.map
package/dist/launch.d.ts CHANGED
@@ -71,6 +71,13 @@ export interface BuildLaunchOptions {
71
71
  cliVersion?: string;
72
72
  /** Base environment to extend (defaults to process.env at call sites). */
73
73
  baseEnv?: NodeJS.ProcessEnv;
74
+ /**
75
+ * Whether this launch freshly collapsed reasoning (seeded `hideThinkingBlock`
76
+ * for the first time). Forwarded as `YAGNI_HIDE_THINKING_SEEDED=1` so the
77
+ * extension can surface a single one-time "reasoning is collapsed" hint.
78
+ * Omitted/false on repeat launches: the hint must not re-nag.
79
+ */
80
+ hideThinkingSeeded?: boolean;
74
81
  /** Clock seam for the token-expiry preflight (defaults to Date.now). */
75
82
  now?: () => number;
76
83
  /**
package/dist/launch.js CHANGED
@@ -7,6 +7,8 @@
7
7
  */
8
8
  import { randomUUID } from "node:crypto";
9
9
  import { agentDirEnvVar } from "./branding.js";
10
+ import { PAD_X_ENV, resolvePadX } from "./padding.js";
11
+ import { ENGINEERING_PRACTICE_SECTION, promptEnrichmentDisabled } from "./promptEnrichment.js";
10
12
  /**
11
13
  * How close to expiry the token can be before launch warns. A coding session
12
14
  * easily outlives a token, so warn early enough that re-logging in before a long
@@ -95,27 +97,37 @@ export function buildLaunch(creds, passthroughArgs, opts) {
95
97
  // Match the e2b harness defaults: skip pi's update check + telemetry.
96
98
  PI_SKIP_VERSION_CHECK: "1",
97
99
  PI_TELEMETRY: "0",
100
+ // One-time marker for the "reasoning is collapsed" hint: only set on the
101
+ // launch that actually seeded the collapse default. Absent on every later
102
+ // launch so the hint never re-nags. (See hideThinkingSeeded in the docs.)
103
+ ...(opts.hideThinkingSeeded ? { YAGNI_HIDE_THINKING_SEEDED: "1" } : {}),
104
+ // Forward the chosen horizontal pad so the extension's footer aligns with
105
+ // the editor (which the launcher pads by seeding editorPaddingX). The
106
+ // footer can't read pi's settings, so the value crosses over env.
107
+ [PAD_X_ENV]: String(resolvePadX()),
98
108
  };
99
109
  // Always load our extension. Default the provider to `yagni` unless the user
100
110
  // explicitly chose one (so power users can still point pi elsewhere).
101
111
  const userChoseProvider = passthroughArgs.some(arg => arg === "--provider" || arg.startsWith("--provider="));
102
- // Default the model to the `balanced` tier (YAG-380). Balanced drives on the
103
- // judgment-grade `advanced` model and additionally lets the session escalate
104
- // hard calls to `peak` through the capped ask_advisor tool. So it is strictly
105
- // additive: no session reasons worse than plain advanced, and the hard ones
106
- // can reason better. A user `--model` (e.g. `standard` or `efficient`) still
107
- // wins. Without this, pi's default-model heuristic could land an interactive
108
- // session on a weaker tier.
109
- // Detect if the user explicitly set a model, whether via "--model" as a separate
110
- // argument or using the equals form "--model=efficient". The previous check only
111
- // caught the separate form, causing a duplicate "--model balanced" to be added
112
- // when the equals form was used.
112
+ // Default the model to the `advanced` tier. The model is locked: the
113
+ // catalog is filtered to only `advanced` (see index.ts), so the user
114
+ // cannot switch to a different tier via /model or Ctrl+P. The proxy still
115
+ // resolves the tier to the concrete backing model.
113
116
  const userChoseModel = passthroughArgs.some(arg => arg === "--model" || arg.startsWith("--model="));
117
+ // Engineering-practice enrichment (YAG-496): appended to the DRIVER's system
118
+ // prompt only — /go stage children and subagents build their own pi argv, so
119
+ // this flag never reaches them. pi treats the value as literal text (it is
120
+ // never an existing file path) and slots it before <project_context>, so the
121
+ // user's repo instructions still outrank it. The flag is repeatable, so a
122
+ // user-passed --append-system-prompt coexists rather than conflicting; the
123
+ // opt-out is YAGNI_DISABLE_PROMPT_ENRICHMENT.
124
+ const enrichmentOff = promptEnrichmentDisabled(opts.baseEnv ?? process.env);
114
125
  const argv = [
115
126
  "-e",
116
127
  opts.extensionPath,
117
128
  ...(userChoseProvider ? [] : ["--provider", "yagni"]),
118
- ...(userChoseModel ? [] : ["--model", "balanced"]),
129
+ ...(userChoseModel ? [] : ["--model", "advanced"]),
130
+ ...(enrichmentOff ? [] : ["--append-system-prompt", ENGINEERING_PRACTICE_SECTION]),
119
131
  ...(opts.extraAgentArgs ?? []),
120
132
  ...passthroughArgs,
121
133
  ];
package/dist/login.d.ts CHANGED
@@ -34,8 +34,10 @@ type OpenRunner = (cmd: string, args: string[]) => Promise<void>;
34
34
  *
35
35
  * macOS: open <url>
36
36
  * Linux: xdg-open <url>
37
- * Windows: cmd /c start "" <url> (the empty "" is start's window-title slot;
38
- * without it `start` swallows the URL as the title and opens nothing)
37
+ * Windows: rundll32 url.dll,FileProtocolHandler <url> (opens the default
38
+ * browser without going through cmd.exe `cmd /c start <url>`
39
+ * re-parses its arguments as a shell line, so a hostile URL with
40
+ * `&`/`^` metacharacters could execute commands)
39
41
  */
40
42
  export declare function resolveOpenCommand(url: string, platform?: NodeJS.Platform): {
41
43
  cmd: string;
package/dist/login.js CHANGED
@@ -31,14 +31,17 @@ function isTimeoutError(err) {
31
31
  *
32
32
  * macOS: open <url>
33
33
  * Linux: xdg-open <url>
34
- * Windows: cmd /c start "" <url> (the empty "" is start's window-title slot;
35
- * without it `start` swallows the URL as the title and opens nothing)
34
+ * Windows: rundll32 url.dll,FileProtocolHandler <url> (opens the default
35
+ * browser without going through cmd.exe `cmd /c start <url>`
36
+ * re-parses its arguments as a shell line, so a hostile URL with
37
+ * `&`/`^` metacharacters could execute commands)
36
38
  */
37
39
  export function resolveOpenCommand(url, platform = process.platform) {
38
40
  if (platform === "darwin")
39
41
  return { cmd: "open", args: [url] };
40
- if (platform === "win32")
41
- return { cmd: "cmd", args: ["/c", "start", "", url] };
42
+ if (platform === "win32") {
43
+ return { cmd: "rundll32", args: ["url.dll,FileProtocolHandler", url] };
44
+ }
42
45
  return { cmd: "xdg-open", args: [url] };
43
46
  }
44
47
  const spawnRunner = (cmd, args) => new Promise((resolve, reject) => {
@@ -50,6 +53,18 @@ const spawnRunner = (cmd, args) => new Promise((resolve, reject) => {
50
53
  * URL is still printed for manual copy. `runner` is injectable for tests.
51
54
  */
52
55
  export const realOpenUrl = (url, runner = spawnRunner) => {
56
+ // Only ever hand http(s) URLs to the OS opener — refuse file:, javascript:,
57
+ // or custom schemes a compromised server response could try to smuggle in.
58
+ let parsed;
59
+ try {
60
+ parsed = new URL(url);
61
+ }
62
+ catch {
63
+ return Promise.resolve();
64
+ }
65
+ if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
66
+ return Promise.resolve();
67
+ }
53
68
  const { cmd, args } = resolveOpenCommand(url);
54
69
  return runner(cmd, args).catch(() => {
55
70
  // Silently fail — the user can still copy the URL manually.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Single source of truth for the CLI's horizontal padding, shared by the
3
+ * launcher (which seeds the editor setting) and — via the `YAGNI_PAD_X` env the
4
+ * launcher forwards — pi-extension-yagni's footer.
5
+ *
6
+ * The value must match pi's `outputPad` (the chat/output area's left+right
7
+ * padding, which defaults to 1) so the input editor, the output stream, and
8
+ * the status bar all align on the same column. Keeping it in one module makes
9
+ * the coherence structural rather than eyeballed: change this one number and
10
+ * the editor, footer, and seeded default move together.
11
+ *
12
+ * Separators (the ─ rules above/below the input) intentionally stay full-bleed
13
+ * and are NOT padded — matching Claude Code's frame.
14
+ */
15
+ export declare const PAD_X = 1;
16
+ /** Left (and right) padding string applied to the editor and footer. */
17
+ export declare const PAD_STR: string;
18
+ /** Env var the launcher sets so the extension's footer can match the editor pad. */
19
+ export declare const PAD_X_ENV = "YAGNI_PAD_X";
20
+ /** Parse a pad width from the env override, falling back to {@link PAD_X}. */
21
+ export declare function resolvePadX(raw?: string | undefined): number;
22
+ //# sourceMappingURL=padding.d.ts.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Single source of truth for the CLI's horizontal padding, shared by the
3
+ * launcher (which seeds the editor setting) and — via the `YAGNI_PAD_X` env the
4
+ * launcher forwards — pi-extension-yagni's footer.
5
+ *
6
+ * The value must match pi's `outputPad` (the chat/output area's left+right
7
+ * padding, which defaults to 1) so the input editor, the output stream, and
8
+ * the status bar all align on the same column. Keeping it in one module makes
9
+ * the coherence structural rather than eyeballed: change this one number and
10
+ * the editor, footer, and seeded default move together.
11
+ *
12
+ * Separators (the ─ rules above/below the input) intentionally stay full-bleed
13
+ * and are NOT padded — matching Claude Code's frame.
14
+ */
15
+ export const PAD_X = 1;
16
+ /** Left (and right) padding string applied to the editor and footer. */
17
+ export const PAD_STR = " ".repeat(PAD_X);
18
+ /** Env var the launcher sets so the extension's footer can match the editor pad. */
19
+ export const PAD_X_ENV = "YAGNI_PAD_X";
20
+ /** Parse a pad width from the env override, falling back to {@link PAD_X}. */
21
+ export function resolvePadX(raw = process.env[PAD_X_ENV]) {
22
+ const n = raw === undefined ? NaN : Number.parseInt(raw, 10);
23
+ return Number.isFinite(n) && n >= 0 && n <= 3 ? n : PAD_X;
24
+ }
25
+ //# sourceMappingURL=padding.js.map
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Engineering-practice prompt enrichment (YAG-496).
3
+ *
4
+ * pi's own base system prompt is deliberately thin (~15 lines: identity, tool
5
+ * one-liners, two generic guidelines). The extension adds identity, grounding,
6
+ * and product-tool guidance — but nothing about general engineering behavior:
7
+ * conventions, verification, commit discipline, communication style. This
8
+ * section carries that missing middle, curated from the prompt lineage shared
9
+ * by OpenCode/Claude Code/Kimi CLI and adapted to YAGNI Code's tools and
10
+ * autonomy posture.
11
+ *
12
+ * Delivery mechanism: pi's `--append-system-prompt <text>` flag, injected by
13
+ * the launcher (launch.ts). pi places appended text after its Guidelines and
14
+ * BEFORE the user's <project_context>, so repo instructions still outrank it.
15
+ * Because `/go` stage children and subagents build their own pi argv
16
+ * (pi-extension-yagni's pipeline/invocation.ts and pipeline/runner.ts), a
17
+ * launcher flag is structurally driver-only: child prompts are untouched by
18
+ * construction, not by an `if`. The piContract test pins both properties.
19
+ *
20
+ * Content constraints (enforced by test/promptEnrichment.test.ts):
21
+ * - must not contain the standalone word "pi" — the extension's brand scrub
22
+ * rewrites it to "YAGNI Code" and would mangle the sentence;
23
+ * - must not OPEN with a "- " bullet line — pi's self-referential docs block
24
+ * (which the extension strips with a regex that consumes consecutive
25
+ * bullets) sits directly above this section in the assembled prompt;
26
+ * - no emojis (the section itself forbids them).
27
+ */
28
+ /** Env switch that skips the enrichment entirely (sibling of
29
+ * YAGNI_DISABLE_BRANDING / YAGNI_DISABLE_CLAUDE_COMPAT, same semantics). */
30
+ export declare const ENRICHMENT_DISABLE_ENV = "YAGNI_DISABLE_PROMPT_ENRICHMENT";
31
+ /** `"1"`/anything truthy disables; unset, empty, and `"0"` keep it on. */
32
+ export declare function promptEnrichmentDisabled(env: NodeJS.ProcessEnv): boolean;
33
+ /**
34
+ * The section appended to the driver session's system prompt. Keep it curated,
35
+ * not encyclopedic: every line here spends attention budget on an open-weight
36
+ * model, and the load-bearing instructions (ask_yagni contract, delegation)
37
+ * live elsewhere in the prompt.
38
+ */
39
+ export declare const ENGINEERING_PRACTICE_SECTION = "Engineering practice:\n\nBias to action: when the user asks you to implement, fix, or change something, use your tools to make the actual edits and run the actual commands \u2014 do not answer with a description of what you would do, or with code for the user to apply themselves. When the user asks HOW to approach something, answer the question first; do not jump into making changes they have not asked for.\n\nConventions:\n- Never assume a library is available, however well known. Before using one, confirm the project already depends on it (its package manifest, or imports in neighboring files).\n- When editing, read the surrounding code and its imports first; match the file's existing style, naming, and patterns rather than introducing your own.\n- When creating a new file or component, study an existing sibling first and follow its structure.\n- Never write code that logs or exposes secrets, keys, or credentials.\n\nVerification:\n- Consider what the code you are changing is supposed to do (from its name, location, and callers) before you change it.\n- Verify changes with the project's own tests when possible. Never assume a test framework or command \u2014 check the README, package scripts, or neighboring tests for the real one.\n- After completing a task, run the project's lint and typecheck commands if you know them; if you cannot find them, ask the user and suggest recording them in AGENTS.md for next time.\n\nVersion control:\n- No unsolicited commits: commit only when the user asked for one or the task at hand clearly calls for it.\n\nGit safety:\n- You may be in a dirty git worktree. Never revert existing changes you did not make unless explicitly asked \u2014 these were made by the user.\n- If there are unrelated changes in files you are touching, read and work with them rather than reverting.\n- If changes appear in unrelated files, ignore them and do not revert.\n- Do not amend a commit unless explicitly asked.\n- If you notice unexpected changes you did not make while working, stop immediately and ask the user.\n- Never use destructive git commands (git reset --hard, git checkout --) unless the user explicitly requests or approves them.\n\nTodo discipline:\n- Track multi-step work with todo_write: keep exactly one item in_progress at a time, mark items completed the moment they are done, and add newly discovered steps as pending.\n- Do not batch-complete items or create single-step plans. Skip planning for trivially small work (~25% of tasks).\n\nMode awareness:\n- In auto mode, proactively run tests, lint, and typecheck after your changes.\n- In review mode, propose verification steps but wait for approval before running them.\n- In plan mode, explore and design only \u2014 the gate holds all writes.\n\nCommunication:\n- Answer directly, without preamble or postamble (\"Here is what I will do next...\", \"Based on the information provided...\"). Match the length of your answer to the question.\n- After making edits, report the outcome briefly; do not restate the diff or explain the code you just wrote unless asked.\n- Do not add code comments that narrate what you changed or why the change is correct; comments are for future readers of the code.\n- Reference code as file_path:line_number so the user can jump to it.\n- Before running a non-trivial command that changes state, say in one line what it does and why.\n- Never guess or fabricate URLs. Only use URLs the user provided or that appear in local files.\n- No emojis unless the user asks for them.";
40
+ //# sourceMappingURL=promptEnrichment.d.ts.map
@@ -0,0 +1,85 @@
1
+ /**
2
+ * Engineering-practice prompt enrichment (YAG-496).
3
+ *
4
+ * pi's own base system prompt is deliberately thin (~15 lines: identity, tool
5
+ * one-liners, two generic guidelines). The extension adds identity, grounding,
6
+ * and product-tool guidance — but nothing about general engineering behavior:
7
+ * conventions, verification, commit discipline, communication style. This
8
+ * section carries that missing middle, curated from the prompt lineage shared
9
+ * by OpenCode/Claude Code/Kimi CLI and adapted to YAGNI Code's tools and
10
+ * autonomy posture.
11
+ *
12
+ * Delivery mechanism: pi's `--append-system-prompt <text>` flag, injected by
13
+ * the launcher (launch.ts). pi places appended text after its Guidelines and
14
+ * BEFORE the user's <project_context>, so repo instructions still outrank it.
15
+ * Because `/go` stage children and subagents build their own pi argv
16
+ * (pi-extension-yagni's pipeline/invocation.ts and pipeline/runner.ts), a
17
+ * launcher flag is structurally driver-only: child prompts are untouched by
18
+ * construction, not by an `if`. The piContract test pins both properties.
19
+ *
20
+ * Content constraints (enforced by test/promptEnrichment.test.ts):
21
+ * - must not contain the standalone word "pi" — the extension's brand scrub
22
+ * rewrites it to "YAGNI Code" and would mangle the sentence;
23
+ * - must not OPEN with a "- " bullet line — pi's self-referential docs block
24
+ * (which the extension strips with a regex that consumes consecutive
25
+ * bullets) sits directly above this section in the assembled prompt;
26
+ * - no emojis (the section itself forbids them).
27
+ */
28
+ /** Env switch that skips the enrichment entirely (sibling of
29
+ * YAGNI_DISABLE_BRANDING / YAGNI_DISABLE_CLAUDE_COMPAT, same semantics). */
30
+ export const ENRICHMENT_DISABLE_ENV = "YAGNI_DISABLE_PROMPT_ENRICHMENT";
31
+ /** `"1"`/anything truthy disables; unset, empty, and `"0"` keep it on. */
32
+ export function promptEnrichmentDisabled(env) {
33
+ const value = env[ENRICHMENT_DISABLE_ENV];
34
+ return value !== undefined && value !== "" && value !== "0";
35
+ }
36
+ /**
37
+ * The section appended to the driver session's system prompt. Keep it curated,
38
+ * not encyclopedic: every line here spends attention budget on an open-weight
39
+ * model, and the load-bearing instructions (ask_yagni contract, delegation)
40
+ * live elsewhere in the prompt.
41
+ */
42
+ export const ENGINEERING_PRACTICE_SECTION = `Engineering practice:
43
+
44
+ Bias to action: when the user asks you to implement, fix, or change something, use your tools to make the actual edits and run the actual commands — do not answer with a description of what you would do, or with code for the user to apply themselves. When the user asks HOW to approach something, answer the question first; do not jump into making changes they have not asked for.
45
+
46
+ Conventions:
47
+ - Never assume a library is available, however well known. Before using one, confirm the project already depends on it (its package manifest, or imports in neighboring files).
48
+ - When editing, read the surrounding code and its imports first; match the file's existing style, naming, and patterns rather than introducing your own.
49
+ - When creating a new file or component, study an existing sibling first and follow its structure.
50
+ - Never write code that logs or exposes secrets, keys, or credentials.
51
+
52
+ Verification:
53
+ - Consider what the code you are changing is supposed to do (from its name, location, and callers) before you change it.
54
+ - Verify changes with the project's own tests when possible. Never assume a test framework or command — check the README, package scripts, or neighboring tests for the real one.
55
+ - After completing a task, run the project's lint and typecheck commands if you know them; if you cannot find them, ask the user and suggest recording them in AGENTS.md for next time.
56
+
57
+ Version control:
58
+ - No unsolicited commits: commit only when the user asked for one or the task at hand clearly calls for it.
59
+
60
+ Git safety:
61
+ - You may be in a dirty git worktree. Never revert existing changes you did not make unless explicitly asked — these were made by the user.
62
+ - If there are unrelated changes in files you are touching, read and work with them rather than reverting.
63
+ - If changes appear in unrelated files, ignore them and do not revert.
64
+ - Do not amend a commit unless explicitly asked.
65
+ - If you notice unexpected changes you did not make while working, stop immediately and ask the user.
66
+ - Never use destructive git commands (git reset --hard, git checkout --) unless the user explicitly requests or approves them.
67
+
68
+ Todo discipline:
69
+ - Track multi-step work with todo_write: keep exactly one item in_progress at a time, mark items completed the moment they are done, and add newly discovered steps as pending.
70
+ - Do not batch-complete items or create single-step plans. Skip planning for trivially small work (~25% of tasks).
71
+
72
+ Mode awareness:
73
+ - In auto mode, proactively run tests, lint, and typecheck after your changes.
74
+ - In review mode, propose verification steps but wait for approval before running them.
75
+ - In plan mode, explore and design only — the gate holds all writes.
76
+
77
+ Communication:
78
+ - Answer directly, without preamble or postamble ("Here is what I will do next...", "Based on the information provided..."). Match the length of your answer to the question.
79
+ - After making edits, report the outcome briefly; do not restate the diff or explain the code you just wrote unless asked.
80
+ - Do not add code comments that narrate what you changed or why the change is correct; comments are for future readers of the code.
81
+ - Reference code as file_path:line_number so the user can jump to it.
82
+ - Before running a non-trivial command that changes state, say in one line what it does and why.
83
+ - Never guess or fabricate URLs. Only use URLs the user provided or that appear in local files.
84
+ - No emojis unless the user asks for them.`;
85
+ //# sourceMappingURL=promptEnrichment.js.map
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Termination-signal forwarding: launcher → pi child.
3
+ *
4
+ * In the interactive TUI the tty is in raw mode, so Ctrl+C never raises
5
+ * SIGINT; this path covers `yagni -p`/piped/CI runs and an external
6
+ * `kill <launcher pid>`. Policy:
7
+ *
8
+ * - The FIRST signal asks pi to shut down cleanly. SIGINT is translated to
9
+ * SIGTERM because pi installs a graceful handler for SIGTERM (it kills its
10
+ * tracked children) but none for SIGINT — a raw SIGINT would drop pi on the
11
+ * default disposition with no cleanup.
12
+ * - Any SECOND signal hard-kills pi's whole process TREE. A bare SIGKILL to
13
+ * pi's pid would bypass its exit sweep (SIGKILL runs no handlers) and leave
14
+ * /go workers alive, so the launcher enumerates and kills the descendants
15
+ * itself: `ps` walk on POSIX, `taskkill /T /F` on Windows.
16
+ */
17
+ /** The minimal child surface the forwarder needs (ChildProcess satisfies it). */
18
+ export interface KillableChild {
19
+ pid?: number | undefined;
20
+ kill(signal: NodeJS.Signals): boolean;
21
+ }
22
+ /** The launcher-terminating signals that are forwarded rather than obeyed. */
23
+ export declare const FORWARDED_SIGNALS: readonly NodeJS.Signals[];
24
+ /**
25
+ * PURE policy for the FIRST signal: which signal the child receives when the
26
+ * launcher gets `received` (SIGINT is translated, the rest pass through).
27
+ * Escalation is not expressed here — a second signal goes through the tree
28
+ * kill, not a forwarded signal.
29
+ */
30
+ export declare function forwardedSignal(received: NodeJS.Signals): NodeJS.Signals;
31
+ /**
32
+ * PURE: the launcher's own exit code for the child's (code, signal) exit tuple.
33
+ * A signal-terminated child maps to the conventional 128+n (bash parity:
34
+ * SIGTERM→143, SIGKILL→137, SIGINT→130), so a cancelled run never reads as
35
+ * success to scripts or CI.
36
+ */
37
+ export declare function exitCodeFor(code: number | null, signal: NodeJS.Signals | null): number;
38
+ /**
39
+ * PURE: given `ps -A -o pid=,ppid=` output lines, collect every descendant of
40
+ * the given roots (children, grandchildren, ...), breadth-first. Mirrored in
41
+ * pi-extension-yagni's childRegistry (the packages are intentionally
42
+ * independent); keep the two in sync.
43
+ */
44
+ export declare function descendantsOf(roots: number[], psLines: string[]): number[];
45
+ /**
46
+ * Synchronously SIGKILL a process AND its descendants (POSIX `ps` walk /
47
+ * Windows `taskkill /T /F`). Throw-proof; fail-soft to a direct kill when no
48
+ * process snapshot is readable.
49
+ */
50
+ export declare function killTreeSync(pid: number): void;
51
+ /**
52
+ * Subscribe the forwarding policy for every signal in {@link FORWARDED_SIGNALS}.
53
+ * `subscribe` and `killTree` default to the real process surfaces and are
54
+ * injectable so tests never install real handlers, raise real signals, or kill
55
+ * real processes. Returns the forward function itself (also for tests).
56
+ * pid guard: a child whose spawn failed has no pid, and `kill()` would resolve
57
+ * that to the whole process group.
58
+ */
59
+ export declare function installSignalForwarding(child: KillableChild, subscribe?: (sig: NodeJS.Signals, handler: () => void) => void, killTree?: (pid: number) => void): (sig: NodeJS.Signals) => void;
60
+ //# sourceMappingURL=signalForward.d.ts.map
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Termination-signal forwarding: launcher → pi child.
3
+ *
4
+ * In the interactive TUI the tty is in raw mode, so Ctrl+C never raises
5
+ * SIGINT; this path covers `yagni -p`/piped/CI runs and an external
6
+ * `kill <launcher pid>`. Policy:
7
+ *
8
+ * - The FIRST signal asks pi to shut down cleanly. SIGINT is translated to
9
+ * SIGTERM because pi installs a graceful handler for SIGTERM (it kills its
10
+ * tracked children) but none for SIGINT — a raw SIGINT would drop pi on the
11
+ * default disposition with no cleanup.
12
+ * - Any SECOND signal hard-kills pi's whole process TREE. A bare SIGKILL to
13
+ * pi's pid would bypass its exit sweep (SIGKILL runs no handlers) and leave
14
+ * /go workers alive, so the launcher enumerates and kills the descendants
15
+ * itself: `ps` walk on POSIX, `taskkill /T /F` on Windows.
16
+ */
17
+ import { spawnSync } from "node:child_process";
18
+ import { constants as osConstants } from "node:os";
19
+ /** The launcher-terminating signals that are forwarded rather than obeyed. */
20
+ export const FORWARDED_SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
21
+ /**
22
+ * PURE policy for the FIRST signal: which signal the child receives when the
23
+ * launcher gets `received` (SIGINT is translated, the rest pass through).
24
+ * Escalation is not expressed here — a second signal goes through the tree
25
+ * kill, not a forwarded signal.
26
+ */
27
+ export function forwardedSignal(received) {
28
+ return received === "SIGINT" ? "SIGTERM" : received;
29
+ }
30
+ /**
31
+ * PURE: the launcher's own exit code for the child's (code, signal) exit tuple.
32
+ * A signal-terminated child maps to the conventional 128+n (bash parity:
33
+ * SIGTERM→143, SIGKILL→137, SIGINT→130), so a cancelled run never reads as
34
+ * success to scripts or CI.
35
+ */
36
+ export function exitCodeFor(code, signal) {
37
+ if (code != null)
38
+ return code;
39
+ if (signal)
40
+ return 128 + (osConstants.signals[signal] ?? 15);
41
+ return 0;
42
+ }
43
+ /**
44
+ * PURE: given `ps -A -o pid=,ppid=` output lines, collect every descendant of
45
+ * the given roots (children, grandchildren, ...), breadth-first. Mirrored in
46
+ * pi-extension-yagni's childRegistry (the packages are intentionally
47
+ * independent); keep the two in sync.
48
+ */
49
+ export function descendantsOf(roots, psLines) {
50
+ const childrenByParent = new Map();
51
+ for (const line of psLines) {
52
+ const m = line.trim().match(/^(\d+)\s+(\d+)$/);
53
+ if (!m)
54
+ continue;
55
+ const pid = Number(m[1]);
56
+ const ppid = Number(m[2]);
57
+ const list = childrenByParent.get(ppid) ?? [];
58
+ list.push(pid);
59
+ childrenByParent.set(ppid, list);
60
+ }
61
+ const found = [];
62
+ const queue = [...roots];
63
+ while (queue.length > 0) {
64
+ const next = queue.shift();
65
+ for (const child of childrenByParent.get(next) ?? []) {
66
+ found.push(child);
67
+ queue.push(child);
68
+ }
69
+ }
70
+ return found;
71
+ }
72
+ /**
73
+ * Synchronously SIGKILL a process AND its descendants (POSIX `ps` walk /
74
+ * Windows `taskkill /T /F`). Throw-proof; fail-soft to a direct kill when no
75
+ * process snapshot is readable.
76
+ */
77
+ export function killTreeSync(pid) {
78
+ if (process.platform === "win32") {
79
+ try {
80
+ spawnSync("taskkill", ["/pid", String(pid), "/T", "/F"], { stdio: "ignore" });
81
+ }
82
+ catch {
83
+ /* best effort */
84
+ }
85
+ return;
86
+ }
87
+ let descendants = [];
88
+ try {
89
+ const ps = spawnSync("ps", ["-A", "-o", "pid=,ppid="], { encoding: "utf8" });
90
+ if (ps.status === 0 && typeof ps.stdout === "string") {
91
+ descendants = descendantsOf([pid], ps.stdout.split("\n"));
92
+ }
93
+ }
94
+ catch {
95
+ /* no snapshot: fall through to the direct kill */
96
+ }
97
+ for (const target of [pid, ...descendants]) {
98
+ try {
99
+ process.kill(target, "SIGKILL");
100
+ }
101
+ catch {
102
+ /* already dead */
103
+ }
104
+ }
105
+ }
106
+ /**
107
+ * Subscribe the forwarding policy for every signal in {@link FORWARDED_SIGNALS}.
108
+ * `subscribe` and `killTree` default to the real process surfaces and are
109
+ * injectable so tests never install real handlers, raise real signals, or kill
110
+ * real processes. Returns the forward function itself (also for tests).
111
+ * pid guard: a child whose spawn failed has no pid, and `kill()` would resolve
112
+ * that to the whole process group.
113
+ */
114
+ export function installSignalForwarding(child, subscribe = (sig, handler) => process.on(sig, handler), killTree = killTreeSync) {
115
+ let received = 0;
116
+ const forward = (sig) => {
117
+ const prior = received;
118
+ received += 1;
119
+ if (!child.pid)
120
+ return;
121
+ if (prior > 0)
122
+ killTree(child.pid);
123
+ else
124
+ child.kill(forwardedSignal(sig));
125
+ };
126
+ for (const sig of FORWARDED_SIGNALS)
127
+ subscribe(sig, () => forward(sig));
128
+ return forward;
129
+ }
130
+ //# sourceMappingURL=signalForward.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * `yagni token` — print the active environment's API token to stdout.
3
+ *
4
+ * This is the credential feed for `yagni connect claude-code`: Claude Code's
5
+ * `apiKeyHelper` runs this command (re-running on 401 and on a TTL), so the
6
+ * contract is strict — stdout carries the TOKEN AND NOTHING ELSE (Claude Code
7
+ * v2.1.227+ rejects helpers that print banners), and every notice goes to
8
+ * stderr. Riding the same refresh-at-launch client as the launcher means a
9
+ * token that enters the 7-day rotation window is rotated and persisted here
10
+ * too, so a Claude Code session keeps working without the user ever running
11
+ * `yagni` itself.
12
+ */
13
+ import { maybeRefreshAtLaunch } from "./refresh.js";
14
+ import type { Credentials } from "./credentials.js";
15
+ import { type Profile } from "./profiles.js";
16
+ export interface TokenCommandDeps {
17
+ readProfile?: () => Promise<Profile>;
18
+ refresh?: typeof maybeRefreshAtLaunch;
19
+ persist?: (name: string, creds: Credentials) => Promise<void>;
20
+ now?: () => number;
21
+ stdout?: (text: string) => void;
22
+ stderr?: (text: string) => void;
23
+ }
24
+ export declare function tokenCommand(deps?: TokenCommandDeps): Promise<number>;
25
+ //# sourceMappingURL=token.d.ts.map