@codyswann/lisa 2.349.1 → 2.351.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 (192) hide show
  1. package/dist/cli/doctor-learnings-ledger.d.ts +23 -0
  2. package/dist/cli/doctor-learnings-ledger.d.ts.map +1 -0
  3. package/dist/cli/doctor-learnings-ledger.js +67 -0
  4. package/dist/cli/doctor-learnings-ledger.js.map +1 -0
  5. package/dist/cli/doctor.d.ts.map +1 -1
  6. package/dist/cli/doctor.js +6 -0
  7. package/dist/cli/doctor.js.map +1 -1
  8. package/dist/core/learnings-file-safety.d.ts +12 -1
  9. package/dist/core/learnings-file-safety.d.ts.map +1 -1
  10. package/dist/core/learnings-file-safety.js +20 -1
  11. package/dist/core/learnings-file-safety.js.map +1 -1
  12. package/dist/core/learnings-location.d.ts +40 -0
  13. package/dist/core/learnings-location.d.ts.map +1 -0
  14. package/dist/core/learnings-location.js +89 -0
  15. package/dist/core/learnings-location.js.map +1 -0
  16. package/dist/core/learnings-stray-ledger.d.ts +24 -0
  17. package/dist/core/learnings-stray-ledger.d.ts.map +1 -0
  18. package/dist/core/learnings-stray-ledger.js +155 -0
  19. package/dist/core/learnings-stray-ledger.js.map +1 -0
  20. package/dist/core/project-config.d.ts +1 -13
  21. package/dist/core/project-config.d.ts.map +1 -1
  22. package/dist/core/project-config.js +5 -53
  23. package/dist/core/project-config.js.map +1 -1
  24. package/dist/core/upstream-evidence-manifest.d.ts.map +1 -1
  25. package/dist/core/upstream-evidence-manifest.js +46 -18
  26. package/dist/core/upstream-evidence-manifest.js.map +1 -1
  27. package/package.json +1 -1
  28. package/plugins/lisa/.claude-plugin/plugin.json +1 -1
  29. package/plugins/lisa/.codex-plugin/plugin.json +1 -1
  30. package/plugins/lisa/.codex-plugin/skills/lisa-github-read-issue/SKILL.md +1 -0
  31. package/plugins/lisa/.codex-plugin/skills/lisa-github-validate-issue/SKILL.md +22 -0
  32. package/plugins/lisa/.codex-plugin/skills/lisa-github-write-issue/SKILL.md +15 -0
  33. package/plugins/lisa/.codex-plugin/skills/lisa-implement/SKILL.md +6 -0
  34. package/plugins/lisa/.codex-plugin/skills/lisa-jira-validate-ticket/SKILL.md +22 -0
  35. package/plugins/lisa/.codex-plugin/skills/lisa-jira-write-ticket/SKILL.md +15 -0
  36. package/plugins/lisa/.codex-plugin/skills/lisa-linear-access/SKILL.md +25 -3
  37. package/plugins/lisa/.codex-plugin/skills/lisa-linear-validate-issue/SKILL.md +22 -0
  38. package/plugins/lisa/.codex-plugin/skills/lisa-linear-write-issue/SKILL.md +15 -0
  39. package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/SKILL.md +20 -2
  40. package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/doctor-secrets.mjs +13 -9
  41. package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/note-format.mjs +179 -0
  42. package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/resolve-secret.mjs +32 -6
  43. package/plugins/lisa/.codex-plugin/skills/lisa-secrets-access/scripts/tools-from-notes.mjs +6 -2
  44. package/plugins/lisa/.codex-plugin/skills/lisa-setup-atlassian/SKILL.md +17 -0
  45. package/plugins/lisa/.codex-plugin/skills/lisa-setup-linear/SKILL.md +17 -0
  46. package/plugins/lisa/.codex-plugin/skills/lisa-setup-notion/SKILL.md +17 -0
  47. package/plugins/lisa/rules/eager/derived-branch-plan.md +45 -0
  48. package/plugins/lisa/rules/reference/config-resolution.md +16 -0
  49. package/plugins/lisa/rules/reference/derived-branch-plan.md +112 -0
  50. package/plugins/lisa/skills/lisa-github-read-issue/SKILL.md +1 -0
  51. package/plugins/lisa/skills/lisa-github-validate-issue/SKILL.md +22 -0
  52. package/plugins/lisa/skills/lisa-github-write-issue/SKILL.md +15 -0
  53. package/plugins/lisa/skills/lisa-implement/SKILL.md +6 -0
  54. package/plugins/lisa/skills/lisa-jira-validate-ticket/SKILL.md +22 -0
  55. package/plugins/lisa/skills/lisa-jira-write-ticket/SKILL.md +15 -0
  56. package/plugins/lisa/skills/lisa-linear-access/SKILL.md +25 -3
  57. package/plugins/lisa/skills/lisa-linear-validate-issue/SKILL.md +22 -0
  58. package/plugins/lisa/skills/lisa-linear-write-issue/SKILL.md +15 -0
  59. package/plugins/lisa/skills/lisa-secrets-access/SKILL.md +20 -2
  60. package/plugins/lisa/skills/lisa-secrets-access/scripts/doctor-secrets.mjs +13 -9
  61. package/plugins/lisa/skills/lisa-secrets-access/scripts/note-format.mjs +179 -0
  62. package/plugins/lisa/skills/lisa-secrets-access/scripts/resolve-secret.mjs +32 -6
  63. package/plugins/lisa/skills/lisa-secrets-access/scripts/tools-from-notes.mjs +6 -2
  64. package/plugins/lisa/skills/lisa-setup-atlassian/SKILL.md +17 -0
  65. package/plugins/lisa/skills/lisa-setup-linear/SKILL.md +17 -0
  66. package/plugins/lisa/skills/lisa-setup-notion/SKILL.md +17 -0
  67. package/plugins/lisa-agy/plugin.json +1 -1
  68. package/plugins/lisa-agy/skills/lisa-github-read-issue/SKILL.md +1 -0
  69. package/plugins/lisa-agy/skills/lisa-github-validate-issue/SKILL.md +22 -0
  70. package/plugins/lisa-agy/skills/lisa-github-write-issue/SKILL.md +15 -0
  71. package/plugins/lisa-agy/skills/lisa-implement/SKILL.md +6 -0
  72. package/plugins/lisa-agy/skills/lisa-jira-validate-ticket/SKILL.md +22 -0
  73. package/plugins/lisa-agy/skills/lisa-jira-write-ticket/SKILL.md +15 -0
  74. package/plugins/lisa-agy/skills/lisa-linear-access/SKILL.md +25 -3
  75. package/plugins/lisa-agy/skills/lisa-linear-validate-issue/SKILL.md +22 -0
  76. package/plugins/lisa-agy/skills/lisa-linear-write-issue/SKILL.md +15 -0
  77. package/plugins/lisa-agy/skills/lisa-secrets-access/SKILL.md +20 -2
  78. package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/doctor-secrets.mjs +13 -9
  79. package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/note-format.mjs +179 -0
  80. package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/resolve-secret.mjs +32 -6
  81. package/plugins/lisa-agy/skills/lisa-secrets-access/scripts/tools-from-notes.mjs +6 -2
  82. package/plugins/lisa-agy/skills/lisa-setup-atlassian/SKILL.md +17 -0
  83. package/plugins/lisa-agy/skills/lisa-setup-linear/SKILL.md +17 -0
  84. package/plugins/lisa-agy/skills/lisa-setup-notion/SKILL.md +17 -0
  85. package/plugins/lisa-cdk/.claude-plugin/plugin.json +1 -1
  86. package/plugins/lisa-cdk/.codex-plugin/plugin.json +1 -1
  87. package/plugins/lisa-cdk-agy/plugin.json +1 -1
  88. package/plugins/lisa-cdk-copilot/.claude-plugin/plugin.json +1 -1
  89. package/plugins/lisa-cdk-cursor/.claude-plugin/plugin.json +1 -1
  90. package/plugins/lisa-copilot/.claude-plugin/plugin.json +1 -1
  91. package/plugins/lisa-copilot/rules/eager/derived-branch-plan.md +45 -0
  92. package/plugins/lisa-copilot/rules/reference/config-resolution.md +16 -0
  93. package/plugins/lisa-copilot/rules/reference/derived-branch-plan.md +112 -0
  94. package/plugins/lisa-copilot/skills/lisa-github-read-issue/SKILL.md +1 -0
  95. package/plugins/lisa-copilot/skills/lisa-github-validate-issue/SKILL.md +22 -0
  96. package/plugins/lisa-copilot/skills/lisa-github-write-issue/SKILL.md +15 -0
  97. package/plugins/lisa-copilot/skills/lisa-implement/SKILL.md +6 -0
  98. package/plugins/lisa-copilot/skills/lisa-jira-validate-ticket/SKILL.md +22 -0
  99. package/plugins/lisa-copilot/skills/lisa-jira-write-ticket/SKILL.md +15 -0
  100. package/plugins/lisa-copilot/skills/lisa-linear-access/SKILL.md +25 -3
  101. package/plugins/lisa-copilot/skills/lisa-linear-validate-issue/SKILL.md +22 -0
  102. package/plugins/lisa-copilot/skills/lisa-linear-write-issue/SKILL.md +15 -0
  103. package/plugins/lisa-copilot/skills/lisa-secrets-access/SKILL.md +20 -2
  104. package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/doctor-secrets.mjs +13 -9
  105. package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/note-format.mjs +179 -0
  106. package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/resolve-secret.mjs +32 -6
  107. package/plugins/lisa-copilot/skills/lisa-secrets-access/scripts/tools-from-notes.mjs +6 -2
  108. package/plugins/lisa-copilot/skills/lisa-setup-atlassian/SKILL.md +17 -0
  109. package/plugins/lisa-copilot/skills/lisa-setup-linear/SKILL.md +17 -0
  110. package/plugins/lisa-copilot/skills/lisa-setup-notion/SKILL.md +17 -0
  111. package/plugins/lisa-cursor/.claude-plugin/plugin.json +1 -1
  112. package/plugins/lisa-cursor/rules/config-resolution-reference.mdc +16 -0
  113. package/plugins/lisa-cursor/rules/derived-branch-plan-reference.mdc +117 -0
  114. package/plugins/lisa-cursor/rules/derived-branch-plan.mdc +50 -0
  115. package/plugins/lisa-cursor/skills/lisa-github-read-issue/SKILL.md +1 -0
  116. package/plugins/lisa-cursor/skills/lisa-github-validate-issue/SKILL.md +22 -0
  117. package/plugins/lisa-cursor/skills/lisa-github-write-issue/SKILL.md +15 -0
  118. package/plugins/lisa-cursor/skills/lisa-implement/SKILL.md +6 -0
  119. package/plugins/lisa-cursor/skills/lisa-jira-validate-ticket/SKILL.md +22 -0
  120. package/plugins/lisa-cursor/skills/lisa-jira-write-ticket/SKILL.md +15 -0
  121. package/plugins/lisa-cursor/skills/lisa-linear-access/SKILL.md +25 -3
  122. package/plugins/lisa-cursor/skills/lisa-linear-validate-issue/SKILL.md +22 -0
  123. package/plugins/lisa-cursor/skills/lisa-linear-write-issue/SKILL.md +15 -0
  124. package/plugins/lisa-cursor/skills/lisa-secrets-access/SKILL.md +20 -2
  125. package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/doctor-secrets.mjs +13 -9
  126. package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/note-format.mjs +179 -0
  127. package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/resolve-secret.mjs +32 -6
  128. package/plugins/lisa-cursor/skills/lisa-secrets-access/scripts/tools-from-notes.mjs +6 -2
  129. package/plugins/lisa-cursor/skills/lisa-setup-atlassian/SKILL.md +17 -0
  130. package/plugins/lisa-cursor/skills/lisa-setup-linear/SKILL.md +17 -0
  131. package/plugins/lisa-cursor/skills/lisa-setup-notion/SKILL.md +17 -0
  132. package/plugins/lisa-expo/.claude-plugin/plugin.json +1 -1
  133. package/plugins/lisa-expo/.codex-plugin/plugin.json +1 -1
  134. package/plugins/lisa-expo-agy/plugin.json +1 -1
  135. package/plugins/lisa-expo-copilot/.claude-plugin/plugin.json +1 -1
  136. package/plugins/lisa-expo-cursor/.claude-plugin/plugin.json +1 -1
  137. package/plugins/lisa-harper-fabric/.claude-plugin/plugin.json +1 -1
  138. package/plugins/lisa-harper-fabric/.codex-plugin/plugin.json +1 -1
  139. package/plugins/lisa-harper-fabric-agy/plugin.json +1 -1
  140. package/plugins/lisa-harper-fabric-copilot/.claude-plugin/plugin.json +1 -1
  141. package/plugins/lisa-harper-fabric-cursor/.claude-plugin/plugin.json +1 -1
  142. package/plugins/lisa-nestjs/.claude-plugin/plugin.json +1 -1
  143. package/plugins/lisa-nestjs/.codex-plugin/plugin.json +1 -1
  144. package/plugins/lisa-nestjs-agy/plugin.json +1 -1
  145. package/plugins/lisa-nestjs-copilot/.claude-plugin/plugin.json +1 -1
  146. package/plugins/lisa-nestjs-cursor/.claude-plugin/plugin.json +1 -1
  147. package/plugins/lisa-openclaw/.claude-plugin/plugin.json +1 -1
  148. package/plugins/lisa-openclaw/.codex-plugin/plugin.json +1 -1
  149. package/plugins/lisa-openclaw-agy/plugin.json +1 -1
  150. package/plugins/lisa-openclaw-copilot/.claude-plugin/plugin.json +1 -1
  151. package/plugins/lisa-openclaw-cursor/.claude-plugin/plugin.json +1 -1
  152. package/plugins/lisa-phaser/.claude-plugin/plugin.json +1 -1
  153. package/plugins/lisa-phaser/.codex-plugin/plugin.json +1 -1
  154. package/plugins/lisa-phaser-agy/plugin.json +1 -1
  155. package/plugins/lisa-phaser-copilot/.claude-plugin/plugin.json +1 -1
  156. package/plugins/lisa-phaser-cursor/.claude-plugin/plugin.json +1 -1
  157. package/plugins/lisa-rails/.claude-plugin/plugin.json +1 -1
  158. package/plugins/lisa-rails/.codex-plugin/plugin.json +1 -1
  159. package/plugins/lisa-rails-agy/plugin.json +1 -1
  160. package/plugins/lisa-rails-copilot/.claude-plugin/plugin.json +1 -1
  161. package/plugins/lisa-rails-cursor/.claude-plugin/plugin.json +1 -1
  162. package/plugins/lisa-typescript/.claude-plugin/plugin.json +1 -1
  163. package/plugins/lisa-typescript/.codex-plugin/plugin.json +1 -1
  164. package/plugins/lisa-typescript-agy/plugin.json +1 -1
  165. package/plugins/lisa-typescript-copilot/.claude-plugin/plugin.json +1 -1
  166. package/plugins/lisa-typescript-cursor/.claude-plugin/plugin.json +1 -1
  167. package/plugins/lisa-wiki/.claude-plugin/plugin.json +1 -1
  168. package/plugins/lisa-wiki/.codex-plugin/plugin.json +1 -1
  169. package/plugins/lisa-wiki-agy/plugin.json +1 -1
  170. package/plugins/lisa-wiki-copilot/.claude-plugin/plugin.json +1 -1
  171. package/plugins/lisa-wiki-cursor/.claude-plugin/plugin.json +1 -1
  172. package/plugins/src/base/rules/eager/derived-branch-plan.md +45 -0
  173. package/plugins/src/base/rules/reference/config-resolution.md +16 -0
  174. package/plugins/src/base/rules/reference/derived-branch-plan.md +112 -0
  175. package/plugins/src/base/skills/lisa-github-read-issue/SKILL.md +1 -0
  176. package/plugins/src/base/skills/lisa-github-validate-issue/SKILL.md +22 -0
  177. package/plugins/src/base/skills/lisa-github-write-issue/SKILL.md +15 -0
  178. package/plugins/src/base/skills/lisa-implement/SKILL.md +6 -0
  179. package/plugins/src/base/skills/lisa-jira-validate-ticket/SKILL.md +22 -0
  180. package/plugins/src/base/skills/lisa-jira-write-ticket/SKILL.md +15 -0
  181. package/plugins/src/base/skills/lisa-linear-access/SKILL.md +25 -3
  182. package/plugins/src/base/skills/lisa-linear-validate-issue/SKILL.md +22 -0
  183. package/plugins/src/base/skills/lisa-linear-write-issue/SKILL.md +15 -0
  184. package/plugins/src/base/skills/lisa-secrets-access/SKILL.md +20 -2
  185. package/plugins/src/base/skills/lisa-secrets-access/scripts/doctor-secrets.mjs +13 -9
  186. package/plugins/src/base/skills/lisa-secrets-access/scripts/note-format.mjs +179 -0
  187. package/plugins/src/base/skills/lisa-secrets-access/scripts/resolve-secret.mjs +32 -6
  188. package/plugins/src/base/skills/lisa-secrets-access/scripts/tools-from-notes.mjs +6 -2
  189. package/plugins/src/base/skills/lisa-setup-atlassian/SKILL.md +17 -0
  190. package/plugins/src/base/skills/lisa-setup-linear/SKILL.md +17 -0
  191. package/plugins/src/base/skills/lisa-setup-notion/SKILL.md +17 -0
  192. package/scripts/github-status-check.sh +22 -7
