@yagni-app/code 0.2.0 → 0.3.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 (77) hide show
  1. package/dist/cli.d.ts +30 -0
  2. package/dist/cli.js +135 -3
  3. package/dist/doctor.d.ts +1 -1
  4. package/dist/doctor.js +1 -1
  5. package/dist/extension/advisor.d.ts +4 -4
  6. package/dist/extension/advisor.js +6 -7
  7. package/dist/extension/approvedPrefixes.d.ts +92 -0
  8. package/dist/extension/approvedPrefixes.js +252 -0
  9. package/dist/extension/askAdvisorTool.d.ts +2 -2
  10. package/dist/extension/askAdvisorTool.js +5 -5
  11. package/dist/extension/askYagniTool.js +49 -0
  12. package/dist/extension/branding.d.ts +24 -3
  13. package/dist/extension/branding.js +71 -10
  14. package/dist/extension/chipEditor.d.ts +30 -9
  15. package/dist/extension/chipEditor.js +173 -59
  16. package/dist/extension/claudeRules.d.ts +0 -2
  17. package/dist/extension/claudeRules.js +0 -8
  18. package/dist/extension/cmux/dispatcher.d.ts +25 -0
  19. package/dist/extension/cmux/dispatcher.js +266 -0
  20. package/dist/extension/cmux/hooks.d.ts +12 -0
  21. package/dist/extension/cmux/hooks.js +192 -0
  22. package/dist/extension/cmux/index.d.ts +3 -0
  23. package/dist/extension/cmux/index.js +155 -0
  24. package/dist/extension/cmux/naming.d.ts +5 -0
  25. package/dist/extension/cmux/naming.js +23 -0
  26. package/dist/extension/cmux/state.d.ts +33 -0
  27. package/dist/extension/cmux/state.js +142 -0
  28. package/dist/extension/config.d.ts +32 -1
  29. package/dist/extension/config.js +36 -4
  30. package/dist/extension/costHud.d.ts +16 -22
  31. package/dist/extension/costHud.js +8 -47
  32. package/dist/extension/crashReport.js +1 -3
  33. package/dist/extension/execPolicy.d.ts +119 -0
  34. package/dist/extension/execPolicy.js +805 -0
  35. package/dist/extension/footer.d.ts +111 -0
  36. package/dist/extension/footer.js +294 -0
  37. package/dist/extension/guardian.d.ts +129 -0
  38. package/dist/extension/guardian.js +213 -0
  39. package/dist/extension/index.d.ts +15 -4
  40. package/dist/extension/index.js +250 -24
  41. package/dist/extension/permission.d.ts +123 -10
  42. package/dist/extension/permission.js +586 -40
  43. package/dist/extension/pipeline/childRegistry.d.ts +41 -0
  44. package/dist/extension/pipeline/childRegistry.js +118 -0
  45. package/dist/extension/pipeline/finish.js +5 -1
  46. package/dist/extension/pipeline/goCommand.d.ts +1 -1
  47. package/dist/extension/pipeline/goCommand.js +35 -6
  48. package/dist/extension/pipeline/goStatusCommands.d.ts +10 -0
  49. package/dist/extension/pipeline/goStatusCommands.js +61 -1
  50. package/dist/extension/pipeline/personas.js +25 -0
  51. package/dist/extension/pipeline/runRegistry.d.ts +14 -0
  52. package/dist/extension/pipeline/runRegistry.js +35 -0
  53. package/dist/extension/pipeline/runner.js +4 -0
  54. package/dist/extension/pipeline/verify.d.ts +4 -0
  55. package/dist/extension/pipeline/verify.js +48 -26
  56. package/dist/extension/redact.d.ts +20 -0
  57. package/dist/extension/redact.js +64 -0
  58. package/dist/extension/rerouteNotice.d.ts +3 -12
  59. package/dist/extension/rerouteNotice.js +36 -15
  60. package/dist/extension/subagentRender.d.ts +129 -0
  61. package/dist/extension/subagentRender.js +441 -0
  62. package/dist/extension/subagents.d.ts +4 -7
  63. package/dist/extension/subagents.js +103 -33
  64. package/dist/extension/ticketTools.d.ts +37 -0
  65. package/dist/extension/ticketTools.js +117 -0
  66. package/dist/extension/tokenProvider.js +46 -5
  67. package/dist/launch.d.ts +7 -0
  68. package/dist/launch.js +24 -12
  69. package/dist/padding.d.ts +22 -0
  70. package/dist/padding.js +25 -0
  71. package/dist/promptEnrichment.d.ts +40 -0
  72. package/dist/promptEnrichment.js +85 -0
  73. package/dist/signalForward.d.ts +60 -0
  74. package/dist/signalForward.js +130 -0
  75. package/package.json +5 -5
  76. package/dist/extension/boostCommand.d.ts +0 -144
  77. package/dist/extension/boostCommand.js +0 -263
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Heuristic secret redaction for Guardian storage events (YAG-510).
3
+ *
4
+ * Applied client-side, BEFORE anything leaves the machine, to both the
5
+ * command and the Guardian rationale (which routinely quotes the command) —
6
+ * and only on the raw storage tier; the base tier never transmits either.
7
+ *
8
+ * Honest scope: this catches the obvious, well-known secret shapes. A secret
9
+ * in a novel shape gets through — which is why raw-tier storage is an
10
+ * explicit-consent, per-workspace opt-in and never a default.
11
+ *
12
+ * Pure, no external deps (bundling constraint — see execPolicy.ts header).
13
+ */
14
+ const REDACTED = "[REDACTED]";
15
+ /** Exactly 40 hex chars = a git SHA; keep those readable for analysis. */
16
+ function isGitSha(token) {
17
+ return /^[0-9a-f]{40}$/i.test(token);
18
+ }
19
+ const RULES = [
20
+ // Known token shapes (provider-prefixed credentials).
21
+ { re: /\bAKIA[0-9A-Z]{16}\b/g },
22
+ { re: /\bgh[pousr]_[A-Za-z0-9_]{20,}\b/g },
23
+ { re: /\bgithub_pat_[A-Za-z0-9_]{20,}\b/g },
24
+ { re: /\bsk-[A-Za-z0-9_-]{16,}\b/g },
25
+ { re: /\bxox[bpsaro]-[A-Za-z0-9-]{10,}\b/g },
26
+ { re: /\beyJ[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{4,}(?:\.[A-Za-z0-9_-]+)?\b/g }, // JWT
27
+ { re: /\bglsa_[A-Za-z0-9_]{20,}\b/g },
28
+ { re: /\b(?:fly|glpat|npm)_[A-Za-z0-9_-]{16,}\b/g },
29
+ // Authorization headers: keep the scheme, redact the credential.
30
+ { re: /\b(Authorization:\s*(?:Bearer|Basic|Token)\s+)[^\s"']+/gi, keepGroup1: true },
31
+ // key=value / --key value / --key=value with a secret-shaped key.
32
+ {
33
+ re: /((?:--?[A-Za-z0-9_-]*)?(?:password|passwd|secret|token|api[_-]?key|auth)[A-Za-z0-9_-]*\s*[=\s]\s*)[^\s"']+/gi,
34
+ keepGroup1: true,
35
+ },
36
+ // user:pass@ in URLs — redact the password only.
37
+ { re: /(\/\/[^\s/:@"']+:)[^\s@"']+(?=@)/g, keepGroup1: true },
38
+ ];
39
+ /** High-entropy runs: 32+ base64/hex chars — except exact git SHAs. */
40
+ const LONG_RUN_RE = /[A-Za-z0-9+/=_-]{32,}/g;
41
+ /**
42
+ * Redact known secret shapes from a command or rationale string. Structure
43
+ * is preserved (only matched values become [REDACTED]) so the redacted text
44
+ * stays analyzable.
45
+ */
46
+ export function redactCommand(text) {
47
+ let out = text;
48
+ for (const rule of RULES) {
49
+ out = out.replace(rule.re, (match, g1) => rule.keepGroup1 && typeof g1 === "string" ? `${g1}${REDACTED}` : REDACTED);
50
+ }
51
+ out = out.replace(LONG_RUN_RE, (match) => {
52
+ if (isGitSha(match))
53
+ return match;
54
+ if (match === REDACTED.slice(1, -1))
55
+ return match;
56
+ // Plain long words (paths, flags already handled above) that are all
57
+ // lowercase letters are more likely English than entropy; keep them.
58
+ if (/^[a-z]+$/.test(match) || /^[A-Z]+$/.test(match))
59
+ return match;
60
+ return REDACTED;
61
+ });
62
+ return out;
63
+ }
64
+ //# sourceMappingURL=redact.js.map
@@ -4,7 +4,7 @@
4
4
  * The backend sets `x-yagni-model-reroute: <requested>-><effective>:vision` on
5
5
  * every response it silently upgrades for image content (yagniCodeV1.ts). pi's
6
6
  * `after_provider_response` event is the only client-side seam that sees raw
7
- * response headers (verified against pi 0.83.0's AfterProviderResponseEvent:
7
+ * response headers (verified against pi 0.84.1's AfterProviderResponseEvent:
8
8
  * `{ type: "after_provider_response", status: number, headers: Record<string,
9
9
  * string> }` in dist/core/extensions/types.d.ts). Its docs (extensions.md,
10
10
  * "after_provider_response") describe `event.headers` as "normalized response
@@ -22,19 +22,10 @@ export interface Reroute {
22
22
  export type HeaderMap = Record<string, string | undefined>;
23
23
  /**
24
24
  * Parse the `x-yagni-model-reroute` header. Returns null when the header is
25
- * absent, does not match `<from>-><to>:<reason>`, or the reason is not
26
- * "vision" (the notice copy says "Your image", which only a vision reroute
27
- * can honestly claim).
25
+ * absent, does not match `<from>-><to>:<reason>`, or the reason is not a
26
+ * known reason (vision or policy; see KNOWN_REASONS).
28
27
  */
29
28
  export declare function parseReroute(headers: HeaderMap): Reroute | null;
30
- /**
31
- * Dedupe wrapper around {@link parseReroute}: `observe` returns the notice
32
- * message at most once per distinct from->to pair for the life of the
33
- * instance (i.e. per session), and null otherwise (absent, malformed, or
34
- * already-seen). Returning the message rather than taking a notify callback
35
- * keeps the caller in charge of the ctx it has on hand at call time, instead
36
- * of this class holding a stale reference across calls.
37
- */
38
29
  export declare class RerouteNotifier {
39
30
  private readonly seen;
40
31
  observe(headers: HeaderMap): string | null;
@@ -4,7 +4,7 @@
4
4
  * The backend sets `x-yagni-model-reroute: <requested>-><effective>:vision` on
5
5
  * every response it silently upgrades for image content (yagniCodeV1.ts). pi's
6
6
  * `after_provider_response` event is the only client-side seam that sees raw
7
- * response headers (verified against pi 0.83.0's AfterProviderResponseEvent:
7
+ * response headers (verified against pi 0.84.1's AfterProviderResponseEvent:
8
8
  * `{ type: "after_provider_response", status: number, headers: Record<string,
9
9
  * string> }` in dist/core/extensions/types.d.ts). Its docs (extensions.md,
10
10
  * "after_provider_response") describe `event.headers` as "normalized response
@@ -14,11 +14,16 @@
14
14
  */
15
15
  const REROUTE_HEADER = "x-yagni-model-reroute";
16
16
  const REROUTE_PATTERN = /^(.+?)->(.+?):(\w+)$/;
17
+ /** Reroute reasons the client understands. `policy` (caller→tier routing,
18
+ * 2026-08-11 spec) is parsed but deliberately produces NO user notice: the
19
+ * spec keeps per-request routing quiet — /cost and the savings receipts are
20
+ * the user-facing surface. `vision` keeps its one-time notice ("Your image…"
21
+ * is copy only a vision reroute can honestly claim). */
22
+ const KNOWN_REASONS = new Set(["vision", "policy"]);
17
23
  /**
18
24
  * Parse the `x-yagni-model-reroute` header. Returns null when the header is
19
- * absent, does not match `<from>-><to>:<reason>`, or the reason is not
20
- * "vision" (the notice copy says "Your image", which only a vision reroute
21
- * can honestly claim).
25
+ * absent, does not match `<from>-><to>:<reason>`, or the reason is not a
26
+ * known reason (vision or policy; see KNOWN_REASONS).
22
27
  */
23
28
  export function parseReroute(headers) {
24
29
  const value = headers[REROUTE_HEADER];
@@ -28,25 +33,36 @@ export function parseReroute(headers) {
28
33
  if (!match)
29
34
  return null;
30
35
  const [, from, to, reason] = match;
31
- if (reason !== "vision")
36
+ if (!KNOWN_REASONS.has(reason))
32
37
  return null;
33
38
  return { from, to, reason };
34
39
  }
35
40
  /**
36
41
  * Dedupe wrapper around {@link parseReroute}: `observe` returns the notice
37
- * message at most once per distinct from->to pair for the life of the
38
- * instance (i.e. per session), and null otherwise (absent, malformed, or
39
- * already-seen). Returning the message rather than taking a notify callback
40
- * keeps the caller in charge of the ctx it has on hand at call time, instead
41
- * of this class holding a stale reference across calls.
42
+ * message at most once per distinct from->to->reason triple for the life of
43
+ * the instance (i.e. per session), and null otherwise (absent, malformed,
44
+ * already-seen, or a non-vision reason `policy` reroutes are parsed but
45
+ * deliberately silent; see KNOWN_REASONS). Returning the message rather than
46
+ * taking a notify callback keeps the caller in charge of the ctx it has on
47
+ * hand at call time, instead of this class holding a stale reference across
48
+ * calls.
42
49
  */
50
+ /**
51
+ * The concrete tier ladder cheapest-first, mirroring the proxy's
52
+ * VISION_REROUTE_LADDER (yagniCodeV1.ts). Used only to tell an upgrade
53
+ * reroute from a downgrade so the "Billed as" clause names the tier the
54
+ * proxy actually bills.
55
+ */
56
+ const TIER_LADDER = ["efficient", "standard", "advanced", "peak"];
43
57
  export class RerouteNotifier {
44
58
  seen = new Set();
45
59
  observe(headers) {
46
60
  const reroute = parseReroute(headers);
47
61
  if (!reroute)
48
62
  return null;
49
- const key = `${reroute.from}->${reroute.to}`;
63
+ if (reroute.reason !== "vision")
64
+ return null;
65
+ const key = `${reroute.from}->${reroute.to}:${reroute.reason}`;
50
66
  if (this.seen.has(key))
51
67
  return null;
52
68
  this.seen.add(key);
@@ -54,13 +70,18 @@ export class RerouteNotifier {
54
70
  // assertBillableTier throws if it ever reaches pricing) — for a balanced
55
71
  // reroute the bill IS the resolved tier (`reroute.to`; yagniCodeV1.ts's
56
72
  // `billedTier` takes its `effectiveModel` arm here), so a "Billed as
57
- // balanced" clause would name a non-price. Only a CONCRETE from-tier
58
- // still bills at its own pre-reroute rate (Task 3's invariant: a re-route
59
- // never moves anyone's price), so only then is a distinct "Billed as X"
60
- // line honest.
73
+ // balanced" clause would name a non-price.
61
74
  if (reroute.from === "balanced") {
62
75
  return `Your image was handled on the ${reroute.to} tier.`;
63
76
  }
77
+ // Concrete tiers bill the CHEAPER of requested and served (yagniCodeV1.ts's
78
+ // billedTier): an UPGRADE still bills the pre-reroute tier, so a distinct
79
+ // "Billed as X" line is honest; a DOWNGRADE bills the served tier, where
80
+ // that clause would name a price the proxy did not charge.
81
+ const downgraded = TIER_LADDER.indexOf(reroute.to) < TIER_LADDER.indexOf(reroute.from);
82
+ if (downgraded) {
83
+ return `Your image was handled on the ${reroute.to} tier. Billed as ${reroute.to}.`;
84
+ }
64
85
  return `Your image was handled on the ${reroute.to} tier. Billed as ${reroute.from}.`;
65
86
  }
66
87
  }
@@ -0,0 +1,129 @@
1
+ /**
2
+ * Live progress model + TUI renderers for the `subagent` tool.
3
+ *
4
+ * The model half is PURE (mirrors `pipeline/activity.ts`): `applyChildEvent`
5
+ * folds one NDJSON event from a child into a bounded per-task progress record,
6
+ * and `finalizeTask` stamps the outcome from the runner's `StageResult`. The
7
+ * tool carries the folded records in its `details`, so every partial update the
8
+ * TUI sees is a complete picture of all tasks.
9
+ *
10
+ * The renderer half implements pi's per-tool rendering seam (`renderCall` /
11
+ * `renderResult`). Collapsed-while-running is the two-line pattern: a stable
12
+ * `agent — task` title over a churning `↳ current tool` line. Completion is a
13
+ * one-line receipt (`✓ agent · N tool uses · Xk tokens · Ys`); expanded shows
14
+ * the curated action log and the full report as markdown. String assembly is
15
+ * kept in pure helpers over a minimal {@link RenderTheme} so tests run against
16
+ * plain text — renderer exceptions are swallowed by pi (silently degrading to
17
+ * the bare title bar), so everything here must stay boringly total.
18
+ */
19
+ import { type Component } from "@earendil-works/pi-tui";
20
+ import type { JsonEvent, StageResult, StageUsage } from "./pipeline/types.js";
21
+ /** The minimal slice of pi's `Theme` the renderers style with (same shape as FeedTheme). */
22
+ export interface RenderTheme {
23
+ bold(text: string): string;
24
+ fg(color: string, text: string): string;
25
+ }
26
+ /** One curated line of a child's activity (tool action or narration headline). */
27
+ export interface SubagentActionEntry {
28
+ kind: "action" | "narration";
29
+ text: string;
30
+ state: "running" | "done" | "error";
31
+ /** Resolves a running tool start against its end event. */
32
+ toolCallId?: string;
33
+ }
34
+ /** Live/final progress of one subagent task; rides the tool's `details`. */
35
+ export interface SubagentTaskProgress {
36
+ agent: string;
37
+ task: string;
38
+ status: "running" | "done" | "error";
39
+ /** -1 while the child is still running (mirrors the pi subagent example). */
40
+ exitCode: number;
41
+ startedAt: number;
42
+ endedAt?: number;
43
+ toolCalls: number;
44
+ toolErrors: number;
45
+ usage: StageUsage;
46
+ /** Bounded curated log; oldest entries are dropped past ACTION_LOG_MAX. */
47
+ actions: SubagentActionEntry[];
48
+ droppedActions: number;
49
+ /** The child's final report, present once the task resolved. */
50
+ report?: string;
51
+ stopReason?: string;
52
+ errorMessage?: string;
53
+ }
54
+ export interface SubagentDetails {
55
+ tasks: SubagentTaskProgress[];
56
+ }
57
+ /** Bound on the retained action log so a chatty child cannot grow details unbounded. */
58
+ export declare const ACTION_LOG_MAX = 120;
59
+ export declare function newTaskProgress(agent: string, task: string, startedAt: number): SubagentTaskProgress;
60
+ /**
61
+ * Fold one child NDJSON event into the task's progress. Returns true when the
62
+ * record changed (the tool emits an update), false for events we drop.
63
+ */
64
+ export declare function applyChildEvent(p: SubagentTaskProgress, ev: JsonEvent): boolean;
65
+ /** Stamp the runner's outcome onto the progress record. */
66
+ export declare function finalizeTask(p: SubagentTaskProgress, result: StageResult, endedAt: number): void;
67
+ /** 532 → "532", 41_234 → "41.2k", 1_240_000 → "1.2M". */
68
+ export declare function formatTokens(n: number): string;
69
+ /** 42_000 → "42s", 81_000 → "1m 21s", 3_720_000 → "1h 2m". */
70
+ export declare function formatDuration(ms: number): string;
71
+ /**
72
+ * The two-line live status for one running task: a stable `agent — task` title
73
+ * over the churning current-action line with elapsed time and live tokens.
74
+ */
75
+ export declare function runningLines(p: SubagentTaskProgress, theme: RenderTheme, now: number, frame: string): string[];
76
+ /** One-line completion receipt: `✓ agent · N tool uses · Xk tokens · Ys · $c`. */
77
+ export declare function receiptLine(p: SubagentTaskProgress, theme: RenderTheme): string;
78
+ /**
79
+ * Plain-text (no theme) summary for the partial result's `content`, so headless
80
+ * consumers and pi's fallback renderer still see live progress.
81
+ */
82
+ export declare function progressSummaryText(tasks: SubagentTaskProgress[], now: number): string;
83
+ /** The harness "Working…" replacement while subagents run. */
84
+ export declare function formatWorkingMessage(tasks: SubagentTaskProgress[], now: number): string;
85
+ /** The subagent tool's argument shape, partial while the model streams it. */
86
+ interface SubagentCallArgs {
87
+ task?: string;
88
+ agent?: string;
89
+ tasks?: Array<{
90
+ task?: string;
91
+ agent?: string;
92
+ }>;
93
+ }
94
+ /** Renderer-row state shared across renders of one tool call (context.state). */
95
+ interface LiveRenderState {
96
+ timer?: ReturnType<typeof setInterval>;
97
+ }
98
+ interface RenderContextSlice {
99
+ state?: LiveRenderState;
100
+ invalidate: () => void;
101
+ }
102
+ /** Title painted the moment the call streams in (before any execution output). */
103
+ export declare function renderSubagentCall(args: SubagentCallArgs | undefined, theme: RenderTheme, _context: unknown): Component;
104
+ /**
105
+ * A prose body as markdown when the TUI's markdown theme is available.
106
+ * `getMarkdownTheme()` hands back a lazy proxy that only throws when a style is
107
+ * first USED, so the fallback must wrap `render`, not construction — otherwise
108
+ * an uninitialized theme would blow up mid-paint and pi would silently degrade
109
+ * the whole row to the bare title bar.
110
+ */
111
+ export declare function markdownOrPlain(body: string, theme: RenderTheme): Component;
112
+ /**
113
+ * Result renderer: live two-line status per task while partial; receipts plus
114
+ * report preview when collapsed; action log plus full markdown report when
115
+ * expanded. Drives its own refresh while running via an unref'd interval on
116
+ * `context.state` (pi has no unmount hook — the final render clears it).
117
+ */
118
+ export declare function renderSubagentResult(result: {
119
+ content: Array<{
120
+ type: string;
121
+ text?: string;
122
+ }>;
123
+ details?: unknown;
124
+ }, options: {
125
+ expanded: boolean;
126
+ isPartial: boolean;
127
+ }, theme: RenderTheme, context: RenderContextSlice): Component;
128
+ export {};
129
+ //# sourceMappingURL=subagentRender.d.ts.map