@shinnodua/agent-workflows 0.0.0-stage → 0.2.8

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 (190) hide show
  1. package/.agents/agents/backend-developer/agent.md +39 -0
  2. package/.agents/agents/frontend-developer/agent.md +42 -0
  3. package/.agents/agents/project-manager/agent.md +37 -0
  4. package/.agents/agents/tech-lead/agent.md +41 -0
  5. package/.agents/agents/ui-ux-designer/agent.md +41 -0
  6. package/.agents/skills/add-project/SKILL.md +90 -0
  7. package/.agents/skills/add-project/agents/openai.yaml +4 -0
  8. package/.agents/skills/add-project/references/save-protocol.md +90 -0
  9. package/.agents/skills/approve-plan/SKILL.md +86 -0
  10. package/.agents/skills/approve-plan/agents/openai.yaml +4 -0
  11. package/.agents/skills/approve-prd/SKILL.md +59 -0
  12. package/.agents/skills/approve-prd/agents/openai.yaml +4 -0
  13. package/.agents/skills/auto-mode/SKILL.md +103 -0
  14. package/.agents/skills/auto-mode/agents/openai.yaml +4 -0
  15. package/.agents/skills/create-design/SKILL.md +197 -0
  16. package/.agents/skills/create-design/agents/openai.yaml +4 -0
  17. package/.agents/skills/create-diagram/SKILL.md +83 -0
  18. package/.agents/skills/create-diagram/agents/openai.yaml +4 -0
  19. package/.agents/skills/create-plan/SKILL.md +104 -0
  20. package/.agents/skills/create-plan/agents/openai.yaml +4 -0
  21. package/.agents/skills/create-prd/SKILL.md +82 -0
  22. package/.agents/skills/create-prd/agents/openai.yaml +4 -0
  23. package/.agents/skills/griling-plan/SKILL.md +114 -0
  24. package/.agents/skills/griling-plan/agents/openai.yaml +4 -0
  25. package/.agents/skills/griling-prd/SKILL.md +91 -0
  26. package/.agents/skills/griling-prd/agents/openai.yaml +4 -0
  27. package/.agents/skills/package-installation/SKILL.md +67 -0
  28. package/.agents/skills/package-installation/agents/openai.yaml +4 -0
  29. package/.agents/skills/project-setup/SKILL.md +104 -0
  30. package/.agents/skills/project-setup/agents/openai.yaml +3 -0
  31. package/.agents/skills/research/SKILL.md +61 -0
  32. package/.agents/skills/research/agents/openai.yaml +4 -0
  33. package/.agents/skills/sprint-meeting/SKILL.md +230 -0
  34. package/.agents/skills/sprint-meeting/agents/openai.yaml +4 -0
  35. package/.claude/agents/backend-developer.md +7 -0
  36. package/.claude/agents/frontend-developer.md +7 -0
  37. package/.claude/agents/project-manager.md +7 -0
  38. package/.claude/agents/tech-lead.md +7 -0
  39. package/.claude/agents/ui-ux-designer.md +7 -0
  40. package/.claude/skills/add-project/SKILL.md +10 -0
  41. package/.claude/skills/approve-plan/SKILL.md +8 -0
  42. package/.claude/skills/approve-prd/SKILL.md +8 -0
  43. package/.claude/skills/auto-mode/SKILL.md +8 -0
  44. package/.claude/skills/create-design/SKILL.md +8 -0
  45. package/.claude/skills/create-diagram/SKILL.md +8 -0
  46. package/.claude/skills/create-plan/SKILL.md +8 -0
  47. package/.claude/skills/create-prd/SKILL.md +8 -0
  48. package/.claude/skills/griling-plan/SKILL.md +8 -0
  49. package/.claude/skills/griling-prd/SKILL.md +8 -0
  50. package/.claude/skills/package-installation/SKILL.md +8 -0
  51. package/.claude/skills/project-setup/SKILL.md +8 -0
  52. package/.claude/skills/research/SKILL.md +8 -0
  53. package/.claude/skills/sprint-meeting/SKILL.md +8 -0
  54. package/.codex/prompts/add-project.md +3 -0
  55. package/.codex/prompts/approve-plan.md +3 -0
  56. package/.codex/prompts/approve-prd.md +3 -0
  57. package/.codex/prompts/auto-mode.md +3 -0
  58. package/.codex/prompts/create-design.md +3 -0
  59. package/.codex/prompts/create-diagram.md +3 -0
  60. package/.codex/prompts/create-plan.md +3 -0
  61. package/.codex/prompts/create-prd.md +3 -0
  62. package/.codex/prompts/griling-plan.md +3 -0
  63. package/.codex/prompts/griling-prd.md +3 -0
  64. package/.codex/prompts/grilling-plan.md +3 -0
  65. package/.codex/prompts/project-setup.md +3 -0
  66. package/.codex/prompts/research.md +3 -0
  67. package/.codex/prompts/sprint-meeting.md +3 -0
  68. package/.gitmodules.example +9 -0
  69. package/AGENTS.md +84 -0
  70. package/CLAUDE.md +1 -0
  71. package/INSTALL.md +284 -0
  72. package/LICENSE +21 -0
  73. package/README.md +342 -2
  74. package/bin/postinstall.js +57 -0
  75. package/bin/workflows.js +1172 -0
  76. package/bin/workflows.test.mjs +682 -0
  77. package/commands/add-project.md +20 -0
  78. package/commands/approve-plan.md +25 -0
  79. package/commands/approve-prd.md +24 -0
  80. package/commands/auto-mode.md +15 -0
  81. package/commands/create-design.md +20 -0
  82. package/commands/create-diagram.md +16 -0
  83. package/commands/create-plan.md +22 -0
  84. package/commands/create-prd.md +16 -0
  85. package/commands/griling-plan.md +16 -0
  86. package/commands/griling-prd.md +16 -0
  87. package/commands/grilling-plan.md +16 -0
  88. package/commands/project-setup.md +16 -0
  89. package/commands/research.md +16 -0
  90. package/commands/sprint-meeting.md +16 -0
  91. package/dashboard/.agents/skills/coding-conventions/SKILL.md +76 -0
  92. package/dashboard/.agents/skills/coding-conventions/agents/openai.yaml +4 -0
  93. package/dashboard/.agents/skills/design-system-guideline/SKILL.md +51 -0
  94. package/dashboard/.agents/skills/design-system-guideline/agents/openai.yaml +4 -0
  95. package/dashboard/.agents/skills/lint-and-fix/SKILL.md +55 -0
  96. package/dashboard/.agents/skills/lint-and-fix/agents/openai.yaml +4 -0
  97. package/dashboard/.agents/skills/taste-ui/SKILL.md +45 -0
  98. package/dashboard/.agents/skills/taste-ui/agents/openai.yaml +4 -0
  99. package/dashboard/AGENTS.md +43 -0
  100. package/dashboard/bun.lock +352 -0
  101. package/dashboard/index.html +12 -0
  102. package/dashboard/package.json +32 -0
  103. package/dashboard/src/App.tsx +5 -0
  104. package/dashboard/src/features/task-status/components/ActionRequiredPanel/ActionRequiredPanel.module.css +85 -0
  105. package/dashboard/src/features/task-status/components/ActionRequiredPanel/ActionRequiredPanel.tsx +80 -0
  106. package/dashboard/src/features/task-status/components/ArtifactButton/ArtifactButton.module.css +25 -0
  107. package/dashboard/src/features/task-status/components/ArtifactButton/ArtifactButton.tsx +29 -0
  108. package/dashboard/src/features/task-status/components/ArtifactSummaryCards/ArtifactSummaryCards.module.css +29 -0
  109. package/dashboard/src/features/task-status/components/ArtifactSummaryCards/ArtifactSummaryCards.tsx +35 -0
  110. package/dashboard/src/features/task-status/components/CategoryPanel/CategoryPanel.module.css +85 -0
  111. package/dashboard/src/features/task-status/components/CategoryPanel/CategoryPanel.tsx +150 -0
  112. package/dashboard/src/features/task-status/components/DashboardHeader/DashboardHeader.module.css +41 -0
  113. package/dashboard/src/features/task-status/components/DashboardHeader/DashboardHeader.tsx +41 -0
  114. package/dashboard/src/features/task-status/components/FilesPanel/FilesPanel.module.css +25 -0
  115. package/dashboard/src/features/task-status/components/FilesPanel/FilesPanel.tsx +40 -0
  116. package/dashboard/src/features/task-status/components/HardnessEngineeringPanel/HardnessEngineeringPanel.module.css +330 -0
  117. package/dashboard/src/features/task-status/components/HardnessEngineeringPanel/HardnessEngineeringPanel.tsx +299 -0
  118. package/dashboard/src/features/task-status/components/LifecyclePanel/LifecyclePanel.module.css +74 -0
  119. package/dashboard/src/features/task-status/components/LifecyclePanel/LifecyclePanel.tsx +79 -0
  120. package/dashboard/src/features/task-status/components/MarkdownDialog/MarkdownDialog.module.css +133 -0
  121. package/dashboard/src/features/task-status/components/MarkdownDialog/MarkdownDialog.tsx +233 -0
  122. package/dashboard/src/features/task-status/components/Sidebar/Sidebar.module.css +53 -0
  123. package/dashboard/src/features/task-status/components/Sidebar/Sidebar.tsx +163 -0
  124. package/dashboard/src/features/task-status/components/StatusBadge/StatusBadge.module.css +41 -0
  125. package/dashboard/src/features/task-status/components/StatusBadge/StatusBadge.tsx +48 -0
  126. package/dashboard/src/features/task-status/components/TaskOverview/TaskOverview.module.css +97 -0
  127. package/dashboard/src/features/task-status/components/TaskOverview/TaskOverview.tsx +128 -0
  128. package/dashboard/src/features/task-status/components/TaskStatusDashboard/TaskStatusDashboard.module.css +9 -0
  129. package/dashboard/src/features/task-status/components/TaskStatusDashboard/TaskStatusDashboard.tsx +318 -0
  130. package/dashboard/src/features/task-status/components/WorkflowPanel/WorkflowPanel.module.css +221 -0
  131. package/dashboard/src/features/task-status/components/WorkflowPanel/WorkflowPanel.tsx +344 -0
  132. package/dashboard/src/features/task-status/taskStatusConfig.ts +100 -0
  133. package/dashboard/src/features/task-status/utils/actionItems.ts +247 -0
  134. package/dashboard/src/features/task-status/utils/artifactGrouping.ts +328 -0
  135. package/dashboard/src/features/task-status/utils/hardnessScanner.ts +406 -0
  136. package/dashboard/src/features/task-status/utils/lifecycle.ts +73 -0
  137. package/dashboard/src/features/task-status/utils/markdownInline/markdownInline.module.css +11 -0
  138. package/dashboard/src/features/task-status/utils/markdownInline/markdownInline.tsx +104 -0
  139. package/dashboard/src/features/task-status/utils/markdownLinks.ts +83 -0
  140. package/dashboard/src/features/task-status/utils/markdownRenderer/markdownRenderer.module.css +74 -0
  141. package/dashboard/src/features/task-status/utils/markdownRenderer/markdownRenderer.tsx +326 -0
  142. package/dashboard/src/features/task-status/utils/status.ts +7 -0
  143. package/dashboard/src/features/task-status/utils/test/actionItems.test.ts +134 -0
  144. package/dashboard/src/features/task-status/utils/test/artifactGrouping.test.ts +294 -0
  145. package/dashboard/src/features/task-status/utils/test/hardnessScanner.test.ts +138 -0
  146. package/dashboard/src/features/task-status/utils/test/lifecycle.test.ts +49 -0
  147. package/dashboard/src/features/task-status/utils/test/markdownInline.test.ts +41 -0
  148. package/dashboard/src/features/task-status/utils/test/markdownLinks.test.ts +158 -0
  149. package/dashboard/src/features/task-status/utils/test/workspaceMetadata.test.ts +37 -0
  150. package/dashboard/src/features/task-status/utils/workspaceMetadata.ts +175 -0
  151. package/dashboard/src/main.tsx +16 -0
  152. package/dashboard/src/shared/design-system.css +134 -0
  153. package/dashboard/src/shared/design-system.tsx +84 -0
  154. package/dashboard/src/styles.css +41 -0
  155. package/dashboard/src/types.ts +133 -0
  156. package/dashboard/src/workspace-artifacts.d.ts +9 -0
  157. package/dashboard/tsconfig.json +22 -0
  158. package/dashboard/vite.config.ts +579 -0
  159. package/designs/.gitkeep +1 -0
  160. package/docs/add-project-command-completion.md +117 -0
  161. package/docs/public-npm-registry-completion.md +104 -0
  162. package/docs/workflows.png +0 -0
  163. package/docs/workspace-template-setup.md +229 -0
  164. package/meeting-logs/.gitkeep +1 -0
  165. package/modules/.gitkeep +1 -0
  166. package/package.json +96 -5
  167. package/plans/.gitkeep +1 -0
  168. package/prds/.gitkeep +1 -0
  169. package/project/PROJECT.md +26 -0
  170. package/project/repositories.json +72 -0
  171. package/project/validation.json +9 -0
  172. package/project/workflows.json +20 -0
  173. package/research/.gitkeep +1 -0
  174. package/roles/backend-developer.md +26 -0
  175. package/roles/frontend-developer.md +25 -0
  176. package/roles/project-manager.md +42 -0
  177. package/roles/tech-lead.md +42 -0
  178. package/roles/ui-ux-designer.md +43 -0
  179. package/scripts/add-project.mjs +990 -0
  180. package/scripts/add-project.test.mjs +804 -0
  181. package/scripts/check-staged-security.mjs +97 -0
  182. package/scripts/check-staged-security.test.mjs +68 -0
  183. package/scripts/workspace-integrity.ts +220 -0
  184. package/templates/auto-mode-completion-summary-template.md +78 -0
  185. package/templates/meeting-log-template.md +177 -0
  186. package/templates/plan-template.md +219 -0
  187. package/templates/prd-template.md +106 -0
  188. package/templates/research-template.md +119 -0
  189. package/workflows.md +590 -0
  190. package/workspace.config.json +43 -0
