@yagni-app/code-staging 0.3.1-staging.1108.1 → 0.3.2-staging.1112.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.
@@ -612,6 +612,16 @@ function classifySegmentTokens(rawTokens, policy, opts) {
612
612
  }
613
613
  const { tokens: strippedTokens, stripped } = stripLeadingTokens(rawTokens);
614
614
  if (strippedTokens.length === 0) {
615
+ // env standalone: `env` or `env VAR=val` with no following command prints
616
+ // environment variables — a read-only operation. stripLeadingTokens removes
617
+ // `env` as a wrapper word, leaving empty tokens. Recognize this case instead
618
+ // of returning "empty command segment" (YAG-549).
619
+ if (!opts.forbiddenOnly && rawTokens.length > 0 && basenameToken(rawTokens[0]) === "env") {
620
+ const onlyEnvAndAssignments = rawTokens.every((t) => basenameToken(t) === "env" || ENV_ASSIGNMENT_RE.test(t));
621
+ if (onlyEnvAndAssignments) {
622
+ return { decision: "allow", justification: "print environment variables (read-only)" };
623
+ }
624
+ }
615
625
  return opts.forbiddenOnly
616
626
  ? { decision: "allow", justification: "no forbidden match" }
617
627
  : { decision: "prompt", justification: "empty command segment" };
@@ -894,6 +904,59 @@ export const DEFAULT_EXEC_POLICY = {
894
904
  { pattern: ["pnpm", "list"], decision: "allow", justification: "list installed packages" },
895
905
  { pattern: ["pnpm", "--version"], decision: "allow", justification: "check pnpm version" },
896
906
  { pattern: ["tsc", "--version"], decision: "allow", justification: "check typescript version" },
907
+ // --- allow: CLI tool reads (YAG-549, based on prod Guardian data) ---
908
+ // linear CLI — read subcommands; write subcommands (create/update/delete/start/pr/attach/comment) stay prompt
909
+ { pattern: ["linear", "issue", "comment", "list"], decision: "allow", justification: "list Linear issue comments (read-only)" },
910
+ {
911
+ pattern: ["linear", "issue"],
912
+ decision: "allow",
913
+ justification: "read Linear issue data",
914
+ unlessTokens: ["start", "create", "update", "delete", "pull-request", "pr", "attach", "comment"],
915
+ },
916
+ { pattern: ["linear", ["--help", "-h"]], decision: "allow", justification: "show Linear CLI help" },
917
+ { pattern: ["linear", ["--version", "-V"]], decision: "allow", justification: "show Linear CLI version" },
918
+ // gh api — REST GET (no params, no method override) and GraphQL queries (no mutation)
919
+ // gh api defaults to POST when -f/-F params are present, so params are disqualifying.
920
+ // GraphQL is always POST, but queries are reads; mutations/subscriptions are disqualifying.
921
+ {
922
+ pattern: ["gh", "api", "graphql"],
923
+ decision: "allow",
924
+ justification: "GraphQL query (read-only)",
925
+ unlessTokens: ["query=mutation*", "query=subscription*"],
926
+ },
927
+ {
928
+ pattern: ["gh", "api"],
929
+ decision: "allow",
930
+ justification: "GitHub API GET request (read-only)",
931
+ unlessTokens: ["--method", "-X", "-X*", "graphql", "POST", "PATCH", "DELETE", "PUT", "-f", "-F", "--raw-field", "--field"],
932
+ },
933
+ { pattern: ["gh", "release", ["list", "view"]], decision: "allow", justification: "read GitHub release data" },
934
+ { pattern: ["gh", "label", "list"], decision: "allow", justification: "list GitHub labels" },
935
+ { pattern: ["gh", "milestone", "list"], decision: "allow", justification: "list GitHub milestones" },
936
+ { pattern: ["gh", "auth", "status"], decision: "allow", justification: "show GitHub auth status" },
937
+ // git read-only subcommands
938
+ { pattern: ["git", "tag"], decision: "allow", justification: "list tags (read-only)" },
939
+ { pattern: ["git", "reflog"], decision: "allow", justification: "show reference log" },
940
+ { pattern: ["git", "ls-remote"], decision: "allow", justification: "list remote refs" },
941
+ { pattern: ["git", "cat-file"], decision: "allow", justification: "inspect git objects (read-only)" },
942
+ { pattern: ["git", "for-each-ref"], decision: "allow", justification: "enumerate refs (read-only)" },
943
+ { pattern: ["git", "rev-list"], decision: "allow", justification: "walk commit history (read-only)" },
944
+ { pattern: ["git", "show-ref"], decision: "allow", justification: "list all refs" },
945
+ { pattern: ["git", "name-rev"], decision: "allow", justification: "map commit to name (read-only)" },
946
+ { pattern: ["git", "merge-base"], decision: "allow", justification: "find common ancestor (read-only)" },
947
+ // package manager test/lint — routine dev-loop operations
948
+ { pattern: ["pnpm", "test"], decision: "allow", justification: "run tests (routine dev-loop operation)" },
949
+ { pattern: ["pnpm", "lint"], decision: "allow", justification: "run linter (routine dev-loop operation)" },
950
+ { pattern: ["npm", "test"], decision: "allow", justification: "run tests (routine dev-loop operation)" },
951
+ { pattern: ["npm", "run", "lint"], decision: "allow", justification: "run linter (routine dev-loop operation)" },
952
+ { pattern: ["npx", "tsc", "--noEmit"], decision: "allow", justification: "typecheck only (no file writes)" },
953
+ { pattern: ["npx", "tsx", "--test"], decision: "allow", justification: "run tests (routine dev-loop operation)" },
954
+ { pattern: ["npx", "vitest"], decision: "allow", justification: "run vitest tests (routine dev-loop operation)" },
955
+ { pattern: ["npx", "vitest", "run"], decision: "allow", justification: "run vitest tests (routine dev-loop operation)" },
956
+ { pattern: ["npx", "jest"], decision: "allow", justification: "run jest tests (routine dev-loop operation)" },
957
+ // misc read-only commands
958
+ { pattern: ["printenv"], decision: "allow", justification: "print environment variables (read-only)" },
959
+ { pattern: ["npm", ["view", "info"]], decision: "allow", justification: "read package metadata from registry" },
897
960
  // --- prompt: potentially destructive but context-dependent ---
898
961
  { pattern: ["rm"], decision: "prompt", justification: "file deletion — review the target" },
899
962
  { pattern: ["git", "commit"], decision: "prompt", justification: "creates a commit — confirm intent" },
@@ -184,7 +184,7 @@ export interface RegisterPermissionDeps {
184
184
  export declare const MODE_CONTEXT_TYPE = "yagni-mode-context";
185
185
  /** Legacy alias — the original plan-mode tag, kept for backward compat. */
186
186
  export declare const PLAN_CONTEXT_TYPE = "yagni-mode-context";
187
- export declare const PLAN_CONTEXT_MESSAGE = "[PLAN MODE ACTIVE]\nYou are in plan mode: explore and design, change nothing.\n- write, edit, and bash are held by the permission gate; do not attempt them.\n- Read, search, and ask_yagni freely to ground the plan in how this company works.\n- Produce a concrete numbered plan of the steps you would take, with the files involved.\n- End by asking the user to review the plan; they run /mode auto (or /mode review) to execute it.\n- Once executing, track the plan's steps with todo_write.";
187
+ export declare const PLAN_CONTEXT_MESSAGE = "[PLAN MODE ACTIVE]\nYou are in plan mode: explore and design, change nothing.\n- Read-only bash commands (ls, grep, git status, gh pr view, etc.) run freely to help you explore.\n- Ambiguous bash commands are reviewed by the Guardian; if non-mutating they run, if potentially mutating you will be asked.\n- write, edit, file_ticket, and update_ticket_status are held by the permission gate; do not attempt them.\n- Read, search, and ask_yagni freely to ground the plan in how this company works.\n- Produce a concrete numbered plan of the steps you would take, with the files involved.\n- End by asking the user to review the plan; they run /mode auto (or /mode review) to execute it.\n- Once executing, track the plan's steps with todo_write.";
188
188
  /** Build the mode-awareness context message for the current permission mode. */
189
189
  export declare function buildModeContextMessage(mode: PermissionMode): string;
190
190
  /**
@@ -56,6 +56,42 @@ export const DEFAULT_PERMISSION_POLICY = {
56
56
  */
57
57
  export function decideGate(toolName, params, mode, policy) {
58
58
  if (mode === "plan") {
59
+ // Non-bash tools in planBlockTools are held outright — they are
60
+ // inherently mutating (write, edit, file_ticket, update_ticket_status).
61
+ // Bash is the exploration tool: run it through the exec policy so
62
+ // read-only commands (git status, ls, grep, gh pr view) work, and
63
+ // prompt-band commands are routed to the Guardian. The gate handler
64
+ // ensures Guardian-unavailable/capped/disabled states fail closed.
65
+ if (toolName === "bash") {
66
+ const command = typeof params.command === "string" ? params.command.trim() : "";
67
+ if (command) {
68
+ try {
69
+ const execPolicy = policy.execPolicy ?? DEFAULT_EXEC_POLICY;
70
+ const classification = classifyCommand(command, execPolicy);
71
+ if (classification.decision === "allow")
72
+ return { block: false };
73
+ if (classification.decision === "forbidden") {
74
+ return {
75
+ block: true,
76
+ reason: `${classification.justification}. Do not attempt the same outcome via a workaround or indirect execution — use a materially safer alternative, or ask the user.`,
77
+ };
78
+ }
79
+ // prompt — Guardian reviews. The gate handler runs the Guardian
80
+ // and handles allow/ask/deny. Grants and cache are skipped in
81
+ // plan mode (they can cover writes). Guardian unavailable/capped/
82
+ // disabled → block (fail closed).
83
+ return { block: false, classify: "prompt", classifyJustification: classification.justification };
84
+ }
85
+ catch {
86
+ // classifyCommand threw — fail closed in plan mode.
87
+ return {
88
+ block: true,
89
+ reason: `plan mode: could not classify this bash command and it is held. Switch to /mode auto to apply changes.`,
90
+ };
91
+ }
92
+ }
93
+ return { block: false };
94
+ }
59
95
  if (policy.planBlockTools.includes(toolName)) {
60
96
  return {
61
97
  block: true,
@@ -122,7 +158,9 @@ const AUTO_MARKER = "[AUTO MODE]";
122
158
  const REVIEW_MARKER = "[REVIEW MODE]";
123
159
  export const PLAN_CONTEXT_MESSAGE = `${PLAN_MARKER}
124
160
  You are in plan mode: explore and design, change nothing.
125
- - write, edit, and bash are held by the permission gate; do not attempt them.
161
+ - Read-only bash commands (ls, grep, git status, gh pr view, etc.) run freely to help you explore.
162
+ - Ambiguous bash commands are reviewed by the Guardian; if non-mutating they run, if potentially mutating you will be asked.
163
+ - write, edit, file_ticket, and update_ticket_status are held by the permission gate; do not attempt them.
126
164
  - Read, search, and ask_yagni freely to ground the plan in how this company works.
127
165
  - Produce a concrete numbered plan of the steps you would take, with the files involved.
128
166
  - End by asking the user to review the plan; they run /mode auto (or /mode review) to execute it.
@@ -414,7 +452,9 @@ export function registerPermissionGate(pi, deps = {}) {
414
452
  }
415
453
  }
416
454
  // 2. Session exact-command approval cache (ticket 4.5).
417
- if (command && approvedCommands.has(cacheKey(cwd, command))) {
455
+ // Skipped in plan mode: a cached approval can cover a write command,
456
+ // and plan mode's contract is no mutations without Guardian review.
457
+ if (modeAtEntry !== "plan" && command && approvedCommands.has(cacheKey(cwd, command))) {
418
458
  emitGateEvent({ ...eventBase, outcome: "cached_allow", consulted: false });
419
459
  return {};
420
460
  }
@@ -423,13 +463,13 @@ export function registerPermissionGate(pi, deps = {}) {
423
463
  if (guardianAvailable && guardianState.read().reviews >= limits.maxReviews) {
424
464
  // Sliding-window consult cap (capacity recovers as old reviews age
425
465
  // out — a long-lived session is never bricked). Review mode falls
426
- // through to its ordinary confirm (no LLM cost); auto blocks.
427
- if (modeAtEntry === "auto") {
466
+ // through to its ordinary confirm (no LLM cost); auto and plan block.
467
+ if (modeAtEntry === "auto" || modeAtEntry === "plan") {
428
468
  if (ctx?.hasUI)
429
469
  ctx.ui.notify(`Guardian review cap reached (${limits.maxReviews} in the last hour).`, "warning");
430
470
  return { block: true, reason: `Guardian review cap reached (${limits.maxReviews} in the last hour). Capacity recovers as older reviews age out; switch to /mode review to approve manually, or retry this step later.` };
431
471
  }
432
- // fall through to decision.confirm below
472
+ // review mode: fall through to decision.confirm below
433
473
  }
434
474
  else if (guardianAvailable) {
435
475
  // Circuit breaker (pre-consult). With a UI, escalate to ONE ask per
@@ -675,6 +715,14 @@ export function registerPermissionGate(pi, deps = {}) {
675
715
  // approval cache were already consulted above.
676
716
  return {};
677
717
  }
718
+ else if (modeAtEntry === "plan") {
719
+ // Guardian disabled or not wired in plan mode: fail closed. Without
720
+ // the Guardian to verify the command is non-mutating, the plan-mode
721
+ // contract (no changes) cannot be upheld. The user can switch to
722
+ // /mode auto or /mode review to proceed.
723
+ emitGateEvent({ ...eventBase, outcome: "breaker_blocked", consulted: false });
724
+ return { block: true, reason: "Guardian unavailable in plan mode. Switch to /mode auto to run commands, or /mode review to approve manually." };
725
+ }
678
726
  // review mode with Guardian disabled/capped: fall through to confirm.
679
727
  }
680
728
  if (decision.confirm) {
@@ -107,7 +107,7 @@ Risk taxonomy:
107
107
  Outcome rules:
108
108
  - "deny" is reserved for actions you are VERY CONFIDENT are very dangerous: irreversible destruction, exfiltration of sensitive data, credential probing, production-impacting security weakening. If you are not sure it is that bad, do not deny.
109
109
  - "allow" when you are confident the action is safe: read-only, routine dev-loop, or clearly scoped and reversible.
110
- - "ask" for everything in between — the action might be fine but a human should decide. This is the correct outcome whenever your confidence is middling; prefer ask over deny for anything short of the very-dangerous bar, and prefer allow over ask for routine work (do not hedge routine commands into ask).
110
+ - "ask" for actions where a specific, concrete risk makes you unsure — the action has a plausible path to harm that you cannot rule out by reading the command. Do not ask just because a command "might" do something; ask when you can name the specific thing you are worried about. If you cannot articulate a concrete risk, allow. Prefer allow over ask: routine dev-loop operations, local file writes within a project, and standard git operations (add, commit, fetch) are safe the agent is already operating in the user's repository with their consent.
111
111
 
112
112
  Rationale rules:
113
113
  - For "ask", the rationale MUST be a specific question addressed to the user, naming the concrete effect that made you unsure — e.g. "This pushes 3 commits to the shared main branch — do you want to publish them now?". You may be told why the static policy routed the command to you; your rationale must ADD information beyond that policy text, not restate it.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yagni-app/code-staging",
3
- "version": "0.3.1-staging.1108.1",
3
+ "version": "0.3.2-staging.1112.1",
4
4
  "description": "YAGNI Code: a terminal coding agent that already knows your company. One YAGNI login routes the model and grounds the agent in your team's context.",
5
5
  "license": "SEE LICENSE IN LICENSE.md",
6
6
  "author": "YAGNI, Inc. <jack@yagni.app> (https://yagni.app)",
@@ -39,5 +39,5 @@
39
39
  "smol-toml": "^1.8.0",
40
40
  "typebox": "^1.3.11"
41
41
  },
42
- "yagniSourceSha": "4244ba837c0cfc0ad410d02e34df6ad82e32a848"
42
+ "yagniSourceSha": "792a9033a5199d4129ba1a53605b23881956e4ce"
43
43
  }