@@ -0,0 +1,179 @@
1
+ /**
2
+ * Validate a credential's usage note against the format the contract documents.
3
+ *
4
+ * The contract states Rule A — "the note must exist and be well-formed",
5
+ * enforced statically by `verify` and by `doctor`. Only half of that was ever
6
+ * true. Both consumers tested the note for emptiness and nothing tested its
7
+ * shape, so a note that promised a scope and delivered a bare colon, or a
8
+ * `tool:` line naming a URL instead of a CLI, passed every check Lisa had. The
9
+ * prose described an enforcement that did not exist, which is worse than no
10
+ * rule: readers stopped checking because they believed something else was.
11
+ *
12
+ * This module is that missing half, and it lives in one place on purpose. The
13
+ * same argument the values file makes for keeping its writer and its parser
14
+ * together applies here: `tools-from-notes.mjs` decides what a `tool:` line
15
+ * *is*, and if this validator held a second copy of that pattern, a note could
16
+ * pass doctor and then be silently ignored at install time with nothing to
17
+ * reveal the disagreement. So the matcher is defined here once and imported
18
+ * there.
19
+ *
20
+ * Messages are written for the person who has to fix the vault, who is often
21
+ * not an engineer. Each one names the secret's defect and the edit that clears
22
+ * it, never only the rule that was broken.
23
+ * @module note-format
24
+ */
25
+
26
+ /**
27
+ * A `key: value` metadata line.
28
+ *
29
+ * The key must be a single bare lowercase token. That is what separates
30
+ * `scope: read-write` from prose that happens to contain a colon, such as
31
+ * "Attio CRM: system of record for sales" — a sentence has spaces before its
32
+ * colon, and a capitalised word opening a sentence is prose, not a field. The
33
+ * discriminator is deliberately generous: mistaking a field for prose only
34
+ * loosens a check, while mistaking prose for a field would fail a good note.
35
+ */
36
+ const FIELD_LINE = /^[ \t]*([a-z][a-z0-9_-]*)[ \t]*:[ \t]*(.*)$/;
37
+
38
+ /** Matches `tool: name` or `tools: a, b`, case-insensitively, on one line. */
39
+ const TOOL_LINE_SINGLE = /^[ \t]*tools?[ \t]*:[ \t]*(.*)$/i;
40
+
41
+ /**
42
+ * The same matcher, global and multiline, for scanning a whole note.
43
+ *
44
+ * Derived from the single-line pattern rather than written out again, so the
45
+ * two can never disagree about what a tool line is.
46
+ */
47
+ export const TOOL_LINE = new RegExp(TOOL_LINE_SINGLE.source, "gim");
48
+
49
+ /**
50
+ * A bare CLI name: what a `tool:` entry is permitted to be.
51
+ *
52
+ * Names are matched against Lisa's catalogue and never executed, so this is not
53
+ * the security boundary — the catalogue is. It is the check that tells an
54
+ * operator their entry will be silently dropped, which is the failure mode
55
+ * worth catching: a note asking for `sonar (for CI)` installs nothing, and the
56
+ * session fails much later for a reason that looks unrelated.
57
+ */
58
+ const TOOL_NAME = /^[a-z0-9][a-z0-9._+-]*$/;
59
+
60
+ /**
61
+ * Whether a line is structured metadata rather than a sentence.
62
+ * @param {string} line One line of a note.
63
+ * @returns {boolean} True when the line is a field or a tool line.
64
+ */
65
+ function isMetadataLine(line) {
66
+ return FIELD_LINE.test(line) || TOOL_LINE_SINGLE.test(line);
67
+ }
68
+
69
+ /**
70
+ * Check the entries on one `tool:` / `tools:` line.
71
+ * @param {string} value The text after the colon.
72
+ * @param {object[]} defects Collector to append to.
73
+ */
74
+ function checkToolLine(value, defects) {
75
+ if (!value.trim()) {
76
+ defects.push({
77
+ level: "error",
78
+ code: "empty-tool-line",
79
+ message:
80
+ "has a `tool:` line that names no tool. Either name the command-line " +
81
+ "tool this credential is for (for example `tool: sonar`) or delete " +
82
+ "the line — as written it asks for a tool and supplies none, so " +
83
+ "nothing gets installed",
84
+ });
85
+ return;
86
+ }
87
+
88
+ for (const raw of value.split(",")) {
89
+ const entry = raw.trim();
90
+ if (!entry) {
91
+ // A trailing or doubled comma is sloppy punctuation, not a broken note:
92
+ // the reader drops the empty entry and installs the rest correctly.
93
+ // Blocking a vault over a comma would teach operators the check is noise.
94
+ defects.push({
95
+ level: "warn",
96
+ code: "stray-separator",
97
+ message:
98
+ "has a `tool:` line with a stray comma. Nothing breaks, but tidy it " +
99
+ "so the list reads as the tools it actually names",
100
+ });
101
+ continue;
102
+ }
103
+ if (!TOOL_NAME.test(entry.toLowerCase())) {
104
+ defects.push({
105
+ level: "error",
106
+ code: "bad-tool-name",
107
+ message:
108
+ `has a \`tool:\` entry that is not a tool name: "${entry}". Each ` +
109
+ "entry must be one plain name such as `sonar` or `gh`, separated by " +
110
+ "commas — no descriptions, links, versions, or punctuation. As " +
111
+ "written this entry is ignored, so the tool never gets installed",
112
+ });
113
+ }
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Report every way a usage note departs from the documented format.
119
+ *
120
+ * Returns defects rather than throwing so a caller can list a whole vault's
121
+ * problems in one pass. An operator fixing a vault wants every edit at once,
122
+ * not one error per run.
123
+ * @param {unknown} note The note text stored beside the secret.
124
+ * @returns {{level: string, code: string, message: string}[]} Defects found.
125
+ */
126
+ export function validateNote(note) {
127
+ if (typeof note !== "string" || !note.trim()) {
128
+ // One cause, one instruction. Also accusing an absent note of lacking a
129
+ // first line would leave the operator guessing which fix comes first.
130
+ return [
131
+ {
132
+ level: "error",
133
+ code: "missing-note",
134
+ message:
135
+ "has no usage note. Write one in the secret's own description field " +
136
+ "in the vault: a first line saying what this credential is for and " +
137
+ "what it can reach, then `key: value` lines such as `scope:`, " +
138
+ "`owner:`, and `tool:`. Guessing a credential's purpose from its " +
139
+ "name is exactly the guess that writes to the wrong system",
140
+ },
141
+ ];
142
+ }
143
+
144
+ const defects = [];
145
+ const lines = note.split(/\r?\n/);
146
+ const populated = lines.filter(line => line.trim());
147
+
148
+ if (!populated.some(line => !isMetadataLine(line))) {
149
+ defects.push({
150
+ level: "error",
151
+ code: "no-prose",
152
+ message:
153
+ "has no plain-language first line. Add a sentence at the top saying " +
154
+ "what this credential is for and what it can reach — the `key: value` " +
155
+ "lines below it list details, but they never say what the thing is",
156
+ });
157
+ }
158
+
159
+ for (const line of populated) {
160
+ const tool = TOOL_LINE_SINGLE.exec(line);
161
+ if (tool) {
162
+ checkToolLine(tool[1], defects);
163
+ continue;
164
+ }
165
+ const field = FIELD_LINE.exec(line);
166
+ if (field && !field[2].trim()) {
167
+ defects.push({
168
+ level: "error",
169
+ code: "empty-field",
170
+ message:
171
+ `has an empty \`${field[1]}:\` line. Either fill in the value or ` +
172
+ "delete the line — a field with nothing after the colon promises a " +
173
+ "fact the reader then cannot find anywhere",
174
+ });
175
+ }
176
+ }
177
+
178
+ return defects;
179
+ }
@@ -30,6 +30,7 @@
30
30
  import { existsSync, readFileSync } from "node:fs";
31
31
 
32
32
  import { parseEnv } from "./envfile.mjs";
33
+ import { validateNote } from "./note-format.mjs";
33
34
  import { ENV_KEY, fetchAll } from "./providers.mjs";
34
35
  import { materializedPaths, readConfig } from "./surfaces.mjs";
35
36
 
@@ -109,6 +110,19 @@ function sourceOf(name, provider, file) {
109
110
  return " ";
110
111
  }
111
112
 
113
+ /**
114
+ * Say what is wrong with a note, not merely that something is.
115
+ *
116
+ * "NO NOTE" against a note that exists but is malformed sends the operator
117
+ * looking for a missing field they already wrote.
118
+ * @param {object} [fault] The blocking defect, if any.
119
+ * @returns {string} A status label for the verify table.
120
+ */
121
+ function noteStatus(fault) {
122
+ if (!fault) return "noted";
123
+ return fault.code === "missing-note" ? "NO NOTE" : `NOTE ${fault.code}`;
124
+ }
125
+
112
126
  /**
113
127
  * Verify every declared secret, mirroring the ladder's own order.
114
128
  *
@@ -119,12 +133,20 @@ function sourceOf(name, provider, file) {
119
133
  * This command is read-only. Proving that a rotating credential can actually be
120
134
  * written back requires a write, so that check lives in the rotation path
121
135
  * rather than here.
136
+ *
137
+ * The two views are parameters so a test can supply them. Reaching for the
138
+ * provider CLI is the one thing in here that cannot run in a test, and a check
139
+ * nobody can test is how the note rule stayed unenforced for so long.
122
140
  * @param {object} cfg Resolved configuration.
141
+ * @param {Map<string, object>} [provider] Provider view.
142
+ * @param {Map<string, string>} [file] Materialized view.
123
143
  * @returns {number} Count of secrets that failed.
124
144
  */
125
- function verify(cfg) {
126
- const provider = fetchAll(cfg);
127
- const file = readMaterialized(cfg);
145
+ export function verify(
146
+ cfg,
147
+ provider = fetchAll(cfg),
148
+ file = readMaterialized(cfg)
149
+ ) {
128
150
  const names = cfg.require ?? [
129
151
  ...new Set([...provider.keys(), ...file.keys()]),
130
152
  ];
@@ -139,13 +161,17 @@ function verify(cfg) {
139
161
  provider.get(name)?.value
140
162
  );
141
163
  const named = ENV_KEY.test(name);
142
- const noted = Boolean(provider.get(name)?.note);
143
- if (!resolves || !named || !noted) bad += 1;
164
+ // Presence is not well-formedness. Testing `Boolean(note)` passed a note
165
+ // that was a single stray character, which is exactly the note an agent
166
+ // learns nothing from. Same validator doctor uses, so the two agree.
167
+ const defects = validateNote(provider.get(name)?.note);
168
+ const noteFault = defects.find(d => d.level === "error");
169
+ if (!resolves || !named || noteFault) bad += 1;
144
170
  console.log(
145
171
  ` ${name.padEnd(30)} ${resolves ? "resolves" : "MISSING "} ` +
146
172
  `${sourceOf(name, provider, file)} ` +
147
173
  `${named ? "name ok" : "NAME NOT UPPER_SNAKE"} ` +
148
- `${noted ? "noted" : "NO NOTE"}` +
174
+ `${noteStatus(noteFault)}` +
149
175
  `${rotating.has(name) ? " rotating" : ""}`
150
176
  );
151
177
  }
@@ -21,11 +21,15 @@
21
21
  * its note. Selecting from a known set means the worst a hostile note can do is
22
22
  * ask for a CLI Lisa already ships a pinned, checksummed entry for — it can
23
23
  * never introduce a URL, a version, or a command.
24
+ * The matcher itself lives in `note-format.mjs` alongside the validator that
25
+ * checks these lines, for the same reason the values file keeps its writer and
26
+ * its parser in one module: two copies of the pattern would let a note pass
27
+ * `doctor` and then be silently ignored here, with nothing to reveal the
28
+ * disagreement.
24
29
  * @module tools-from-notes
25
30
  */
26
31
 
27
- /** Matches `tool: name` or `tools: a, b`, case-insensitively, one per line. */
28
- const TOOL_LINE = /^[ \t]*tools?[ \t]*:[ \t]*(.+)$/gim;
32
+ import { TOOL_LINE } from "./note-format.mjs";
29
33
 
30
34
  /**
31
35
  * Collect the tool names a set of notes asks for.
@@ -77,6 +77,23 @@ read_token() {
77
77
  local slug=$(echo "$email" | tr '[:upper:]@.' '[:lower:]__')
78
78
  local varname="ATLASSIAN_API_TOKEN_${slug}"
79
79
  [ -n "${!varname}" ] && { echo "${!varname}"; return; }
80
+ # Preferred path: the single secrets chokepoint. It owns the one-store rule
81
+ # and the surface ladder, so anything it can answer must not be read out of an
82
+ # OS keychain here — a second reader is how the same credential ends up living
83
+ # in two places and drifting. Keep this identical to `atlassian-access`.
84
+ local resolver
85
+ for resolver in .claude/skills/lisa-secrets-access/scripts/resolve-secret.mjs \
86
+ .agents/skills/lisa-secrets-access/scripts/resolve-secret.mjs; do
87
+ if [ -f "$resolver" ]; then
88
+ local via_lisa
89
+ via_lisa=$(node "$resolver" get ATLASSIAN_API_TOKEN 2>/dev/null) \
90
+ && [ -n "$via_lisa" ] && { echo "$via_lisa"; return; }
91
+ break
92
+ fi
93
+ done
94
+ # Legacy fallback: the OS keychain written by the guided flow below, for
95
+ # projects that have not adopted a credentials provider. Reached only when the
96
+ # chokepoint is absent or has no entry.
80
97
  case "$(uname -s)" in
81
98
  Darwin) security find-generic-password -s lisa-atlassian -a "$email" -w 2>/dev/null ;;
82
99
  Linux) command -v secret-tool >/dev/null && secret-tool lookup service lisa-atlassian account "$email" 2>/dev/null ;;
@@ -89,6 +89,23 @@ read_linear_key() { # $1=workspace slug
89
89
  local slug; slug=$(echo "$ws" | tr '[:upper:]-' '[:lower:]_')
90
90
  local varname="LINEAR_API_KEY_${slug}"
91
91
  [ -n "${!varname}" ] && { echo "${!varname}"; return; }
92
+ # Preferred path: the single secrets chokepoint. It owns the one-store rule
93
+ # and the surface ladder, so anything it can answer must not be read out of an
94
+ # OS keychain here — a second reader is how the same credential ends up living
95
+ # in two places and drifting. Keep this identical to `linear-access`.
96
+ local resolver
97
+ for resolver in .claude/skills/lisa-secrets-access/scripts/resolve-secret.mjs \
98
+ .agents/skills/lisa-secrets-access/scripts/resolve-secret.mjs; do
99
+ if [ -f "$resolver" ]; then
100
+ local via_lisa
101
+ via_lisa=$(node "$resolver" get LINEAR_API_KEY 2>/dev/null) \
102
+ && [ -n "$via_lisa" ] && { echo "$via_lisa"; return; }
103
+ break
104
+ fi
105
+ done
106
+ # Legacy fallback: the OS keychain written by the guided flow below, for
107
+ # projects that have not adopted a credentials provider. Reached only when the
108
+ # chokepoint is absent or has no entry.
92
109
  case "$(uname -s)" in
93
110
  Darwin) security find-generic-password -s lisa-linear -a "$ws" -w 2>/dev/null ;;
94
111
  Linux) command -v secret-tool >/dev/null && secret-tool lookup service lisa-linear account "$ws" 2>/dev/null ;;
@@ -164,6 +164,23 @@ read_notion_token() {
164
164
  local slug=$(echo "$workspace" | tr '[:upper:]-' '[:lower:]_')
165
165
  local varname="NOTION_API_TOKEN_${slug}"
166
166
  [ -n "${!varname}" ] && { echo "${!varname}"; return; }
167
+ # Preferred path: the single secrets chokepoint. It owns the one-store rule
168
+ # and the surface ladder, so anything it can answer must not be read out of an
169
+ # OS keychain here — a second reader is how the same credential ends up living
170
+ # in two places and drifting. Keep this identical to `notion-access`.
171
+ local resolver
172
+ for resolver in .claude/skills/lisa-secrets-access/scripts/resolve-secret.mjs \
173
+ .agents/skills/lisa-secrets-access/scripts/resolve-secret.mjs; do
174
+ if [ -f "$resolver" ]; then
175
+ local via_lisa
176
+ via_lisa=$(node "$resolver" get NOTION_API_TOKEN 2>/dev/null) \
177
+ && [ -n "$via_lisa" ] && { echo "$via_lisa"; return; }
178
+ break
179
+ fi
180
+ done
181
+ # Legacy fallback: the OS keychain written by the guided flow below, for
182
+ # projects that have not adopted a credentials provider. Reached only when the
183
+ # chokepoint is absent or has no entry.
167
184
  case "$(uname -s)" in
168
185
  Darwin) security find-generic-password -s lisa-notion -a "$workspace" -w 2>/dev/null ;;
169
186
  Linux) command -v secret-tool >/dev/null && secret-tool lookup service lisa-notion account "$workspace" 2>/dev/null ;;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lisa",
3
- "version": "2.349.1",
3
+ "version": "2.351.0",
4
4
  "description": "Universal governance — agents, skills, commands, hooks, and rules for all projects",
5
5
  "author": {
6
6
  "name": "Cody Swann"
@@ -852,6 +852,22 @@ read_notion_token() {
852
852
  local slug=$(echo "$workspace" | tr '[:upper:]-' '[:lower:]_')
853
853
  local varname="NOTION_API_TOKEN_${slug}"
854
854
  [ -n "${!varname}" ] && { echo "${!varname}"; return; }
855
+ # Preferred path: the single secrets chokepoint, which owns the one-store rule
856
+ # and the surface ladder. An agent following this reference must try it before
857
+ # any keychain — a second reader is how one credential ends up in two places.
858
+ local resolver
859
+ for resolver in .claude/skills/lisa-secrets-access/scripts/resolve-secret.mjs \
860
+ .agents/skills/lisa-secrets-access/scripts/resolve-secret.mjs; do
861
+ if [ -f "$resolver" ]; then
862
+ local via_lisa
863
+ via_lisa=$(node "$resolver" get NOTION_API_TOKEN 2>/dev/null) \
864
+ && [ -n "$via_lisa" ] && { echo "$via_lisa"; return; }
865
+ break
866
+ fi
867
+ done
868
+ # Legacy fallback: the OS keychain written by the guided setup flow, for
869
+ # projects with no credentials provider. Reached only when the chokepoint is
870
+ # absent or has no entry.
855
871
  case "$(uname -s)" in
856
872
  Darwin) security find-generic-password -s lisa-notion -a "$workspace" -w 2>/dev/null ;;
857
873
  Linux) command -v secret-tool >/dev/null && \
@@ -0,0 +1,117 @@
1
+ ---
2
+ description: "Derived Branch Plan — reference"
3
+ alwaysApply: false
4
+ ---
5
+
6
+ # Derived Branch Plan — reference
7
+
8
+ The full body behind the `derived-branch-plan` eager head. It defines one vendor-neutral contract consumed by the three tracker writers (`lisa-jira-write-ticket`, `lisa-github-write-issue`, `lisa-linear-write-issue`), the three validators (`lisa-jira-validate-ticket`, `lisa-github-validate-issue`, `lisa-linear-validate-issue`) via gate **S19**, and `lisa-implement` at claim time. Each surface cites this slug rather than growing its own prose, exactly as the vendor arms cite `leaf-only-lifecycle` and `repo-scope-split`. One slug is what keeps a branch plan rejected on JIRA from being accepted on Linear.
9
+
10
+ ## The problem this solves, and the one it must not create
11
+
12
+ An operator reading a work item cannot see which branch the work starts from or which branch the PR lands in. Both facts are knowable, but only by resolving `.lisa.config.json` — which is exactly the kind of engineering step the factory model says a non-technical operator standing at the gate should not have to take.
13
+
14
+ The obvious fix — add a "source branch" field and a "PR target" field to the ticket template — is wrong, and it is worth being explicit about why, because it will look like the simple answer every time someone revisits this. Those fields would be **a second source of truth** for a fact Lisa already derives authoritatively from `## Target Backend Environment` + `deploy.branches`. Two authorities do not stay equal. They drift the first time an environment is corrected on a ticket whose branch fields nobody updated, or the first time `deploy.branches` is remapped. And the consequence of that drift is not a stale label: it is an agent branching from, and merging into, the wrong environment's branch — shipping unreviewed code to production, or shipping a production fix into a staging branch where nobody sees it.
15
+
16
+ So the contract renders the branches **for humans** and recomputes them **for machines**. The rendered section is output. It is never input.
17
+
18
+ Precedence is therefore not a negotiation: whenever a rendered plan and the resolved environment disagree, **the environment wins** — the authority wins, in every phase, on every vendor, with no exception for a plan a human edited by hand. The only question a disagreement raises is whether to re-render silently (staleness) or stop for a human (a conflict with a confirmed environment or an open PR base). It is never "which branch did they mean?"
19
+
20
+ ## The rendered section
21
+
22
+ | Vendor | Heading form |
23
+ |---|---|
24
+ | JIRA | `h2. Branch Plan` (ADF heading in live JIRA) |
25
+ | GitHub | `## Branch Plan` |
26
+ | Linear | `## Branch Plan` |
27
+
28
+ Body, identical on all three:
29
+
30
+ ```
31
+ Branch from: <branch>
32
+ PR into: <branch>
33
+ Derived from: Target Backend Environment <env> via .lisa.config.json deploy.branches
34
+ ```
35
+
36
+ ### The derivation provenance line
37
+
38
+ The third line is load-bearing. It is the discriminator between a section this contract produced and one a human typed, and it is deliberately visible prose rather than an HTML comment — the same reason the `Target Backend Environment` grammar uses visible `Inferred:` / `Assumption:` annotations: JIRA's ADF has no comment node, so a marker that only exists in markdown cannot be a vendor-neutral discriminator.
39
+
40
+ A `Branch Plan` **without the provenance line is treated as hand-authored**, and hand-authored branches are never obeyed — they are compared against the recomputed plan and, on any disagreement, fail. A provenance line naming an `<env>` that is not an exact configured `deploy.branches` key is itself malformed and fails.
41
+
42
+ ### One branch, two labels
43
+
44
+ `Branch from` and `PR into` always name the **same branch**. That is not a simplification, it is the invariant `lisa-implement` already implements: the feature branch is cut from `origin/<base>` and the PR targets `<base>`. Both labels exist because operators asked to see both questions answered, and because naming them separately gives the contract somewhere to say they are equal instead of leaving it implicit.
45
+
46
+ A plan whose two fields name **two different branches** is malformed and fails validation. The case that looks like a counter-example — a bug fixed on a non-integration environment branch that must also reach the integration branch — is handled the way `lisa-implement` already handles it: as a **linked forward cherry-pick follow-up item**, which is its own work item with its own single-branch plan. It is never a divergence inside one plan.
47
+
48
+ ## Derivation algorithm
49
+
50
+ 1. **Resolve the environment.** Use the existing grammar and precedence defined in `config-resolution` and `pre-flight-autofill`: a human-confirmed bare configured key or `Confirmed: <env>` wins; then a validated `Inferred: <env> — evidence: <title|body|reproduction|hostname>`; then `Assumption: <env> — remote default branch <branch>`, or the branch-only `Assumption: remote default branch <branch>` when the reverse-map is not unique. This rule adds no new resolution logic and no new aliases.
51
+ 2. **Map forward.** Look the exact configured key up in `deploy.branches`. The key must resolve to exactly one branch.
52
+ 3. **Prove the branch.** The mapped branch must exist on the remote.
53
+ 4. **Render.** Both fields to that branch, plus the provenance line naming the `<env>` used.
54
+
55
+ ### Stop conditions
56
+
57
+ | Condition | Behavior |
58
+ |---|---|
59
+ | No environment resolvable and the item is not exempt | Stop — the `Target Backend Environment` gate (S8) already owns this |
60
+ | Environment key absent from `deploy.branches` | Stop |
61
+ | Mapping ambiguous / not unique | Stop |
62
+ | Mapped branch missing on the remote | Stop |
63
+
64
+ **Never guess.** There is no fallback that quietly substitutes `main`, the remote default branch, or the branch of a sibling environment to keep a write from failing — a silent guess here is the exact failure this contract exists to prevent, and a stopped write is cheap next to a wrong-branch merge. The remote default branch enters only through the `Assumption:` form the environment grammar already defines, and only recorded as an assumption.
65
+
66
+ ## Gate S19 — Branch Plan derivation
67
+
68
+ Registered in all three validators as `| S19 Branch Plan derivation | technical | false |`. The gate **recomputes** the plan from current config and compares; it never reads the rendered branches as input.
69
+
70
+ | Case | Verdict |
71
+ |---|---|
72
+ | Exempt work (`runtime_behavior_change = false`, or a container) with no plan | `N/A` |
73
+ | Exempt work **carrying** a plan | **FAIL** — hand-authored branches on work that declared no runtime target |
74
+ | Applicable work, plan present, matches recomputed plan | PASS |
75
+ | Applicable work, plan present, disagrees with recomputed plan | **FAIL** |
76
+ | Applicable work, plan present, missing the provenance line and disagreeing | **FAIL** (hand-authored) |
77
+ | Applicable work, two fields naming different branches | **FAIL** — malformed |
78
+ | Applicable work, derivation hits a stop condition | **FAIL** — same stop as implement |
79
+ | Applicable work, **proposed spec** (pre-write) with no plan | **FAIL** — the writer must render it before the write |
80
+ | Applicable work, **live legacy item** with no plan | `N/A` with a repair note routed to claim time |
81
+
82
+ The last two rows are the asymmetry that matters. Failing a *proposed* spec is free — the writer just renders the section. Failing every *existing* item would turn a whole legacy queue red overnight for a section no human ever had a way to add, so those are repaired at claim time instead, where the derivation is written onto the item as evidence.
83
+
84
+ ### Failure remediation
85
+
86
+ Every S19 failure names both plans (rendered and recomputed) and points the fix at **the environment, never the branches**:
87
+
88
+ > Branch Plan conflicts with the environment mapping. Rendered `Branch from: release/staging`; recomputed from `Target Backend Environment: production` via `deploy.branches` → `main`. Correct the environment, not the branch — the branches are derived. Then re-render.
89
+
90
+ The gate never silently chooses between the two. Picking one would be a guess wearing a verdict.
91
+
92
+ ## Claim-time behavior (`lisa-implement`)
93
+
94
+ At claim time the plan is recomputed against **current config and the remote** — never trusted from the item — and one of four arms runs:
95
+
96
+ - **Match** — proceed. The already-existing base-branch validation, feature-branch sync, and `target_branch=<base>` handoff are unchanged.
97
+ - **Legacy (no plan)** — derive it, **write the assumption onto the item as a comment**, then proceed. The comment carries a visible prose line plus a dedupe marker so a re-claim produces no duplicate:
98
+
99
+ ```
100
+ Branch plan derived for this item: branch from `main`, PR into `main` (Target Backend
101
+ Environment: production via .lisa.config.json deploy.branches).
102
+ <!-- [lisa-branch-plan] key=<work-item-ref>::<branch> -->
103
+ ```
104
+
105
+ Marker-dedupe is on `<work-item-ref>::<branch>`, so the comment reappears only if the derived branch actually changes. Where a vendor cannot host an HTML comment, the visible line alone carries it. If the comment cannot be written, that is a stop, not a shrug — proceeding would make it exactly the silent guess this rule forbids.
106
+ - **Conflict with a human-confirmed environment, or with an existing open PR's base** — **stop under the existing confirmation rules**. `lisa-implement` already surfaces a PR-base mismatch and re-targets only with confirmation, on the stated grounds that the ticket's environment is the source of truth; a branch plan never overrides that, and never supplies the confirmation itself.
107
+ - **Stale (config changed since the plan was rendered)** — **current config wins**. Re-render the section onto the item, record the change, and never follow the stale plan. A stale plan is not a conflict to escalate; it is output that fell behind its input.
108
+
109
+ ## Why the gate is `technical` / not product-relevant
110
+
111
+ S19 is categorized `technical`, `product_relevant: false`, matching S8 — the fact it checks is a deployment-topology fact, and a PRD-intake comment aimed at a product author cannot act on it. The operator-facing value of the section is that it is *visible on the item*, not that its failures are routed to product.
112
+
113
+ ## What this rule deliberately does not do
114
+
115
+ - It defines **no new environment resolution**, no new aliases, and no new provenance grammar. All of that stays in `config-resolution` / `pre-flight-autofill`, and this rule reads the result.
116
+ - It does **not** let a branch plan influence which environment is chosen, in any direction, at any phase.
117
+ - It does **not** introduce branch fields on PRDs. PRDs are not built directly; their generated leaves carry the plan.
@@ -0,0 +1,50 @@
1
+ ---
2
+ description: "Derived Branch Plan (load-bearing)"
3
+ alwaysApply: true
4
+ ---
5
+
6
+ # Derived Branch Plan (load-bearing)
7
+
8
+ **Every applicable leaf work item shows the branch it will be built from and the branch its PR lands in, as a generated `Branch Plan` section — and that section is derived data, not a second authority.** The authority is `## Target Backend Environment` resolved forward through `.lisa.config.json` `deploy.branches`. A work item that displays branches nobody can trace back to that mapping, or a flow that reads the displayed branches instead of recomputing them, is a contract violation.
9
+
10
+ **One vendor-neutral contract, cited by** `lisa-jira-write-ticket`, `lisa-github-write-issue`, `lisa-linear-write-issue`, `lisa-jira-validate-ticket`, `lisa-github-validate-issue`, `lisa-linear-validate-issue`, and `lisa-implement` (the `leaf-only-lifecycle` / `repo-scope-split` precedent: one shared slug, never divergent per-vendor prose).
11
+
12
+ ## Why derived, and not two branch fields
13
+
14
+ The operator need is real: reading a ticket should not require resolving a config file to learn where the work starts and where it lands. But Lisa already owns that fact. Adding independent literal branch fields would create **a second source of truth that can drift** — and the failure mode of that drift is not a cosmetic mismatch, it is code silently shipped to the wrong environment. So the branches are rendered for humans and recomputed for machines. The rendered branches are **never read as input** by any flow, at any phase — a surface that needs the base branch derives it again from the environment.
15
+
16
+ ## The rendered section
17
+
18
+ Exactly three lines, identical across vendors (`h2. Branch Plan` in JIRA wiki markup, `## Branch Plan` in GitHub/Linear markdown):
19
+
20
+ ```
21
+ Branch from: <branch>
22
+ PR into: <branch>
23
+ Derived from: Target Backend Environment <env> via .lisa.config.json deploy.branches
24
+ ```
25
+
26
+ The third line is the **derivation provenance line**. It is what marks the section machine-authored: a `Branch Plan` without it is treated as hand-authored, and hand-authored branches are never obeyed.
27
+
28
+ `Branch from` and `PR into` name the **same branch by construction** — implementation checks the feature branch out of `origin/<base>` and targets the PR back into `<base>`. A plan naming two different branches is malformed and fails validation. (A fix that genuinely lands on one branch and must reach another travels as a linked follow-up work item with its own branch plan, never as a divergence inside one plan.)
29
+
30
+ ## Derivation
31
+
32
+ 1. Resolve the environment under the existing `Target Backend Environment` grammar (`config-resolution`, `pre-flight-autofill`) — human-confirmed wins, then validated `Inferred:`, then `Assumption:`.
33
+ 2. Map that exact configured key forward through `deploy.branches`. The key must map uniquely and the mapped branch must exist on the remote.
34
+ 3. Render both fields to that branch plus the provenance line.
35
+
36
+ A missing or **ambiguous** mapping, a key that is **not unique**, or a branch absent from the remote **stops** the flow — exactly as `lisa-implement` already stops. **Never default independently to `main`, to the remote default branch, or to any other branch** to keep a write from failing. The remote default is a legitimate input only through the `Assumption:` fallback the environment grammar already defines, and it must be recorded as such.
37
+
38
+ ## Exemption
39
+
40
+ Work that declares no runtime behavior change — `runtime_behavior_change = false`, i.e. doc-only, config-only, and type-only items — carries **no `Target Backend Environment`**, therefore has nothing to derive from and **requires no branch plan**. Its **absence is correct**, not a missing section, and no gate may demand one. Containers (an Epic, or a Story/Spike still holding child work) are exempt for the same reason: they are not built directly.
41
+
42
+ The exemption is one-way. Exempt work that *carries* a branch plan fails validation — branches asserted for work that declared it has no runtime target are hand-authored by definition, which is the second-authority failure this rule exists to prevent.
43
+
44
+ ## Conflict, legacy, and drift
45
+
46
+ - **Conflict** — a present plan that disagrees with the recomputed plan **fails**; the flow never silently picks a side. The remediation is always to correct the environment, never to edit the branches.
47
+ - **Legacy** — an item written before this rule has no plan. At claim time the implementing agent derives it, **writes the assumption onto the item as a comment**, and proceeds. Never a silent guess.
48
+ - **Drift** — config changed after the plan was rendered. Current config wins; the stale plan is re-rendered and never followed.
49
+
50
+ Full derivation table, gate S19 semantics, the claim-time arms, and the vendor rendering details: [reference/derived-branch-plan.md](derived-branch-plan-reference.mdc).
@@ -48,6 +48,7 @@ Walk the markdown body and capture each top-level `## ` section by name. Standar
48
48
  - `Acceptance Criteria` (preserve the Gherkin code-fence verbatim)
49
49
  - `Out of Scope`
50
50
  - `Target Backend Environment`
51
+ - `Branch Plan` (derived output per `derived-branch-plan` — parsed so callers can *compare* it against a recomputation, never so they can use it as the base branch)
51
52
  - `Sign-in Required`
52
53
  - `Repository`
53
54
  - `Source Artifacts`
@@ -98,6 +98,7 @@ Per-type content requirements are defined once in the vendor-neutral `work-item-
98
98
  | S16 Source Requirement traceability | `product-clarity` | true |
99
99
  | S17 Improvement measurability | `acceptance-criteria` | true |
100
100
  | S18 Stateless-pickup dry-run | `product-clarity` | true |
101
+ | S19 Branch Plan derivation | `technical` | false |
101
102
  | F1 Issue type label exists in repo | `structural` | false |
102
103
  | F2 Parent sub-issue exists and is the right type | `structural` | false |
103
104
  | F3 Linked issues exist | `structural` | false |
@@ -299,6 +300,26 @@ The autonomy gate, run last, on every build-ready leaf (use the S15 classificati
299
300
 
300
301
  Zero questions → PASS. Any question → FAIL, with each question listed verbatim as its own remediation line — these are exactly the clarifying comments the caller posts to the source. The structure gates are proxies; this gate checks the readiness property itself: `ready` means a stateless agent can drive this item to its terminal state with zero human clarification (see `work-item-definition-of-ready`).
301
302
 
303
+ #### S19 — Branch Plan derivation
304
+
305
+ Enforces the `derived-branch-plan` rule: the `## Branch Plan` section is **derived only** — recompute it from current config and compare; never trust the rendered branches or read them as input. Resolve the environment under the S8 grammar, map that exact configured key forward through `.lisa.config.json` `deploy.branches`, and require the mapped branch on the remote.
306
+
307
+ | Case | Verdict |
308
+ |---|---|
309
+ | `runtime_behavior_change = false` (doc-only / config-only / type-only) or an Epic/container, with no plan | `N/A` — absence is correct; never demand one |
310
+ | Exempt work **carrying** a `## Branch Plan` | **FAIL** — hand-authored branches on work that declared no runtime target |
311
+ | Plan matches the recomputed plan | PASS |
312
+ | Plan conflicts with the recomputed plan | **FAIL** |
313
+ | Plan missing the `Derived from:` provenance line and disagreeing | **FAIL** — treated as hand-authored |
314
+ | `Branch from` and `PR into` name two different branches | **FAIL** — malformed; they are the same branch by construction |
315
+ | Derivation hits a stop condition (env absent from `deploy.branches`, ambiguous / non-unique mapping, branch missing on the remote) | **FAIL** — the same stop `lisa-implement` takes; never default to `main` or the remote default |
316
+ | Proposed spec (pre-write) for applicable work with no plan | **FAIL** — `lisa-github-write-issue` must render it before the write |
317
+ | Live **legacy** issue for applicable work with no plan | `N/A` with a repair note — routed to claim time, where `lisa-implement` writes the derived assumption as a comment and proceeds |
318
+
319
+ Failing a proposed spec is free; failing every existing issue would turn a legacy queue red for a section no human had a way to add, so legacy absence is repaired at claim time instead.
320
+
321
+ FAIL names both plans (rendered and recomputed) and points the remediation at **the environment, never the branch** — e.g. `"Branch Plan conflicts with the environment mapping. Rendered 'Branch from: release/staging'; recomputed from Target Backend Environment 'production' via deploy.branches → 'main'. Correct the environment, not the branch — the branches are derived. Then re-render."` Never silently choose between the two plans.
322
+
302
323
  ### Feasibility Gates (require GitHub lookups; skip in `--spec-only`)
303
324
 
304
325
  #### F1 — Issue type label exists in repo
@@ -455,6 +476,7 @@ Output is a single fenced text block. Callers parse it; do not add free-form pro
455
476
  - [PASS|FAIL|N/A] S16 Source Requirement traceability — <one-line reason>
456
477
  - [PASS|FAIL|N/A] S17 Improvement measurability — <one-line reason>
457
478
  - [PASS|FAIL|N/A] S18 Stateless-pickup dry-run — <one-line reason>
479
+ - [PASS|FAIL|N/A] S19 Branch Plan derivation — <one-line reason>
458
480
 
459
481
  ### Feasibility Gates (omit this section when --spec-only)
460
482
  - [PASS|FAIL|N/A] F1 Issue type label exists in repo — <one-line reason>
@@ -100,6 +100,21 @@ Scenario: <name>
100
100
  Human confirmation replaces the automated annotation with a bare key or
101
101
  `Confirmed: <env>`. Skip only for doc/config/type-only issues.]
102
102
 
103
+ ## Branch Plan
104
+ [GENERATED, never hand-authored. Render only when the issue has a Target
105
+ Backend Environment; omit entirely when `runtime_behavior_change = false`
106
+ (doc-only / config-only / type-only) or for an Epic/container — absence is
107
+ correct there. Derive per the `derived-branch-plan` rule: resolve the
108
+ environment, map it forward through `.lisa.config.json` `deploy.branches`,
109
+ and prove the branch exists on the remote. Do not accept caller-supplied
110
+ branches; recompute them. Exactly three lines:
111
+ Branch from: <branch>
112
+ PR into: <branch>
113
+ Derived from: Target Backend Environment <env> via .lisa.config.json deploy.branches
114
+ Both fields name the same branch by construction. A missing, ambiguous, or
115
+ non-unique mapping, or a branch absent from the remote, STOPS the write —
116
+ never default to `main` or the remote default to keep the write alive.]
117
+
103
118
  ## Sign-in Required
104
119
  [Include this section ONLY if the work touches authenticated surfaces.
105
120
  Specify: the account/role, where to get the credentials (1Password item,
@@ -107,6 +107,12 @@ Using the general-purpose agent in Team Lead session, **determine the base branc
107
107
  - The only normalization is built-in `prod` ↔ `production`, and only when exactly one of those keys exists in `deploy.branches`; normalize to that configured key. No other aliases exist.
108
108
  - Never infer from arbitrary branch text, URL paths or query strings, or substrings inside other words or hostname labels. Multiple conflicting signals after normalization **stop** the flow. If there are no signals, resolve the remote default branch (`gh repo view --json defaultBranchRef -q .defaultBranchRef.name`, or `git remote set-head origin -a` then `origin/HEAD`). When it reverse-maps uniquely, write the env-bearing `Assumption:` form; when the reverse-map is not unique, write the branch-only form and continue on the remote default without inventing an environment or blocking solely for that ambiguity. Record the fallback assumption in the plan/tracker artifact.
109
109
  2. **Map the resolved environment to a base branch** through `.lisa.config.json` `deploy.branches` — the forward direction of the env-keyed `done` resolution. The selected exact configured key must map uniquely, and the mapped branch must exist on the remote. A missing/ambiguous mapping or remote branch **stops** the flow; never guess or silently fall back.
110
+ - **Reconcile the ticket's `## Branch Plan` (`derived-branch-plan` rule).** The rendered plan is derived output, never input: **recompute** it here from current config and the remote — the mapping you just resolved — and compare. Four arms, no fifth:
111
+ - **Match** → proceed.
112
+ - **Legacy (no plan)** → derive it, **write the assumption onto the ticket as a comment**, then proceed. Visible prose plus a dedupe marker, e.g. ``Branch plan derived for this item: branch from `main`, PR into `main` (Target Backend Environment: production via .lisa.config.json deploy.branches).`` followed by `<!-- [lisa-branch-plan] key=<work-item-ref>::<branch> -->` (marker-dedupe on `<work-item-ref>::<branch>`, so a re-claim adds no duplicate; where a vendor cannot host an HTML comment the visible line alone carries it). **No silent guess** — if the comment cannot be written, that is a stop, because proceeding would make the inference invisible.
113
+ - **Conflict with a human-confirmed environment, or with an existing open PR's base** → **stop under the existing confirmation rules** below. A branch plan never overrides the environment and never supplies the confirmation itself.
114
+ - **Stale (config changed since the plan was rendered)** → current config wins: re-render the section onto the ticket, record the change, and never follow the stale plan. Staleness is output falling behind its input, not a conflict to escalate.
115
+ - Exempt work carries no plan and needs none: `runtime_behavior_change = false` (doc-only / config-only / type-only) and containers have no `## Target Backend Environment` to derive from, so **absence is correct** — never demand or invent one.
110
116
  3. **Establish the feature branch off the latest base, conflict-free:**
111
117
  - `git fetch origin`.
112
118
  - Already on a feature branch with an **open PR** → reuse it. If the PR's base ≠ the resolved base branch, surface the mismatch and re-target only with confirmation — the ticket's environment is the source of truth.