@@ -0,0 +1,804 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import fs from "node:fs";
4
+ import os from "node:os";
5
+ import path from "node:path";
6
+ import { afterEach, test } from "node:test";
7
+ import { normalizeUrl, preview, save } from "./add-project.mjs";
8
+
9
+ const temporary = [];
10
+ const options = { allowLocal: true };
11
+ const template = JSON.parse(
12
+ fs.readFileSync(
13
+ new URL("../project/repositories.json", import.meta.url),
14
+ "utf8",
15
+ ),
16
+ );
17
+ const workflowTemplate = JSON.parse(
18
+ fs.readFileSync(
19
+ new URL("../project/workflows.json", import.meta.url),
20
+ "utf8",
21
+ ),
22
+ );
23
+ function git(root, ...args) {
24
+ const environment = { ...process.env };
25
+ for (const name of [
26
+ "GIT_DIR",
27
+ "GIT_WORK_TREE",
28
+ "GIT_INDEX_FILE",
29
+ "GIT_COMMON_DIR",
30
+ "GIT_OBJECT_DIRECTORY",
31
+ "GIT_ALTERNATE_OBJECT_DIRECTORIES",
32
+ "GIT_PREFIX",
33
+ "GIT_SHALLOW_FILE",
34
+ "GIT_GRAFT_FILE",
35
+ "GIT_IMPLICIT_WORK_TREE",
36
+ ])
37
+ delete environment[name];
38
+ const result = spawnSync(
39
+ "git",
40
+ [
41
+ "-c",
42
+ "core.hooksPath=/dev/null",
43
+ "-c",
44
+ "user.name=Fixture",
45
+ "-c",
46
+ "user.email=fixture@example.com",
47
+ ...args,
48
+ ],
49
+ { cwd: root, encoding: "utf8", env: environment },
50
+ );
51
+ assert.equal(result.status, 0, result.stderr);
52
+ return result.stdout.trim();
53
+ }
54
+ function fixture({ examples = true } = {}) {
55
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "add-project-test-"));
56
+ temporary.push(dir);
57
+ const root = path.join(dir, "workspace");
58
+ fs.mkdirSync(path.join(root, "project"), { recursive: true });
59
+ git(root, "init", "-q");
60
+ fs.writeFileSync(
61
+ path.join(root, "project/repositories.json"),
62
+ JSON.stringify(examples ? template : { repositories: [] }, null, "\t") +
63
+ "\n",
64
+ );
65
+ fs.writeFileSync(
66
+ path.join(root, "project/workflows.json"),
67
+ `${JSON.stringify(
68
+ examples ? workflowTemplate : { implementationStages: [] },
69
+ null,
70
+ "\t",
71
+ )}\n`,
72
+ );
73
+ fs.writeFileSync(
74
+ path.join(root, ".gitmodules"),
75
+ examples
76
+ ? fs.readFileSync(
77
+ new URL("../.gitmodules.example", import.meta.url),
78
+ "utf8",
79
+ )
80
+ : "",
81
+ );
82
+ fs.writeFileSync(path.join(root, "notes"), "baseline\n");
83
+ git(root, "add", ".");
84
+ git(root, "commit", "-qm", "fixture");
85
+ function remote(id) {
86
+ const location = path.join(dir, id);
87
+ fs.mkdirSync(location);
88
+ git(location, "init", "-q");
89
+ fs.writeFileSync(path.join(location, "README.md"), id);
90
+ git(location, "add", ".");
91
+ git(location, "commit", "-qm", "fixture");
92
+ return location;
93
+ }
94
+ function entry(id = "alpha", url = remote(id)) {
95
+ const local = `modules/${id}`;
96
+ return {
97
+ id,
98
+ name: id,
99
+ path: local,
100
+ url,
101
+ purpose: "Test repository",
102
+ scope: ["logic"],
103
+ platforms: ["backend"],
104
+ agentGuide: `${local}/AGENTS.md`,
105
+ artifactDirectories: Object.fromEntries(
106
+ ["plans", "designs", "research", "docs"].map((key) => [
107
+ key,
108
+ `${local}/${key}`,
109
+ ]),
110
+ ),
111
+ codeScanDirectories: [],
112
+ validation: [],
113
+ };
114
+ }
115
+ const read = (file) => fs.readFileSync(path.join(root, file), "utf8");
116
+ const write = (file, value) =>
117
+ fs.writeFileSync(
118
+ path.join(root, file),
119
+ typeof value === "string"
120
+ ? value
121
+ : `${JSON.stringify(value, null, "\t")}\n`,
122
+ );
123
+ return { root, dir, remote, entry, read, write };
124
+ }
125
+ function reviewed(root, entries, extra = {}) {
126
+ const request = { entries, ...extra };
127
+ const result = preview(root, request, options);
128
+ assert.equal(result.status, "preview", result.error);
129
+ return { ...request, token: result.token };
130
+ }
131
+ afterEach(() => {
132
+ for (const dir of temporary.splice(0))
133
+ fs.rmSync(dir, { recursive: true, force: true });
134
+ });
135
+
136
+ test("preview and empty Save leave configuration, Git index, and examples untouched", () => {
137
+ const f = fixture();
138
+ const entry = f.entry();
139
+ const before = git(f.root, "status", "--porcelain=v1");
140
+ const result = preview(f.root, { entries: [entry] }, options);
141
+ assert.equal(result.status, "preview");
142
+ assert.equal(result.effects.removeExamples.length, 3);
143
+ assert.equal(fs.existsSync(path.join(f.root, entry.path)), false);
144
+ assert.equal(save(f.root, { entries: [] }, options).status, "empty");
145
+ assert.equal(git(f.root, "status", "--porcelain=v1"), before);
146
+ assert.equal(
147
+ JSON.parse(f.read("project/repositories.json")).repositories.length,
148
+ 3,
149
+ );
150
+ });
151
+
152
+ test("multi-add clones, registers real submodules, reports revisions and removes exact examples", () => {
153
+ const f = fixture();
154
+ const entries = [f.entry("alpha"), f.entry("beta")];
155
+ const result = save(f.root, reviewed(f.root, entries), options);
156
+ assert.equal(result.status, "saved", result.error);
157
+ assert.deepEqual(
158
+ result.repositories.map((state) => state.state),
159
+ ["registered", "registered"],
160
+ );
161
+ for (const entry of entries) {
162
+ const revision = git(path.join(f.root, entry.path), "rev-parse", "HEAD");
163
+ assert.match(
164
+ git(f.root, "ls-files", "--stage", "--", entry.path),
165
+ new RegExp(`160000 ${revision}`),
166
+ );
167
+ assert.equal(
168
+ git(
169
+ f.root,
170
+ "config",
171
+ "--file",
172
+ ".gitmodules",
173
+ "--get",
174
+ `submodule.${entry.path}.url`,
175
+ ),
176
+ entry.url,
177
+ );
178
+ assert.match(
179
+ git(f.root, "submodule", "status", "--", entry.path),
180
+ new RegExp(revision),
181
+ );
182
+ }
183
+ assert.deepEqual(
184
+ JSON.parse(f.read("project/repositories.json")).repositories,
185
+ entries,
186
+ );
187
+ assert.deepEqual(
188
+ JSON.parse(f.read("project/workflows.json")).implementationStages,
189
+ [],
190
+ );
191
+ assert.doesNotMatch(f.read(".gitmodules"), /example-/);
192
+ assert.equal(git(f.root, "rev-list", "--count", "HEAD"), "1");
193
+ assert.equal(
194
+ save(f.root, reviewed(f.root, entries), options).status,
195
+ "saved",
196
+ );
197
+ });
198
+
199
+ test("unrelated staged and unstaged changes, including mixed .gitmodules, survive", () => {
200
+ const f = fixture({ examples: false });
201
+ const entry = f.entry();
202
+ f.write("notes", "staged\n");
203
+ git(f.root, "add", "notes");
204
+ f.write("notes", "working\n");
205
+ f.write(".gitmodules", "# staged comment\n[custom]\n\tkeep = staged\n");
206
+ git(f.root, "add", ".gitmodules");
207
+ f.write(".gitmodules", "# working comment\n[custom]\n\tkeep = working\n");
208
+ const result = save(f.root, reviewed(f.root, [entry]), options);
209
+ assert.equal(result.status, "saved", result.error);
210
+ assert.equal(git(f.root, "show", ":notes"), "staged");
211
+ assert.equal(f.read("notes"), "working\n");
212
+ assert.match(git(f.root, "show", ":.gitmodules"), /keep = staged/);
213
+ assert.doesNotMatch(git(f.root, "show", ":.gitmodules"), /working comment/);
214
+ assert.match(f.read(".gitmodules"), /keep = working/);
215
+ assert.match(git(f.root, "show", ":.gitmodules"), /modules\/alpha/);
216
+ });
217
+
218
+ test("B failure keeps A registered and examples; fresh preview retries only missing B", () => {
219
+ const f = fixture();
220
+ const first = f.entry();
221
+ const missing = path.join(f.dir, "later");
222
+ const second = f.entry("beta", missing);
223
+ const result = save(f.root, reviewed(f.root, [first, second]), options);
224
+ assert.equal(result.status, "incomplete");
225
+ assert.equal(result.repositories[0].state, "registered");
226
+ assert.equal(result.repositories[1].state, "failed");
227
+ assert.equal(
228
+ JSON.parse(f.read("project/repositories.json")).repositories.length,
229
+ 3,
230
+ );
231
+ assert.match(f.read(".gitmodules"), /example-core/);
232
+ f.remote("later");
233
+ const before = git(path.join(f.root, first.path), "rev-parse", "HEAD");
234
+ const retry = save(f.root, reviewed(f.root, [first, second]), options);
235
+ assert.equal(retry.status, "saved", retry.error);
236
+ assert.equal(git(path.join(f.root, first.path), "rev-parse", "HEAD"), before);
237
+ assert.equal(f.read(".gitmodules").match(/path = modules\/alpha/g).length, 1);
238
+ });
239
+
240
+ test("failure after clone keeps an owned checkout that can finish registration on retry", () => {
241
+ const f = fixture();
242
+ const entry = f.entry();
243
+ const result = save(f.root, reviewed(f.root, [entry]), {
244
+ ...options,
245
+ beforeRegister() {
246
+ throw new Error("Injected registration failure");
247
+ },
248
+ });
249
+ assert.equal(result.status, "incomplete");
250
+ assert.equal(result.repositories[0].state, "checkout-ready");
251
+ assert.equal(
252
+ save(f.root, reviewed(f.root, [entry]), options).status,
253
+ "saved",
254
+ );
255
+ });
256
+
257
+ test("materially changed cleanup returns a revised preview without cloning or overwriting edits", () => {
258
+ const f = fixture();
259
+ const entry = f.entry();
260
+ const request = reviewed(f.root, [entry]);
261
+ const config = JSON.parse(f.read("project/repositories.json"));
262
+ config.custom = "intervening";
263
+ config.repositories[0].purpose = "A retained real repository";
264
+ f.write("project/repositories.json", config);
265
+ const result = save(f.root, request, options);
266
+ assert.equal(result.status, "conflict");
267
+ assert.equal(result.preview.status, "preview");
268
+ assert.equal(fs.existsSync(path.join(f.root, entry.path)), false);
269
+ assert.equal(
270
+ save(f.root, { ...request, token: result.preview.token }, options).status,
271
+ "saved",
272
+ );
273
+ assert.equal(
274
+ JSON.parse(f.read("project/repositories.json")).custom,
275
+ "intervening",
276
+ );
277
+ });
278
+
279
+ test("write failure restores only owned JSON and retains examples and successful registrations", () => {
280
+ const f = fixture();
281
+ const entry = f.entry();
282
+ const original = f.read("project/workflows.json");
283
+ const result = save(f.root, reviewed(f.root, [entry]), {
284
+ ...options,
285
+ beforeWrite(file) {
286
+ if (file === "project/repositories.json")
287
+ throw new Error("Injected write failure");
288
+ },
289
+ });
290
+ assert.equal(result.status, "incomplete");
291
+ assert.equal(f.read("project/workflows.json"), original);
292
+ assert.equal(
293
+ JSON.parse(f.read("project/repositories.json")).repositories.length,
294
+ 3,
295
+ );
296
+ assert.match(f.read(".gitmodules"), /example-core/);
297
+ assert.deepEqual(result.restoredFiles, ["project/workflows.json"]);
298
+ assert.equal(
299
+ save(f.root, reviewed(f.root, [entry]), options).status,
300
+ "saved",
301
+ );
302
+ });
303
+
304
+ test("concurrent newer JSON is never overwritten by failure recovery", () => {
305
+ const f = fixture();
306
+ const entry = f.entry();
307
+ const result = save(f.root, reviewed(f.root, [entry]), {
308
+ ...options,
309
+ beforeWrite(file) {
310
+ if (file === "project/repositories.json") {
311
+ f.write("project/workflows.json", {
312
+ implementationStages: [],
313
+ newer: true,
314
+ });
315
+ throw new Error("Injected");
316
+ }
317
+ },
318
+ });
319
+ assert.equal(result.status, "incomplete");
320
+ assert.equal(JSON.parse(f.read("project/workflows.json")).newer, true);
321
+ assert.deepEqual(result.restoredFiles, []);
322
+ });
323
+
324
+ test("modified examples and custom metadata survive automatic cleanup", () => {
325
+ const f = fixture();
326
+ const profile = JSON.parse(f.read("project/repositories.json"));
327
+ profile.repositories[0].purpose = "My real service";
328
+ profile.repositories[0].custom = true;
329
+ profile.custom = 42;
330
+ f.write("project/repositories.json", profile);
331
+ const result = save(f.root, reviewed(f.root, [f.entry()]), options);
332
+ assert.equal(result.status, "saved", result.error);
333
+ const saved = JSON.parse(f.read("project/repositories.json"));
334
+ assert.equal(saved.custom, 42);
335
+ assert.equal(saved.repositories[0].custom, true);
336
+ assert.equal(saved.repositories.length, 2);
337
+ });
338
+
339
+ test("custom stages require explicit reference decisions and retain their metadata", () => {
340
+ const f = fixture();
341
+ f.write("project/workflows.json", {
342
+ implementationStages: [
343
+ { id: "custom", repositoryIds: ["example-core"], custom: "retain" },
344
+ ],
345
+ custom: true,
346
+ });
347
+ const entry = f.entry();
348
+ assert.equal(
349
+ preview(f.root, { entries: [entry] }, options).status,
350
+ "conflict",
351
+ );
352
+ const request = reviewed(f.root, [entry], {
353
+ workflowReplacements: { "example-core": [entry.id] },
354
+ });
355
+ assert.equal(save(f.root, request, options).status, "saved");
356
+ assert.deepEqual(JSON.parse(f.read("project/workflows.json")), {
357
+ implementationStages: [
358
+ { id: "custom", repositoryIds: [entry.id], custom: "retain" },
359
+ ],
360
+ custom: true,
361
+ });
362
+ });
363
+
364
+ test("duplicate IDs, URLs, and overlapping paths in pending or saved records conflict", () => {
365
+ const f = fixture({ examples: false });
366
+ const a = f.entry();
367
+ const b = f.entry("beta");
368
+ for (const changed of [
369
+ { ...b, id: a.id },
370
+ { ...b, url: a.url },
371
+ { ...b, path: a.path },
372
+ ])
373
+ assert.equal(
374
+ preview(f.root, { entries: [a, changed] }, options).status,
375
+ "conflict",
376
+ );
377
+ assert.equal(
378
+ preview(f.root, { entries: [a, a] }, options).status,
379
+ "conflict",
380
+ );
381
+ assert.equal(save(f.root, reviewed(f.root, [a]), options).status, "saved");
382
+ assert.equal(
383
+ preview(f.root, { entries: [{ ...b, url: a.url }] }, options).status,
384
+ "conflict",
385
+ );
386
+ });
387
+
388
+ test("reject escaping, symlink, nonempty, and tracked-file destinations before mutation", () => {
389
+ const f = fixture({ examples: false });
390
+ const entry = f.entry();
391
+ for (const local of [
392
+ "../outside",
393
+ "modules/../outside",
394
+ "/tmp/outside",
395
+ ".git/evil",
396
+ ])
397
+ assert.equal(
398
+ preview(f.root, { entries: [{ ...entry, path: local }] }, options).status,
399
+ "conflict",
400
+ );
401
+ fs.mkdirSync(path.join(f.root, "modules"));
402
+ fs.symlinkSync(f.dir, path.join(f.root, "modules/link"));
403
+ assert.equal(
404
+ preview(
405
+ f.root,
406
+ { entries: [{ ...entry, path: "modules/link/repo" }] },
407
+ options,
408
+ ).status,
409
+ "conflict",
410
+ );
411
+ fs.mkdirSync(path.join(f.root, entry.path));
412
+ fs.writeFileSync(path.join(f.root, entry.path, "work"), "preserve");
413
+ assert.equal(
414
+ preview(f.root, { entries: [entry] }, options).status,
415
+ "conflict",
416
+ );
417
+ assert.equal(
418
+ fs.readFileSync(path.join(f.root, entry.path, "work"), "utf8"),
419
+ "preserve",
420
+ );
421
+ });
422
+
423
+ test("clean URL canonicalization keeps host and unknown-host path identity; rejects secrets without echo", () => {
424
+ assert.equal(
425
+ normalizeUrl("github.com:Owner/Repo.git"),
426
+ normalizeUrl("https://github.com/owner/repo"),
427
+ );
428
+ assert.equal(
429
+ normalizeUrl("ssh://git@example.com/Owner/Repo.git"),
430
+ normalizeUrl("https://example.com/Owner/Repo"),
431
+ );
432
+ assert.notEqual(
433
+ normalizeUrl("https://a.example/Owner/Repo"),
434
+ normalizeUrl("https://b.example/Owner/Repo"),
435
+ );
436
+ assert.notEqual(
437
+ normalizeUrl("https://a.example/Owner/Repo"),
438
+ normalizeUrl("https://a.example/owner/repo"),
439
+ );
440
+ const f = fixture();
441
+ const entry = f.entry();
442
+ for (const url of [
443
+ "https://token-secret@example.com/owner/repo",
444
+ "ssh://git:token-secret@host/repo",
445
+ "https://host/repo?token=token-secret",
446
+ "ext::token-secret",
447
+ "--upload-pack=token-secret",
448
+ ]) {
449
+ const result = preview(f.root, { entries: [{ ...entry, url }] });
450
+ assert.equal(result.status, "conflict");
451
+ assert.doesNotMatch(JSON.stringify(result), /token-secret/);
452
+ }
453
+ });
454
+
455
+ test("CLI requires an explicit operation and refuses malformed or secret requests safely", () => {
456
+ const f = fixture();
457
+ const script = new URL("./add-project.mjs", import.meta.url).pathname;
458
+ const request = path.join(f.dir, "request.json");
459
+ fs.writeFileSync(request, JSON.stringify({ entries: [] }));
460
+ const empty = spawnSync(
461
+ process.execPath,
462
+ [script, "save", "--root", f.root, "--request", request],
463
+ { encoding: "utf8" },
464
+ );
465
+ assert.equal(empty.status, 0);
466
+ assert.equal(JSON.parse(empty.stdout).status, "empty");
467
+ fs.writeFileSync(request, '{"secret":"should-not-echo"');
468
+ const malformed = spawnSync(
469
+ process.execPath,
470
+ [script, "preview", "--root", f.root, "--request", request],
471
+ { encoding: "utf8" },
472
+ );
473
+ assert.equal(malformed.status, 1);
474
+ assert.doesNotMatch(malformed.stdout, /should-not-echo/);
475
+ });
476
+
477
+ test("malformed and modified template .gitmodules are conflicts, never cleanup candidates", () => {
478
+ const f = fixture();
479
+ const entry = f.entry();
480
+ f.write(".gitmodules", "[broken\n");
481
+ assert.equal(
482
+ preview(f.root, { entries: [entry] }, options).status,
483
+ "conflict",
484
+ );
485
+ f.write(
486
+ ".gitmodules",
487
+ fs.readFileSync(new URL("../.gitmodules.example", import.meta.url), "utf8"),
488
+ );
489
+ git(
490
+ f.root,
491
+ "config",
492
+ "--file",
493
+ ".gitmodules",
494
+ "submodule.modules/example-core.branch",
495
+ "custom",
496
+ );
497
+ assert.equal(
498
+ preview(f.root, { entries: [entry] }, options).status,
499
+ "conflict",
500
+ );
501
+ assert.match(f.read(".gitmodules"), /branch = custom/);
502
+ });
503
+
504
+ test("empty preview proposes no formatting writes and optional arrays remain honest", () => {
505
+ const f = fixture({ examples: false });
506
+ f.write("project/repositories.json", '{"repositories":[]}');
507
+ const result = preview(f.root, { entries: [] }, options);
508
+ assert.equal(result.status, "preview");
509
+ assert.deepEqual(result.effects.files, []);
510
+ assert.deepEqual(result.effects.index, []);
511
+ assert.deepEqual(result.effects.removeExamples, []);
512
+ const entry = f.entry();
513
+ entry.artifactDirectories.custom = 1;
514
+ assert.equal(
515
+ preview(f.root, { entries: [entry] }, options).status,
516
+ "conflict",
517
+ );
518
+ });
519
+
520
+ test("mixed index blob whitespace is preserved exactly outside newly appended registrations", () => {
521
+ const f = fixture({ examples: false });
522
+ const original = "# staged trailing text\n\n\n";
523
+ f.write(".gitmodules", original);
524
+ git(f.root, "add", ".gitmodules");
525
+ f.write(".gitmodules", "# work only\n");
526
+ const entry = f.entry();
527
+ assert.equal(
528
+ save(f.root, reviewed(f.root, [entry]), options).status,
529
+ "saved",
530
+ );
531
+ const result = spawnSync("git", ["show", ":.gitmodules"], {
532
+ cwd: f.root,
533
+ encoding: "utf8",
534
+ });
535
+ assert.ok(result.stdout.startsWith(original));
536
+ assert.ok(f.read(".gitmodules").startsWith("# work only\n"));
537
+ });
538
+
539
+ test("final cleanup index conflict restores template references and JSON without overwriting new index work", () => {
540
+ const f = fixture();
541
+ const entry = f.entry();
542
+ const result = save(f.root, reviewed(f.root, [entry]), {
543
+ ...options,
544
+ beforeWrite(file) {
545
+ if (file !== ".gitmodules") return;
546
+ const staged = spawnSync("git", ["show", ":.gitmodules"], {
547
+ cwd: f.root,
548
+ encoding: "utf8",
549
+ }).stdout;
550
+ const object = spawnSync("git", ["hash-object", "-w", "--stdin"], {
551
+ cwd: f.root,
552
+ input: `${staged}# concurrent index\n`,
553
+ encoding: "utf8",
554
+ }).stdout.trim();
555
+ git(
556
+ f.root,
557
+ "update-index",
558
+ "--cacheinfo",
559
+ `100644,${object},.gitmodules`,
560
+ );
561
+ },
562
+ });
563
+ assert.equal(result.status, "incomplete");
564
+ assert.match(f.read(".gitmodules"), /example-core/);
565
+ assert.match(git(f.root, "show", ":.gitmodules"), /concurrent index/);
566
+ assert.equal(
567
+ JSON.parse(f.read("project/repositories.json")).repositories.length,
568
+ 3,
569
+ );
570
+ assert.equal(result.repositories[0].state, "registered");
571
+ });
572
+
573
+ test("concurrent metadata changes during cloning stop registration and preserve the checkout", () => {
574
+ const f = fixture();
575
+ const entry = f.entry();
576
+ const result = save(f.root, reviewed(f.root, [entry]), {
577
+ ...options,
578
+ beforeRegister() {
579
+ f.write(".gitmodules", `${f.read(".gitmodules")}# concurrent work\n`);
580
+ },
581
+ });
582
+ assert.equal(result.status, "incomplete");
583
+ assert.equal(result.repositories[0].state, "checkout-ready");
584
+ assert.match(f.read(".gitmodules"), /concurrent work/);
585
+ assert.equal(
586
+ save(f.root, reviewed(f.root, [entry]), options).status,
587
+ "saved",
588
+ );
589
+ assert.match(f.read(".gitmodules"), /concurrent work/);
590
+ });
591
+
592
+ test("unrelated intervening profile, workflow, and working .gitmodules edits merge without another Save", () => {
593
+ const f = fixture();
594
+ const entry = f.entry();
595
+ const request = reviewed(f.root, [entry]);
596
+ const config = JSON.parse(f.read("project/repositories.json"));
597
+ config.custom = "newer";
598
+ f.write("project/repositories.json", config);
599
+ const workflows = JSON.parse(f.read("project/workflows.json"));
600
+ workflows.custom = true;
601
+ workflows.implementationStages.push({
602
+ id: "independent",
603
+ repositoryIds: [],
604
+ custom: true,
605
+ });
606
+ f.write("project/workflows.json", workflows);
607
+ f.write(
608
+ ".gitmodules",
609
+ `${f.read(".gitmodules")}# preserve unrelated new comment\n`,
610
+ );
611
+ const result = save(f.root, request, options);
612
+ assert.equal(result.status, "saved", result.error);
613
+ assert.equal(JSON.parse(f.read("project/repositories.json")).custom, "newer");
614
+ assert.equal(JSON.parse(f.read("project/workflows.json")).custom, true);
615
+ assert.deepEqual(
616
+ JSON.parse(f.read("project/workflows.json")).implementationStages,
617
+ [{ id: "independent", repositoryIds: [], custom: true }],
618
+ );
619
+ assert.match(f.read(".gitmodules"), /preserve unrelated new comment/);
620
+ });
621
+
622
+ test("explicit reviewed cleanup accepts a modified known template identity with an HTTPS URL", () => {
623
+ const f = fixture({ examples: false });
624
+ const modified = structuredClone(template.repositories[0]);
625
+ modified.url = "https://github.com/example/example-core.git";
626
+ modified.purpose = "Changed";
627
+ f.write("project/repositories.json", { repositories: [modified] });
628
+ const entry = f.entry();
629
+ const first = preview(f.root, { entries: [entry] }, options);
630
+ assert.equal(first.status, "preview");
631
+ assert.deepEqual(first.effects.removeExamples, []);
632
+ const request = reviewed(f.root, [entry], { removeExamples: [modified.id] });
633
+ assert.equal(save(f.root, request, options).status, "saved");
634
+ assert.deepEqual(
635
+ JSON.parse(f.read("project/repositories.json")).repositories,
636
+ [entry],
637
+ );
638
+ });
639
+
640
+ test("concurrent staged destination is preserved rather than overwritten with a gitlink", () => {
641
+ const f = fixture();
642
+ const entry = f.entry();
643
+ let stagedObject;
644
+ const result = save(f.root, reviewed(f.root, [entry]), {
645
+ ...options,
646
+ beforeRegister() {
647
+ stagedObject = git(f.root, "hash-object", "-w", "notes");
648
+ git(
649
+ f.root,
650
+ "update-index",
651
+ "--add",
652
+ "--cacheinfo",
653
+ `100644,${stagedObject},${entry.path}`,
654
+ );
655
+ },
656
+ });
657
+ assert.equal(result.status, "incomplete");
658
+ assert.match(
659
+ git(f.root, "ls-files", "--stage", "--", entry.path),
660
+ new RegExp(`100644 ${stagedObject}`),
661
+ );
662
+ assert.equal(
663
+ JSON.parse(f.read("project/repositories.json")).repositories.length,
664
+ 3,
665
+ );
666
+ });
667
+
668
+ test("matching existing submodules with custom section names are reused without duplicate local configuration", () => {
669
+ const f = fixture({ examples: false });
670
+ const entry = f.entry();
671
+ assert.equal(
672
+ save(f.root, reviewed(f.root, [entry]), options).status,
673
+ "saved",
674
+ );
675
+ git(
676
+ f.root,
677
+ "config",
678
+ "--file",
679
+ ".gitmodules",
680
+ "--rename-section",
681
+ `submodule.${entry.path}`,
682
+ "submodule.custom-name",
683
+ );
684
+ git(f.root, "add", ".gitmodules");
685
+ git(
686
+ f.root,
687
+ "config",
688
+ "--rename-section",
689
+ `submodule.${entry.path}`,
690
+ "submodule.custom-name",
691
+ );
692
+ const request = reviewed(f.root, [entry]);
693
+ const result = save(f.root, request, options);
694
+ assert.equal(result.status, "saved", result.error);
695
+ assert.equal(result.repositories[0].state, "registered");
696
+ assert.equal(
697
+ git(f.root, "config", "--get", "submodule.custom-name.url"),
698
+ entry.url,
699
+ );
700
+ const missing = spawnSync(
701
+ "git",
702
+ ["config", "--get", `submodule.${entry.path}.url`],
703
+ { cwd: f.root },
704
+ );
705
+ assert.equal(missing.status, 1);
706
+ assert.deepEqual(result.createdPaths, []);
707
+ });
708
+
709
+ test("concurrent target local configuration changes are conflicts and never overwritten", () => {
710
+ const f = fixture();
711
+ const entry = f.entry();
712
+ const result = save(f.root, reviewed(f.root, [entry]), {
713
+ ...options,
714
+ beforeRegister() {
715
+ git(
716
+ f.root,
717
+ "config",
718
+ `submodule.${entry.path}.url`,
719
+ "https://other.example/other/repo",
720
+ );
721
+ },
722
+ });
723
+ assert.equal(result.status, "incomplete");
724
+ assert.equal(
725
+ git(f.root, "config", "--get", `submodule.${entry.path}.url`),
726
+ "https://other.example/other/repo",
727
+ );
728
+ assert.equal(git(f.root, "ls-files", "--stage", "--", entry.path), "");
729
+ });
730
+
731
+ test("template cleanup retains standalone and inline comments in working and indexed .gitmodules", () => {
732
+ const f = fixture();
733
+ const entry = f.entry();
734
+ const original = `${f
735
+ .read(".gitmodules")
736
+ .replace(
737
+ '[submodule "modules/example-core"]',
738
+ '[submodule "modules/example-core"] # keep header comment',
739
+ )
740
+ .replace(
741
+ "path = modules/example-core",
742
+ "path = modules/example-core # keep path comment",
743
+ )}# keep trailing comment\n`;
744
+ f.write(".gitmodules", original);
745
+ git(f.root, "add", ".gitmodules");
746
+ const result = save(f.root, reviewed(f.root, [entry]), options);
747
+ assert.equal(result.status, "saved", result.error);
748
+ for (const text of [
749
+ f.read(".gitmodules"),
750
+ git(f.root, "show", ":.gitmodules"),
751
+ ]) {
752
+ assert.match(text, /keep header comment/);
753
+ assert.match(text, /keep path comment/);
754
+ assert.match(text, /keep trailing comment/);
755
+ assert.doesNotMatch(text, /path = modules\/example-core/);
756
+ }
757
+ });
758
+
759
+ test("save isolates repository-local Git hook variables from fixture clones", () => {
760
+ const f = fixture();
761
+ const entry = f.entry();
762
+ const parentIndex = fs.readFileSync(path.join(f.root, ".git/index"));
763
+ const helperUrl = new URL("./add-project.mjs", import.meta.url).href;
764
+ const child = spawnSync(
765
+ process.execPath,
766
+ [
767
+ "--input-type=module",
768
+ "-e",
769
+ `
770
+ import { preview, save } from ${JSON.stringify(helperUrl)};
771
+ const root = process.argv[1];
772
+ const request = JSON.parse(process.argv[2]);
773
+ const result = preview(root, request, { allowLocal: true });
774
+ console.log(JSON.stringify(save(root, { ...request, token: result.token }, { allowLocal: true })));
775
+ `,
776
+ f.root,
777
+ JSON.stringify({ entries: [entry] }),
778
+ ],
779
+ {
780
+ encoding: "utf8",
781
+ env: {
782
+ ...process.env,
783
+ GIT_INDEX_FILE: ".git/index",
784
+ GIT_DIR: path.join(f.root, ".git"),
785
+ GIT_WORK_TREE: f.root,
786
+ },
787
+ },
788
+ );
789
+ assert.equal(child.status, 0, child.stderr);
790
+ const result = JSON.parse(child.stdout);
791
+ assert.equal(result.status, "saved", result.error);
792
+ assert.equal(
793
+ git(path.join(f.root, entry.path), "rev-parse", "HEAD"),
794
+ result.repositories[0].revision,
795
+ );
796
+ assert.notDeepEqual(
797
+ fs.readFileSync(path.join(f.root, ".git/index")),
798
+ parentIndex,
799
+ );
800
+ assert.match(
801
+ git(f.root, "ls-files", "--stage", "--", entry.path),
802
+ /^160000 /,
803
+ );
804
+ });