@uniqbit/mate-core 1.0.0-canary.2 → 1.0.0-canary.5
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.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
- package/claude-plugin/hooks/hooks.json +21 -1
- package/claude-plugin/hooks/session-attention.mjs +10 -0
- package/claude-plugin/hooks/session-end.mjs +9 -0
- package/claude-plugin/hooks/session-guidance.mjs +1 -1
- package/opencode-plugin/src/server.ts +13 -2
- package/opencode-plugin/src/tui.tsx +1 -1
- package/opencode-plugin/tui.tsx +2 -1
- package/package.json +1 -1
- package/src/cli/commands/artifact/delivery/archive.ts +2 -2
- package/src/cli/commands/artifact/delivery/link.ts +22 -5
- package/src/cli/commands/artifact/delivery/output.ts +9 -1
- package/src/cli/commands/artifact/finish/openspec.ts +1 -3
- package/src/cli/commands/companion/companion.ts +1 -1
- package/src/cli/commands/companion/link.ts +36 -4
- package/src/cli/commands/companion/open.ts +40 -12
- package/src/cli/commands/doctor.ts +122 -0
- package/src/cli/commands/session/prepare.ts +32 -4
- package/src/cli/commands/session/registry.ts +90 -0
- package/src/cli/commands/studio/companion-removal.ts +79 -0
- package/src/cli/commands/studio/mate-inventory.ts +1 -1
- package/src/cli/commands/studio/payload.ts +12 -1
- package/src/cli/commands/studio/server.ts +39 -16
- package/src/cli/commands/studio/services.ts +20 -0
- package/src/cli/commands/studio/skill-files.ts +133 -0
- package/src/cli/commands/studio/vault.ts +218 -44
- package/src/cli/commands/studio/views/model.ts +0 -5
- package/src/cli/commands/studio/views/vault/markdown-tree.ts +255 -4
- package/src/cli/commands/unwrap.ts +8 -0
- package/src/cli/commands/update.ts +26 -8
- package/src/cli/commands/vscode/setup.ts +155 -0
- package/src/cli/commands/vscode/vsix.ts +73 -0
- package/src/cli/commands/working/cleanup.ts +34 -10
- package/src/cli/commands/working/worktree.ts +58 -8
- package/src/cli/commands/wrap.ts +33 -7
- package/src/cli/main.ts +9 -2
- package/src/cli/usage.ts +6 -1
- package/src/hooks/companion-instructions.ts +19 -11
- package/src/hooks/hook-io.ts +15 -0
- package/src/hooks/session-banner.ts +5 -3
- package/src/hooks/session-end.ts +10 -0
- package/src/hooks/session-guidance.ts +10 -6
- package/src/hooks/session-prepare.ts +47 -31
- package/src/hooks/session-register.ts +199 -0
- package/src/hooks/tokensave-route.ts +7 -3
- package/src/hooks/validate-artifact-path.ts +9 -2
- package/src/lib/delivery/archive-change.ts +0 -1
- package/src/lib/delivery/branches.ts +15 -0
- package/src/lib/delivery/record-delivery.ts +94 -39
- package/src/lib/delivery/record.ts +30 -28
- package/src/lib/delivery/refresh.ts +37 -17
- package/src/lib/delivery/resolve-branch.ts +258 -37
- package/src/lib/factory/outcomes/index.ts +11 -1
- package/src/lib/factory/runtime.ts +10 -1
- package/src/lib/opencode-server.ts +238 -0
- package/src/lib/orchestrator/adapters/claude.ts +147 -2
- package/src/lib/orchestrator/adapters/opencode.ts +53 -2
- package/src/lib/orchestrator/checkout-adoption.ts +125 -0
- package/src/lib/orchestrator/companion-registry-store.ts +6 -2
- package/src/lib/orchestrator/editor.ts +2 -2
- package/src/lib/orchestrator/framework-context.ts +26 -14
- package/src/lib/orchestrator/global-config-store.ts +11 -0
- package/src/lib/orchestrator/launcher.ts +15 -2
- package/src/lib/orchestrator/projection-claude-links.ts +52 -5
- package/src/lib/orchestrator/projection-claude-skills.ts +28 -2
- package/src/lib/orchestrator/projection-companion-link.ts +12 -1
- package/src/lib/orchestrator/registry-checkouts.ts +177 -0
- package/src/lib/orchestrator/repository-link.ts +216 -57
- package/src/lib/orchestrator/serving-claude-wrap.ts +43 -0
- package/src/lib/orchestrator/session-context-link.ts +11 -5
- package/src/lib/orchestrator/session-prepare.ts +36 -6
- package/src/lib/orchestrator/types.ts +5 -0
- package/src/lib/orchestrator/workspace-inventory.ts +5 -1
- package/src/lib/public-npm.ts +17 -0
- package/src/lib/session-attribution.ts +52 -0
- package/src/lib/session-state.ts +285 -0
- package/src/lib/session-stop.ts +64 -0
- package/src/lib/workset/record.ts +20 -0
- package/src/lib/workset/worktree.ts +85 -17
- package/src/opencode/background-server.ts +145 -0
- package/src/opencode/companion-hooks.ts +3 -1
- package/src/opencode/companion-policy.ts +2 -2
- package/src/opencode/projected-guidance.ts +2 -1
- package/src/opencode/session-register.ts +176 -0
- package/src/opencode/tui.tsx +19 -29
- package/src/runtime/claude-delivery-plan.ts +14 -3
- package/src/runtime/current-branch.ts +10 -0
- package/src/runtime/env.ts +13 -7
- package/src/runtime/git-layout.ts +164 -17
- package/src/runtime/launch-env-guard.ts +65 -0
- package/src/runtime/opencode-server-record.ts +136 -0
- package/src/runtime/projection.ts +40 -6
- package/src/runtime/repo-local.ts +6 -1
- package/src/runtime/serving-claude-wrap.ts +28 -0
- package/src/runtime/session-context.ts +4 -3
- package/src/runtime/session-registry.ts +434 -0
- package/src/runtime/tokensave-route.ts +10 -5
- package/src/runtime/wrap-state.ts +31 -0
- package/src/studio.ts +2 -0
- package/src/templates/mate-skills/agents/mate-apply-change/SKILL.md +49 -21
- package/src/templates/mate-skills/agents/mate-archive-change/SKILL.md +0 -5
- package/src/templates/mate-skills/agents/mate-propose-change/SKILL.md +2 -8
- package/src/templates/mate-skills/agents/mate-propose-change/references/mate-revise.md +1 -3
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +2 -4
- package/src/templates/mate-skills/claude/mate-apply-change/SKILL.md +49 -21
- package/src/templates/mate-skills/claude/mate-archive-change/SKILL.md +0 -5
- package/src/templates/mate-skills/claude/mate-propose-change/SKILL.md +2 -8
- package/src/templates/mate-skills/claude/mate-propose-change/references/mate-revise.md +1 -3
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +2 -4
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +404 -30
- package/src/tools/setup/dynamic-plugins/hydrate.ts +4 -3
- package/src/tools/setup/providers/claude-plugin-hooks.ts +26 -0
- package/src/tools/setup/providers/claude.ts +21 -1
- package/studio-dist/client/assets/app-CdPiFv59.css +2 -0
- package/studio-dist/client/assets/button-BIIHE0EQ.js +3 -0
- package/studio-dist/client/assets/companion-view-DM6YyXaR.js +1 -0
- package/studio-dist/client/assets/delivery-path-DELxj0Av.js +1 -0
- package/studio-dist/client/assets/factory-BZy0E8ty.js +4 -0
- package/studio-dist/client/assets/index-B3wkMzjA.js +40 -0
- package/studio-dist/client/assets/markdown-view-pQ2Qp_i5.js +1 -0
- package/studio-dist/client/assets/panel-CbajlC3p.js +1 -0
- package/studio-dist/client/assets/{prepaint-CD5OpmTM.js → prepaint-CwSrpdFA.js} +7 -4
- package/studio-dist/client/assets/react-CN2GSx7x.js +1 -0
- package/studio-dist/client/assets/reports-DllhYQ5_.js +1 -0
- package/studio-dist/client/assets/routes-COm-G3mK.js +1 -0
- package/studio-dist/client/assets/skills-DmWAy-jZ.js +1 -0
- package/studio-dist/client/assets/specs-BG3Wi3ln.js +1 -0
- package/studio-dist/client/assets/steps-DFsH3Neu.js +1 -0
- package/studio-dist/client/assets/vault-B2q1nBY5.js +1 -0
- package/studio-dist/client/assets/warnings-BSXIyuSQ.js +1 -0
- package/studio-dist/client/assets/workflow-DlsQD6Hc.js +1 -0
- package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-BQKuMdJW.js → __23tanstack-start-server-fn-resolver-M2GBs8s3.js} +179 -9
- package/studio-dist/server/assets/_tanstack-start-manifest_v.js +35 -25
- package/studio-dist/server/assets/button-CIJqAhni.js +11929 -0
- package/studio-dist/server/assets/{companion-view-aBady57v.js → companion-view-DISASvdJ.js} +13 -7
- package/studio-dist/server/assets/companions-BYbHWKOZ.js +15 -0
- package/studio-dist/server/assets/delivery-path-C29fBynY.js +654 -0
- package/studio-dist/server/assets/{factory-DT3UzHlh.js → factory-DGPmNGbo.js} +1 -0
- package/studio-dist/server/assets/{factory-D6xnjedJ.js → factory-DUTa0eDs.js} +317 -530
- package/studio-dist/server/assets/markdown-view-Bn7xPdks.js +86 -0
- package/studio-dist/server/assets/panel-3Jmn4awF.js +169 -0
- package/studio-dist/server/assets/{prepaint-BMke0fo1.js → prepaint-DJfTQ_VH.js} +6 -2
- package/studio-dist/server/assets/{react-COs0LHn-.js → react-Ce6dj15C.js} +4 -9
- package/studio-dist/server/assets/reports-C06RXVE2.js +18 -0
- package/studio-dist/server/assets/reports-D6YMqhnO.js +142 -0
- package/studio-dist/server/assets/router-C8MGqlAY.js +13713 -0
- package/studio-dist/server/assets/routes-BcFgvqf7.js +622 -0
- package/studio-dist/server/assets/{shell-CboT2f66.js → shell-DS3wUexh.js} +1 -0
- package/studio-dist/server/assets/skills-BEnOxiDl.js +266 -0
- package/studio-dist/server/assets/skills-CtrBAtX3.js +28 -0
- package/studio-dist/server/assets/specs-C8rv34-5.js +211 -0
- package/studio-dist/server/assets/{start-BW5ovN0k.js → start-h3ICWwd2.js} +4 -1
- package/studio-dist/server/assets/steps-Dq_CwY_s.js +181 -0
- package/studio-dist/server/assets/{vault-BGulVoNh.js → vault-BmWnryh3.js} +16 -1
- package/studio-dist/server/assets/vault-Fvxt2Tzl.js +1032 -0
- package/studio-dist/server/assets/{views-Bd7cRr27.js → views-BgYa-za2.js} +1 -3
- package/studio-dist/server/assets/warnings-DzR6fyZh.js +23 -0
- package/studio-dist/server/assets/workflow-liRYecHk.js +73 -0
- package/studio-dist/server/server.js +3 -157
- package/studio-dist/client/assets/companion-view-Csva26Ir.js +0 -1
- package/studio-dist/client/assets/delivery-path-DJMpRmiY.js +0 -1
- package/studio-dist/client/assets/factory-B7l9ZQyx.js +0 -4
- package/studio-dist/client/assets/index-n6uo_92S.js +0 -40
- package/studio-dist/client/assets/queries-CN3JwMBX.js +0 -1
- package/studio-dist/client/assets/react-CabXf2Ds.js +0 -1
- package/studio-dist/client/assets/report-time-Dc-KOqQu.js +0 -1
- package/studio-dist/client/assets/reports-C01RsnMA.js +0 -1
- package/studio-dist/client/assets/routes-4pbC-2Hj.js +0 -1
- package/studio-dist/client/assets/skills-CihQganl.js +0 -1
- package/studio-dist/client/assets/spec-areas-C2L48N4C.js +0 -1
- package/studio-dist/client/assets/specs-D24_35_K.js +0 -1
- package/studio-dist/client/assets/studio-DKxfi691.css +0 -1
- package/studio-dist/client/assets/studio-queries-rvbJupCy.js +0 -3
- package/studio-dist/client/assets/vault-Bd4CQiTK.js +0 -1
- package/studio-dist/client/assets/warnings-V_Ys51wJ.js +0 -1
- package/studio-dist/client/assets/workflow-BJejeVwQ.js +0 -1
- package/studio-dist/server/assets/delivery-path-BkKNjgkf.js +0 -778
- package/studio-dist/server/assets/queries-Ag2iL8q2.js +0 -107
- package/studio-dist/server/assets/report-time-DAfzln-N.js +0 -8
- package/studio-dist/server/assets/reports-BnUNJVtx.js +0 -126
- package/studio-dist/server/assets/router-BH--drIx.js +0 -4298
- package/studio-dist/server/assets/routes-khSDK1bV.js +0 -361
- package/studio-dist/server/assets/skills-MWYnWoKs.js +0 -106
- package/studio-dist/server/assets/spec-areas-DcnO6vW-.js +0 -16
- package/studio-dist/server/assets/specs-DE3w8hZP.js +0 -155
- package/studio-dist/server/assets/studio-queries-CLnP9kGu.js +0 -3365
- package/studio-dist/server/assets/vault-CuyyhLyB.js +0 -832
- package/studio-dist/server/assets/warnings-BH05rOuG.js +0 -15
- package/studio-dist/server/assets/workflow-BSuIKWqH.js +0 -42
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Token, type Tokens, Lexer } from "marked";
|
|
2
|
+
import { parse as parseYaml } from "yaml";
|
|
2
3
|
|
|
3
4
|
import { highlightNodes } from "../../../report/highlight";
|
|
4
5
|
|
|
@@ -33,6 +34,9 @@ export type MdTag =
|
|
|
33
34
|
| "li"
|
|
34
35
|
| "input"
|
|
35
36
|
| "div"
|
|
37
|
+
| "dl"
|
|
38
|
+
| "dt"
|
|
39
|
+
| "dd"
|
|
36
40
|
| "table"
|
|
37
41
|
| "thead"
|
|
38
42
|
| "tbody"
|
|
@@ -108,12 +112,141 @@ function highlighted(code: string, language: string | undefined): MdNode[] {
|
|
|
108
112
|
return highlightNodes(code, language).map(map);
|
|
109
113
|
}
|
|
110
114
|
|
|
115
|
+
const SECTION_PREFIX = /^(Requirement|Scenario):\s*/i;
|
|
116
|
+
const STEP_KEYWORDS = new Set(["GIVEN", "WHEN", "THEN", "AND", "BUT"]);
|
|
117
|
+
const NORMATIVE = /\b(SHALL NOT|SHALL|MUST NOT|MUST)\b/g;
|
|
118
|
+
|
|
119
|
+
/** OpenSpec's `Requirement:` (level 3) and `Scenario:` (level 4) headings open a section. */
|
|
120
|
+
function sectionKind(heading: Tokens.Heading): "requirement" | "scenario" | null {
|
|
121
|
+
const match = SECTION_PREFIX.exec(heading.text);
|
|
122
|
+
if (!match) return null;
|
|
123
|
+
const word = match[1]!.toLowerCase();
|
|
124
|
+
if (word === "requirement" && heading.depth === 3) return "requirement";
|
|
125
|
+
if (word === "scenario" && heading.depth >= 3) return "scenario";
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** A `- **WHEN** …` item as its keyword and the inline tokens after it. */
|
|
130
|
+
function stepOf(item: Tokens.ListItem): { keyword: string; rest: Token[] } | null {
|
|
131
|
+
const first = item.tokens[0];
|
|
132
|
+
if (item.task || first?.type !== "text") return null;
|
|
133
|
+
const inline = (first as Tokens.Text).tokens ?? [];
|
|
134
|
+
const lead = inline[0];
|
|
135
|
+
if (lead?.type !== "strong") return null;
|
|
136
|
+
const keyword = (lead as Tokens.Strong).text.trim().replace(/:$/, "").toUpperCase();
|
|
137
|
+
if (!STEP_KEYWORDS.has(keyword)) return null;
|
|
138
|
+
const rest = inline.slice(1);
|
|
139
|
+
const next = rest[0];
|
|
140
|
+
if (next?.type === "text") {
|
|
141
|
+
const text = next as Tokens.Text;
|
|
142
|
+
const trimmed = text.text.replace(/^[\s:]+/, "");
|
|
143
|
+
rest[0] = { ...text, raw: trimmed, text: trimmed, tokens: undefined };
|
|
144
|
+
}
|
|
145
|
+
return { keyword, rest };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const headingTag = (heading: Tokens.Heading): MdTag =>
|
|
149
|
+
`h${Math.min(Math.max(heading.depth, 1), 6)}` as MdTag;
|
|
150
|
+
|
|
151
|
+
/** SHALL and MUST in a requirement's own paragraphs, so the obligation reads at a glance. */
|
|
152
|
+
function markNormative(node: MdNode): MdNode {
|
|
153
|
+
if (typeof node === "string" || node.t !== "p" || !node.c) return node;
|
|
154
|
+
return {
|
|
155
|
+
...node,
|
|
156
|
+
c: node.c.flatMap((child) =>
|
|
157
|
+
typeof child === "string"
|
|
158
|
+
? child
|
|
159
|
+
.split(NORMATIVE)
|
|
160
|
+
.filter((part) => part !== "")
|
|
161
|
+
.map((part) =>
|
|
162
|
+
/^(SHALL|MUST)( NOT)?$/.test(part)
|
|
163
|
+
? el("strong", [part], { className: "md-shall" })
|
|
164
|
+
: part,
|
|
165
|
+
)
|
|
166
|
+
: [child],
|
|
167
|
+
),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
111
171
|
/** The same mapping the server-rendered vault used, producing data instead of markup. */
|
|
112
172
|
class TreeMapper {
|
|
113
173
|
constructor(private readonly path: string) {}
|
|
114
174
|
|
|
115
175
|
blocks(tokens: Token[] | undefined): MdNode[] {
|
|
116
|
-
|
|
176
|
+
const list = tokens ?? [];
|
|
177
|
+
const nodes: MdNode[] = [];
|
|
178
|
+
for (let index = 0; index < list.length; index += 1) {
|
|
179
|
+
const token = list[index]!;
|
|
180
|
+
const kind = token.type === "heading" ? sectionKind(token as Tokens.Heading) : null;
|
|
181
|
+
if (!kind) {
|
|
182
|
+
nodes.push(...this.block(token));
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
// An OpenSpec section runs to the next heading at its own depth or above.
|
|
186
|
+
const heading = token as Tokens.Heading;
|
|
187
|
+
let end = index + 1;
|
|
188
|
+
while (end < list.length) {
|
|
189
|
+
const next = list[end]!;
|
|
190
|
+
if (next.type === "heading" && (next as Tokens.Heading).depth <= heading.depth) break;
|
|
191
|
+
end += 1;
|
|
192
|
+
}
|
|
193
|
+
const body = list.slice(index + 1, end);
|
|
194
|
+
nodes.push(
|
|
195
|
+
kind === "scenario" ? this.scenario(heading, body) : this.requirement(heading, body),
|
|
196
|
+
);
|
|
197
|
+
index = end - 1;
|
|
198
|
+
}
|
|
199
|
+
return nodes;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** `### Requirement: …`: the heading with its label, then its text, SHALL marked. */
|
|
203
|
+
private requirement(heading: Tokens.Heading, body: Token[]): MdElement {
|
|
204
|
+
return el(
|
|
205
|
+
"div",
|
|
206
|
+
[
|
|
207
|
+
el(
|
|
208
|
+
headingTag(heading),
|
|
209
|
+
[
|
|
210
|
+
el("span", ["Requirement"], { className: "md-section-label" }),
|
|
211
|
+
...this.titleOf(heading),
|
|
212
|
+
],
|
|
213
|
+
{ className: "md-requirement-title" },
|
|
214
|
+
),
|
|
215
|
+
...this.blocks(body).map(markNormative),
|
|
216
|
+
],
|
|
217
|
+
{ className: "md-requirement" },
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/** `#### Scenario: …` as one card; its `**WHEN**`-style list items become steps. */
|
|
222
|
+
private scenario(heading: Tokens.Heading, body: Token[]): MdElement {
|
|
223
|
+
return el(
|
|
224
|
+
"div",
|
|
225
|
+
[
|
|
226
|
+
el(
|
|
227
|
+
"p",
|
|
228
|
+
[el("span", ["Scenario"], { className: "md-section-label" }), ...this.titleOf(heading)],
|
|
229
|
+
{ className: "md-scenario-title" },
|
|
230
|
+
),
|
|
231
|
+
...body.flatMap((token) =>
|
|
232
|
+
token.type === "list"
|
|
233
|
+
? [this.steps(token as Tokens.List) ?? this.list(token as Tokens.List)]
|
|
234
|
+
: this.block(token),
|
|
235
|
+
),
|
|
236
|
+
],
|
|
237
|
+
{ className: "md-scenario" },
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** A section heading's text without its `Requirement:` or `Scenario:` prefix. */
|
|
242
|
+
private titleOf(heading: Tokens.Heading): MdNode[] {
|
|
243
|
+
const tokens = heading.tokens ?? [];
|
|
244
|
+
const first = tokens[0];
|
|
245
|
+
if (first?.type !== "text") return this.inline(tokens, heading.text);
|
|
246
|
+
const text = (first as Tokens.Text).text.replace(SECTION_PREFIX, "");
|
|
247
|
+
return [text, ...tokens.slice(1).map((token) => this.span(token))].filter(
|
|
248
|
+
(node) => node !== "",
|
|
249
|
+
);
|
|
117
250
|
}
|
|
118
251
|
|
|
119
252
|
inline(tokens: Token[] | undefined, fallback = ""): MdNode[] {
|
|
@@ -128,8 +261,7 @@ class TreeMapper {
|
|
|
128
261
|
return [];
|
|
129
262
|
case "heading": {
|
|
130
263
|
const heading = token as Tokens.Heading;
|
|
131
|
-
|
|
132
|
-
return [el(`h${depth}` as MdTag, this.inline(heading.tokens, heading.text))];
|
|
264
|
+
return [el(headingTag(heading), this.inline(heading.tokens, heading.text))];
|
|
133
265
|
}
|
|
134
266
|
case "paragraph": {
|
|
135
267
|
const paragraph = token as Tokens.Paragraph;
|
|
@@ -162,6 +294,26 @@ class TreeMapper {
|
|
|
162
294
|
}
|
|
163
295
|
}
|
|
164
296
|
|
|
297
|
+
/** A scenario's list as keyword steps, or `null` unless every item is a step. */
|
|
298
|
+
private steps(list: Tokens.List): MdElement | null {
|
|
299
|
+
const steps = list.items.map(stepOf);
|
|
300
|
+
if (!steps.every((step) => step !== null)) return null;
|
|
301
|
+
return el(
|
|
302
|
+
"ul",
|
|
303
|
+
steps.map(({ keyword, rest }) =>
|
|
304
|
+
el(
|
|
305
|
+
"li",
|
|
306
|
+
[
|
|
307
|
+
el("span", [keyword], { className: `md-step-key md-key-${keyword.toLowerCase()}` }),
|
|
308
|
+
el("span", this.inline(rest)),
|
|
309
|
+
],
|
|
310
|
+
{ className: "md-step" },
|
|
311
|
+
),
|
|
312
|
+
),
|
|
313
|
+
{ className: "md-steps" },
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
165
317
|
private list(list: Tokens.List): MdElement {
|
|
166
318
|
const start =
|
|
167
319
|
list.ordered && typeof list.start === "number" && list.start !== 1 ? list.start : undefined;
|
|
@@ -263,5 +415,104 @@ class TreeMapper {
|
|
|
263
415
|
|
|
264
416
|
/** A markdown file as data the browser renders; `path` is where its relative links start. */
|
|
265
417
|
export function markdownTree(source: string, path: string): MdNode[] {
|
|
266
|
-
|
|
418
|
+
const match = FRONTMATTER.exec(source);
|
|
419
|
+
const body = match ? source.slice(match[0].length) : source;
|
|
420
|
+
const nodes = new TreeMapper(path).blocks(new Lexer({ gfm: true }).lex(body));
|
|
421
|
+
return match ? [frontmatter(match[1] ?? match[2] ?? ""), ...nodes] : nodes;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/** A text file that is not markdown as one highlighted block; `language` may be an extension. */
|
|
425
|
+
export function codeTree(source: string, language: string | undefined): MdNode[] {
|
|
426
|
+
return [el("pre", [el("code", highlighted(source, language))], { className: "md-fence" })];
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/** `---` YAML, or the `<!-- mate:delta … -->` header Mate writes atop a change's spec delta. */
|
|
430
|
+
const FRONTMATTER =
|
|
431
|
+
/^(?:---[ \t]*\r?\n([\s\S]*?)\r?\n---|<!--[ \t]*mate:delta[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*-->)[ \t]*(?:\r?\n|$)/;
|
|
432
|
+
/** Nesting shown as fields; deeper values fall back to their JSON text. */
|
|
433
|
+
const FIELD_DEPTH = 2;
|
|
434
|
+
|
|
435
|
+
/** A file's leading YAML block as fields; text that is not a mapping is shown as written. */
|
|
436
|
+
function frontmatter(yaml: string): MdElement {
|
|
437
|
+
let data: unknown;
|
|
438
|
+
try {
|
|
439
|
+
data = parseYaml(yaml);
|
|
440
|
+
} catch {
|
|
441
|
+
data = undefined;
|
|
442
|
+
}
|
|
443
|
+
const fields = isRecord(data)
|
|
444
|
+
? fieldList(data, 0)
|
|
445
|
+
: el("pre", [el("code", [yaml])], { className: "md-fence" });
|
|
446
|
+
return el("div", [fields], { className: "md-frontmatter" });
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const isRecord = (value: unknown): value is Record<string, unknown> =>
|
|
450
|
+
typeof value === "object" && value !== null && !Array.isArray(value);
|
|
451
|
+
|
|
452
|
+
/** Only scalar values, so the mapping fits on one chip. */
|
|
453
|
+
const flat = (record: Record<string, unknown>): boolean =>
|
|
454
|
+
Object.values(record).every((entry) => entry === null || typeof entry !== "object");
|
|
455
|
+
|
|
456
|
+
interface Scope {
|
|
457
|
+
repository: string;
|
|
458
|
+
area: string;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/** A `scopes` entry: exactly a repository and one of its Areas. */
|
|
462
|
+
const isScope = (value: unknown): value is Scope =>
|
|
463
|
+
isRecord(value) &&
|
|
464
|
+
Object.keys(value).length === 2 &&
|
|
465
|
+
typeof value.repository === "string" &&
|
|
466
|
+
typeof value.area === "string";
|
|
467
|
+
|
|
468
|
+
/** Scopes grouped by repository, in first-seen order, each Area a chip; `.` is its root. */
|
|
469
|
+
function scopeGroups(scopes: Scope[]): MdNode[] {
|
|
470
|
+
const areasByRepository = new Map<string, string[]>();
|
|
471
|
+
for (const { repository, area } of scopes) {
|
|
472
|
+
areasByRepository.set(repository, [...(areasByRepository.get(repository) ?? []), area]);
|
|
473
|
+
}
|
|
474
|
+
return [...areasByRepository].map(([repository, areas]) =>
|
|
475
|
+
el(
|
|
476
|
+
"div",
|
|
477
|
+
[
|
|
478
|
+
el("span", [repository], { className: "md-scope-repo" }),
|
|
479
|
+
...areas.map((area) =>
|
|
480
|
+
area === "."
|
|
481
|
+
? el("span", ["root"], { className: "md-chip md-chip-root" })
|
|
482
|
+
: el("span", [area], { className: "md-chip" }),
|
|
483
|
+
),
|
|
484
|
+
],
|
|
485
|
+
{ className: "md-scope" },
|
|
486
|
+
),
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function fieldList(data: Record<string, unknown>, depth: number): MdElement {
|
|
491
|
+
return el(
|
|
492
|
+
"dl",
|
|
493
|
+
Object.entries(data).flatMap(([name, value]) => [
|
|
494
|
+
el("dt", [name]),
|
|
495
|
+
el("dd", fieldValue(value, depth)),
|
|
496
|
+
]),
|
|
497
|
+
);
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function fieldValue(value: unknown, depth: number): MdNode[] {
|
|
501
|
+
if (value === null || value === undefined || value === "") {
|
|
502
|
+
return [el("span", ["empty"], { className: "md-field-empty" })];
|
|
503
|
+
}
|
|
504
|
+
if (value instanceof Date) return [value.toISOString().slice(0, 10)];
|
|
505
|
+
if (Array.isArray(value) && value.every((item) => !isRecord(item) && !Array.isArray(item))) {
|
|
506
|
+
return value.map((item) => el("span", [String(item)], { className: "md-chip" }));
|
|
507
|
+
}
|
|
508
|
+
if (Array.isArray(value) && value.length > 0 && value.every(isScope)) return scopeGroups(value);
|
|
509
|
+
// A list of small mappings reads as one chip per item.
|
|
510
|
+
if (Array.isArray(value) && value.every((item) => isRecord(item) && flat(item))) {
|
|
511
|
+
return value.map((item) =>
|
|
512
|
+
el("span", [Object.values(item).map(String).join(" · ")], { className: "md-chip" }),
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
if (isRecord(value) && depth < FIELD_DEPTH) return [fieldList(value, depth + 1)];
|
|
516
|
+
if (typeof value === "object") return [el("code", [JSON.stringify(value)])];
|
|
517
|
+
return [String(value)];
|
|
267
518
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { FRAMEWORK_NAME } from "../../framework";
|
|
2
|
+
import { otherRegisteredWraps } from "../../lib/orchestrator/checkout-adoption";
|
|
2
3
|
import { attendedLockOptions } from "../../lib/orchestrator/companion-git-sync";
|
|
3
4
|
import { findRepoLocalLinkedRepository } from "../../lib/orchestrator/repository-link";
|
|
4
5
|
import { unwrapWorkingRuntimeDocuments } from "../../lib/orchestrator/working-repo-projection";
|
|
@@ -100,4 +101,11 @@ export async function runUnwrapCommand(
|
|
|
100
101
|
console.log(
|
|
101
102
|
`The next \`${FRAMEWORK_NAME} claude\` or \`${FRAMEWORK_NAME} opencode\` wraps this repository again.`,
|
|
102
103
|
);
|
|
104
|
+
/** Adoption gives a Checkout its Registered Checkout's wraps (design Decision 8). */
|
|
105
|
+
const registered = companionPath && (await otherRegisteredWraps(companionPath, repository));
|
|
106
|
+
if (registered) {
|
|
107
|
+
console.log(
|
|
108
|
+
`So does the next \`${FRAMEWORK_NAME} session prepare\` here: ${registered.checkout}, the Registered Checkout of ${repository.id}, is wrapped for ${registered.runtimes.join(" and ")}.`,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
103
111
|
}
|
|
@@ -31,6 +31,18 @@ function writeNpmOnlyRecoveryMessage(): void {
|
|
|
31
31
|
);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Runs a command of the just-installed Mate through this process's entrypoint,
|
|
36
|
+
* which now resolves to the new version; skipped for any other entrypoint.
|
|
37
|
+
*/
|
|
38
|
+
function runNewEntrypoint(command: string[]): InstallResult {
|
|
39
|
+
const entrypoint = process.argv[1];
|
|
40
|
+
if (!entrypoint || !/(?:^|[\\/])(?:cli\.ts|cli\.mjs|cli-bootstrap\.cjs)$/.test(entrypoint)) {
|
|
41
|
+
return { status: 0, error: undefined } as InstallResult;
|
|
42
|
+
}
|
|
43
|
+
return updateCommandDeps.spawnPostInstall(process.execPath, [entrypoint, ...command]);
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
export const updateCommandDeps = {
|
|
35
47
|
fetchLatestVersion,
|
|
36
48
|
getCurrentVersion,
|
|
@@ -55,14 +67,11 @@ export const updateCommandDeps = {
|
|
|
55
67
|
});
|
|
56
68
|
},
|
|
57
69
|
/** Re-runs install from dev (`cli.ts`) or prod (`cli.mjs`/bootstrap) entrypoints so config reconciles during `mate update`. */
|
|
58
|
-
runPostInstall: (skipConfirm: boolean): InstallResult =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const args = [entrypoint, "install", ...(skipConfirm ? ["--yes"] : [])];
|
|
64
|
-
return updateCommandDeps.spawnPostInstall(process.execPath, args);
|
|
65
|
-
},
|
|
70
|
+
runPostInstall: (skipConfirm: boolean): InstallResult =>
|
|
71
|
+
runNewEntrypoint(["install", ...(skipConfirm ? ["--yes"] : [])]),
|
|
72
|
+
/** Brings an installed VS Code or Cursor extension to the new version; a no-op without one. */
|
|
73
|
+
updateEditorExtension: (): InstallResult =>
|
|
74
|
+
runNewEntrypoint(["vscode", "setup", "--if-installed"]),
|
|
66
75
|
spawnPostInstall: (executable: string, args: string[]): InstallResult =>
|
|
67
76
|
spawnSync(executable, args, { stdio: "inherit" }) as InstallResult,
|
|
68
77
|
};
|
|
@@ -71,6 +80,8 @@ export const updateCommandDeps = {
|
|
|
71
80
|
* @command mate update
|
|
72
81
|
* @description Checks the public npm registry for a newer mate-cli release and
|
|
73
82
|
* self-upgrades only when Mate is running from the npm global installation.
|
|
83
|
+
* Then re-runs `mate install` and updates the Mate extension in each editor
|
|
84
|
+
* (VS Code, Cursor) that has it installed.
|
|
74
85
|
* @flags
|
|
75
86
|
* - `--check` — only report whether an update is available (exit code 1 if so);
|
|
76
87
|
* does not install anything.
|
|
@@ -188,6 +199,13 @@ async function runUpdate(
|
|
|
188
199
|
|
|
189
200
|
console.log(`\nUpgraded to ${latest}.`);
|
|
190
201
|
console.log("Post-update installation complete.");
|
|
202
|
+
// The CLI is upgraded either way; a failed extension update only warns.
|
|
203
|
+
const extension = updateCommandDeps.updateEditorExtension();
|
|
204
|
+
if (extension.status !== 0 || extension.error) {
|
|
205
|
+
process.stderr.write(
|
|
206
|
+
`${FRAMEWORK_NAME}: the Mate editor extension was not updated; run \`${FRAMEWORK_NAME} vscode setup\`.\n`,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
191
209
|
/** Managed launches run standalone; only a long-lived service keeps the replaced plugin loaded. */
|
|
192
210
|
console.log(
|
|
193
211
|
"Restart any running OpenCode service to load the new plugin: `opencode service restart`.",
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
import { version as coreVersion } from "../../../../package.json";
|
|
4
|
+
import { FRAMEWORK_NAME } from "../../../framework";
|
|
5
|
+
import { resolveEditorBinary } from "../../../lib/orchestrator/editor";
|
|
6
|
+
import { resolveVsix, VsixError, vsixResolverDeps, type VsixResolverDeps } from "./vsix";
|
|
7
|
+
|
|
8
|
+
const EDITORS = ["code", "cursor"] as const;
|
|
9
|
+
type Editor = (typeof EDITORS)[number];
|
|
10
|
+
|
|
11
|
+
const EDITOR_NAMES: Record<Editor, string> = { code: "VS Code", cursor: "Cursor" };
|
|
12
|
+
|
|
13
|
+
/** The id the editors list the installed extension under (`publisher.name` of the VSIX manifest). */
|
|
14
|
+
const EXTENSION_ID = "uniqbit.mate";
|
|
15
|
+
|
|
16
|
+
const USAGE = `Usage: ${FRAMEWORK_NAME} vscode setup [--editor code|cursor] [--vsix <path>] [--if-installed]`;
|
|
17
|
+
|
|
18
|
+
interface VscodeSetupArgs {
|
|
19
|
+
editor?: Editor;
|
|
20
|
+
vsix?: string;
|
|
21
|
+
/** Only editors that already have the extension; none is no error. */
|
|
22
|
+
ifInstalled?: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function parseVscodeSetupArgs(argv: string[]): VscodeSetupArgs | { error: string } {
|
|
26
|
+
const args: VscodeSetupArgs = {};
|
|
27
|
+
for (let index = 0; index < argv.length; index += 1) {
|
|
28
|
+
const arg = argv[index]!;
|
|
29
|
+
const [flag, inline] = arg.startsWith("--") && arg.includes("=") ? arg.split(/=(.*)/s) : [arg];
|
|
30
|
+
if (arg === "--if-installed") {
|
|
31
|
+
args.ifInstalled = true;
|
|
32
|
+
} else if (flag === "--editor" || flag === "--vsix") {
|
|
33
|
+
const value = inline ?? argv[++index];
|
|
34
|
+
if (!value) return { error: `${flag} requires a value` };
|
|
35
|
+
if (flag === "--vsix") {
|
|
36
|
+
args.vsix = value;
|
|
37
|
+
} else if ((EDITORS as readonly string[]).includes(value)) {
|
|
38
|
+
args.editor = value as Editor;
|
|
39
|
+
} else {
|
|
40
|
+
return { error: `unknown editor: ${value} (expected ${EDITORS.join(" or ")})` };
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
return { error: `unknown vscode setup option: ${arg}` };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return args;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface VscodeSetupDeps {
|
|
50
|
+
resolveEditor: (cli: Editor) => string | null;
|
|
51
|
+
/** Runs `<binary> --install-extension <vsix> --force`; returns the exit status and output. */
|
|
52
|
+
install: (binary: string, vsix: string) => { ok: boolean; output: string };
|
|
53
|
+
/** `<binary> --list-extensions`; null when it cannot be listed. */
|
|
54
|
+
installedExtensions: (binary: string) => string[] | null;
|
|
55
|
+
vsix: VsixResolverDeps;
|
|
56
|
+
version: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const vscodeSetupDeps: VscodeSetupDeps = {
|
|
60
|
+
resolveEditor: resolveEditorBinary,
|
|
61
|
+
install: (binary, vsix) => {
|
|
62
|
+
const result = spawnSync(binary, ["--install-extension", vsix, "--force"], {
|
|
63
|
+
encoding: "utf8",
|
|
64
|
+
});
|
|
65
|
+
const output = `${result.stdout ?? ""}${result.stderr ?? ""}${result.error?.message ?? ""}`;
|
|
66
|
+
return { ok: result.status === 0, output: output.trim() };
|
|
67
|
+
},
|
|
68
|
+
installedExtensions: (binary) => {
|
|
69
|
+
const result = spawnSync(binary, ["--list-extensions"], { encoding: "utf8", timeout: 30_000 });
|
|
70
|
+
return result.status === 0 ? result.stdout.split("\n").map((line) => line.trim()) : null;
|
|
71
|
+
},
|
|
72
|
+
vsix: vsixResolverDeps,
|
|
73
|
+
version: coreVersion,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
function fail(message: string, usage = false): void {
|
|
77
|
+
console.error(`${FRAMEWORK_NAME}: ${message}`);
|
|
78
|
+
if (usage) console.error(USAGE);
|
|
79
|
+
process.exitCode = 1;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* `mate vscode setup`: installs the Mate extension into every resolved VS Code
|
|
84
|
+
* and Cursor CLI; with `--if-installed`, only into those that already have it
|
|
85
|
+
* (how `mate update` brings the extension to the new version).
|
|
86
|
+
*/
|
|
87
|
+
export async function runVscodeSetupCommand(
|
|
88
|
+
argv: string[],
|
|
89
|
+
deps: VscodeSetupDeps = vscodeSetupDeps,
|
|
90
|
+
): Promise<void> {
|
|
91
|
+
const parsed = parseVscodeSetupArgs(argv);
|
|
92
|
+
if ("error" in parsed) return fail(parsed.error, true);
|
|
93
|
+
|
|
94
|
+
const resolved = (parsed.editor ? [parsed.editor] : [...EDITORS]).map((editor) => ({
|
|
95
|
+
editor,
|
|
96
|
+
binary: deps.resolveEditor(editor),
|
|
97
|
+
}));
|
|
98
|
+
const found = resolved.filter(
|
|
99
|
+
(entry): entry is { editor: Editor; binary: string } => entry.binary !== null,
|
|
100
|
+
);
|
|
101
|
+
if (parsed.ifInstalled) {
|
|
102
|
+
const editors = found.filter(({ binary }) =>
|
|
103
|
+
deps.installedExtensions(binary)?.some((id) => id.toLowerCase() === EXTENSION_ID),
|
|
104
|
+
);
|
|
105
|
+
if (editors.length === 0) return;
|
|
106
|
+
return installInto(editors, parsed.vsix, deps);
|
|
107
|
+
}
|
|
108
|
+
if (found.length === 0) {
|
|
109
|
+
const wanted = parsed.editor ? `\`${parsed.editor}\`` : "`code` or `cursor`";
|
|
110
|
+
return fail(
|
|
111
|
+
`no editor CLI found: ${wanted} is not on PATH. In the editor, run "Shell Command: Install '${parsed.editor ?? "code"}' command in PATH", then retry.`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
for (const { editor, binary } of resolved) {
|
|
116
|
+
if (binary === null)
|
|
117
|
+
console.log(` ${EDITOR_NAMES[editor]}: not found (\`${editor}\` is not on PATH)`);
|
|
118
|
+
}
|
|
119
|
+
return installInto(found, parsed.vsix, deps);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
async function installInto(
|
|
123
|
+
editors: Array<{ editor: Editor; binary: string }>,
|
|
124
|
+
vsixArg: string | undefined,
|
|
125
|
+
deps: VscodeSetupDeps,
|
|
126
|
+
): Promise<void> {
|
|
127
|
+
let vsix: string;
|
|
128
|
+
try {
|
|
129
|
+
vsix = await resolveVsix({ vsix: vsixArg, version: deps.version }, deps.vsix);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (error instanceof VsixError) return fail(error.message);
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
let installed = 0;
|
|
136
|
+
for (const { editor, binary } of editors) {
|
|
137
|
+
const result = deps.install(binary, vsix);
|
|
138
|
+
if (result.ok) {
|
|
139
|
+
installed += 1;
|
|
140
|
+
console.log(` ${EDITOR_NAMES[editor]}: installed`);
|
|
141
|
+
} else {
|
|
142
|
+
console.log(` ${EDITOR_NAMES[editor]}: failed${result.output ? ` — ${result.output}` : ""}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (installed === 0) return fail("the extension could not be installed into any editor");
|
|
146
|
+
console.log("Reload open editor windows to load the Mate sidebar.");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export async function runVscodeCommand(subcommand: string | undefined, rest: string[]) {
|
|
150
|
+
if (subcommand === "setup") {
|
|
151
|
+
await runVscodeSetupCommand(rest);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
fail(`unknown vscode subcommand: ${subcommand ?? ""}`.trimEnd(), true);
|
|
155
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { execFile as execFileCb } from "node:child_process";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { promisify } from "node:util";
|
|
5
|
+
|
|
6
|
+
import { FRAMEWORK_NAME } from "../../../framework";
|
|
7
|
+
import { packPublicPackage } from "../../../lib/public-npm";
|
|
8
|
+
import { mateHome } from "../../../runtime/runtime-directory";
|
|
9
|
+
|
|
10
|
+
const VSCODE_PACKAGE = "@uniqbit/mate-vscode";
|
|
11
|
+
export const VSIX_FILE = "mate-vscode.vsix";
|
|
12
|
+
|
|
13
|
+
const execFile = promisify(execFileCb);
|
|
14
|
+
|
|
15
|
+
export interface VsixResolverDeps {
|
|
16
|
+
exists: (file: string) => Promise<boolean>;
|
|
17
|
+
/** Downloads the package tarball into `destination`, returns its path. */
|
|
18
|
+
pack: (spec: string, destination: string) => Promise<string>;
|
|
19
|
+
/** Extracts `package/<VSIX_FILE>` from the tarball to `target`. */
|
|
20
|
+
extract: (tarball: string, target: string) => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function extractVsix(tarball: string, target: string): Promise<void> {
|
|
24
|
+
const dir = path.dirname(target);
|
|
25
|
+
await execFile("tar", ["-xzf", tarball, "-C", dir, `package/${VSIX_FILE}`]);
|
|
26
|
+
await fs.rename(path.join(dir, "package", VSIX_FILE), target);
|
|
27
|
+
await fs.rm(path.join(dir, "package"), { recursive: true, force: true });
|
|
28
|
+
await fs.rm(tarball, { force: true });
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const vsixResolverDeps: VsixResolverDeps = {
|
|
32
|
+
exists: (file) =>
|
|
33
|
+
fs.stat(file).then(
|
|
34
|
+
(stat) => stat.isFile(),
|
|
35
|
+
() => false,
|
|
36
|
+
),
|
|
37
|
+
pack: (spec, destination) => packPublicPackage(spec, destination),
|
|
38
|
+
extract: extractVsix,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function vsixCacheDir(version: string, homeDir?: string): string {
|
|
42
|
+
return path.join(mateHome(homeDir), "cache", "vscode", version);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export class VsixError extends Error {}
|
|
46
|
+
|
|
47
|
+
/** `--vsix` wins; otherwise the cached copy for `version`; otherwise download it from public npm. */
|
|
48
|
+
export async function resolveVsix(
|
|
49
|
+
options: { vsix?: string; version: string; cacheDir?: string; cwd?: string },
|
|
50
|
+
deps: VsixResolverDeps = vsixResolverDeps,
|
|
51
|
+
): Promise<string> {
|
|
52
|
+
if (options.vsix) {
|
|
53
|
+
const file = path.resolve(options.cwd ?? process.cwd(), options.vsix);
|
|
54
|
+
if (!(await deps.exists(file))) throw new VsixError(`VSIX not found: ${file}`);
|
|
55
|
+
return file;
|
|
56
|
+
}
|
|
57
|
+
const cacheDir = options.cacheDir ?? vsixCacheDir(options.version);
|
|
58
|
+
const cached = path.join(cacheDir, VSIX_FILE);
|
|
59
|
+
if (await deps.exists(cached)) return cached;
|
|
60
|
+
|
|
61
|
+
const spec = `${VSCODE_PACKAGE}@${options.version}`;
|
|
62
|
+
try {
|
|
63
|
+
await fs.mkdir(cacheDir, { recursive: true });
|
|
64
|
+
const tarball = await deps.pack(spec, cacheDir);
|
|
65
|
+
await deps.extract(tarball, cached);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw new VsixError(
|
|
68
|
+
`could not download ${spec}: ${(error as Error).message.trim()}\n` +
|
|
69
|
+
`Install a local build instead with \`${FRAMEWORK_NAME} vscode setup --vsix <path>\`.`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
return cached;
|
|
73
|
+
}
|
|
@@ -7,9 +7,11 @@ import { parse } from "yaml";
|
|
|
7
7
|
|
|
8
8
|
import { FRAMEWORK_NAME } from "../../../framework";
|
|
9
9
|
import { gitEnvironment } from "../../../runtime/companion-git";
|
|
10
|
+
import { checkoutCommonDir } from "../../../runtime/git-layout";
|
|
10
11
|
import type { RootKind } from "../../../lib/orchestrator/root-context";
|
|
11
12
|
import {
|
|
12
13
|
collectWorkspaceInventory,
|
|
14
|
+
type WorkspaceInventoryPairingEntry,
|
|
13
15
|
type WorkspaceInventoryV1,
|
|
14
16
|
} from "../../../lib/orchestrator/workspace-inventory";
|
|
15
17
|
import {
|
|
@@ -72,6 +74,32 @@ const defaultDeps: WorkingCleanupCommandDeps = {
|
|
|
72
74
|
cleanup: cleanupWorkingRepository,
|
|
73
75
|
};
|
|
74
76
|
|
|
77
|
+
/**
|
|
78
|
+
* The pairings of the Checkout at `repoPath`: by path, else by clone for
|
|
79
|
+
* another Checkout of a linked clone (design Decision 7). The recorded clone
|
|
80
|
+
* still counts once the entry's folder is gone.
|
|
81
|
+
*/
|
|
82
|
+
async function pairingsOf(
|
|
83
|
+
repoPath: string,
|
|
84
|
+
pairings: WorkspaceInventoryPairingEntry[],
|
|
85
|
+
): Promise<{ matches: WorkspaceInventoryPairingEntry[]; byClone: boolean }> {
|
|
86
|
+
const resolved = await Promise.all(
|
|
87
|
+
pairings.map(async (pairing) => ({
|
|
88
|
+
pairing,
|
|
89
|
+
repositoryPath: await canonicalPath(pairing.repository.path),
|
|
90
|
+
})),
|
|
91
|
+
);
|
|
92
|
+
const atPath = resolved.filter(({ repositoryPath }) => repositoryPath === repoPath);
|
|
93
|
+
if (atPath.length > 0) return { matches: atPath.map(({ pairing }) => pairing), byClone: false };
|
|
94
|
+
const clone = checkoutCommonDir(repoPath);
|
|
95
|
+
const ofClone = resolved.filter(
|
|
96
|
+
({ pairing, repositoryPath }) =>
|
|
97
|
+
clone !== null &&
|
|
98
|
+
(checkoutCommonDir(repositoryPath) ?? pairing.repository.gitCommonDir) === clone,
|
|
99
|
+
);
|
|
100
|
+
return { matches: ofClone.map(({ pairing }) => pairing), byClone: true };
|
|
101
|
+
}
|
|
102
|
+
|
|
75
103
|
export async function runWorkingCleanupCommand(
|
|
76
104
|
argv: string[],
|
|
77
105
|
deps: WorkingCleanupCommandDeps = defaultDeps,
|
|
@@ -97,16 +125,7 @@ export async function runWorkingCleanupCommand(
|
|
|
97
125
|
process.exitCode = 1;
|
|
98
126
|
return;
|
|
99
127
|
}
|
|
100
|
-
const
|
|
101
|
-
const resolvedPairings = await Promise.all(
|
|
102
|
-
inventory.pairings.map(async (pairing) => ({
|
|
103
|
-
pairing,
|
|
104
|
-
repositoryPath: await canonicalPath(pairing.repository.path),
|
|
105
|
-
})),
|
|
106
|
-
);
|
|
107
|
-
const matches = resolvedPairings
|
|
108
|
-
.filter(({ repositoryPath }) => repositoryPath === repoPath)
|
|
109
|
-
.map(({ pairing }) => pairing);
|
|
128
|
+
const { matches, byClone } = await pairingsOf(repoPath, (await deps.collectInventory()).pairings);
|
|
110
129
|
if (matches.length === 0) {
|
|
111
130
|
process.stderr.write(
|
|
112
131
|
`${FRAMEWORK_NAME}: working cleanup must run from a linked Git working repository\n`,
|
|
@@ -134,4 +153,9 @@ export async function runWorkingCleanupCommand(
|
|
|
134
153
|
...(keptDetail ? [keptDetail] : []),
|
|
135
154
|
];
|
|
136
155
|
console.log(`${FRAMEWORK_NAME}: cleaned working repository (${details.join("; ")})`);
|
|
156
|
+
if (byClone) {
|
|
157
|
+
console.log(
|
|
158
|
+
`${FRAMEWORK_NAME}: ${repoPath} is another Checkout of ${matches[0]!.repository.id}; ${FRAMEWORK_NAME} adopts it again the next time it runs here.`,
|
|
159
|
+
);
|
|
160
|
+
}
|
|
137
161
|
}
|