@uniqbit/mate-core 1.0.0 → 1.0.1-canary.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
- package/package.json +1 -1
- package/src/cli/agent-selector.ts +16 -0
- package/src/cli/commands/artifact/finish/command.ts +18 -6
- package/src/cli/commands/artifact/finish/engine.ts +3 -1
- package/src/cli/commands/artifact/finish/git.ts +4 -2
- package/src/cli/commands/artifact/pending/discovery.ts +2 -2
- package/src/cli/commands/companion/link.ts +3 -2
- package/src/cli/commands/triage.ts +11 -23
- package/src/cli/commands/vscode/release-vsix.json +2 -2
- package/src/cli/commands/workflow/workflow.ts +3 -2
- package/src/cli/companion-selector.ts +26 -0
- package/src/cli/main.ts +12 -2
- package/src/hooks/validate-artifact-path.ts +79 -17
- package/src/lib/components/select-one.tsx +122 -0
- package/src/lib/delivery/record-delivery.ts +14 -0
- package/src/lib/delivery/staging/apply-chain.ts +60 -30
- package/src/lib/delivery/staging/pending.ts +13 -0
- package/src/lib/delivery/staging/project.ts +21 -6
- package/src/lib/delivery/staging/publish.ts +10 -11
- package/src/lib/delivery/staging/submit.ts +2 -8
- package/src/lib/orchestrator/companion-git-sync.ts +53 -24
- package/src/lib/workflow/handoff.ts +1 -1
- package/src/lib/workflow/position.ts +29 -2
- package/src/lib/workset/worktree.ts +1 -0
- package/src/opencode/companion-hooks.ts +3 -1
- package/src/runtime/artifact-refusal.ts +17 -7
- package/src/runtime/companion-guidance.ts +2 -2
- package/src/runtime/companion-sync.ts +21 -1
- package/src/runtime/shell-heredoc.ts +67 -26
- package/src/runtime/shell-variables.ts +257 -0
- package/src/templates/capabilities/openspec-cap/mate-full/schema.yaml +3 -0
- package/src/templates/capabilities/openspec-cap/mate-minimal/schema.yaml +4 -0
- package/src/templates/capabilities/react-doctor/mate-react-doctor/SKILL.md +20 -2
- package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +2 -2
- package/src/templates/mate-skills/agents/mate-publish-artifact/references/openspec.md +6 -6
- package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +4 -4
- package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +2 -2
- package/src/templates/mate-skills/claude/mate-publish-artifact/references/openspec.md +6 -6
- package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +4 -4
- package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +30 -30
- package/src/tools/setup/capabilities/openspec.ts +3 -1
- package/src/tools/setup/capabilities/tokensave.ts +8 -1
- package/src/tools/setup/mate.ts +2 -1
- package/src/tools/setup.ts +22 -1
- package/src/cli/companion-selector.tsx +0 -139
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { nulPaths, type CompanionGit } from "../../../runtime/companion-git";
|
|
2
2
|
import { inboxText } from "../../../runtime/pending-records";
|
|
3
3
|
import type { ArtifactType, ValidationFailure } from "./artifact-type";
|
|
4
|
-
import { sourcePathOf } from "./pending";
|
|
4
|
+
import { resubmitAccepts, sourcePathOf, staleParts, STALE_SCAN_LIMIT } from "./pending";
|
|
5
5
|
import type { DeltaFailure } from "./replay";
|
|
6
6
|
|
|
7
7
|
/** A change to apply, with the commit its delta was written against (null: unknown). */
|
|
@@ -10,9 +10,12 @@ export interface ChainMember {
|
|
|
10
10
|
base: string | null;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Why a chain cannot be applied, with the change that failed when known. A `stale` failure holds
|
|
15
|
+
* every stale part of that change, up to {@link STALE_SCAN_LIMIT}.
|
|
16
|
+
*/
|
|
14
17
|
export type ChainFailure =
|
|
15
|
-
| { kind: "stale"; change: string;
|
|
18
|
+
| { kind: "stale"; change: string; parts: [DeltaFailure, ...DeltaFailure[]] }
|
|
16
19
|
| { kind: "apply"; change: string; failure?: DeltaFailure; detail: string }
|
|
17
20
|
| { kind: "invalid"; change: string | null; failure: ValidationFailure };
|
|
18
21
|
|
|
@@ -70,12 +73,11 @@ export async function applyChain(options: ApplyChainOptions): Promise<AppliedCha
|
|
|
70
73
|
const records: string[] = [];
|
|
71
74
|
for (const member of members) {
|
|
72
75
|
// A part someone changed since goes to a human: applying would overwrite that change.
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
if (stale) return { kind: "stale", change: member.name, failure: stale };
|
|
76
|
+
const [first, ...rest] = member.base
|
|
77
|
+
? // oxlint-disable-next-line no-await-in-loop -- each change applies on the one before
|
|
78
|
+
await staleParts(type, work, ref, sourcePathOf(type, member.name), member.base, start)
|
|
79
|
+
: [];
|
|
80
|
+
if (first) return { kind: "stale", change: member.name, parts: [first, ...rest] };
|
|
79
81
|
// oxlint-disable-next-line no-await-in-loop -- same change
|
|
80
82
|
const applied = await type.apply(dir, member.name);
|
|
81
83
|
if (!applied.ok) {
|
|
@@ -106,12 +108,14 @@ export function isChainFailure(result: AppliedChain | ChainFailure): result is C
|
|
|
106
108
|
return "kind" in result;
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
/** Paths a failure concerns: the spec a delta names, or the invalid file. */
|
|
110
111
|
export function failurePaths(
|
|
111
112
|
failure: ChainFailure,
|
|
112
113
|
pathOf: (capability: string) => string,
|
|
113
114
|
): string[] {
|
|
114
115
|
if (failure.kind === "invalid") return [failure.failure.path];
|
|
116
|
+
if (failure.kind === "stale") {
|
|
117
|
+
return [...new Set(failure.parts.map((part) => pathOf(part.capability)))];
|
|
118
|
+
}
|
|
115
119
|
return failure.failure ? [pathOf(failure.failure.capability)] : [];
|
|
116
120
|
}
|
|
117
121
|
|
|
@@ -125,7 +129,7 @@ export function describeFailure(failure: ChainFailure, defaultBranch: string): s
|
|
|
125
129
|
}
|
|
126
130
|
const change = inboxText(failure.change);
|
|
127
131
|
if (failure.kind === "stale") {
|
|
128
|
-
return `${change}:
|
|
132
|
+
return `${change}: ${partList(failure.parts)} changed on ${defaultBranch} since the delta was written`;
|
|
129
133
|
}
|
|
130
134
|
if (!failure.failure) {
|
|
131
135
|
return `${change}: it no longer applies to ${defaultBranch} (${inboxText(failure.detail)})`;
|
|
@@ -144,33 +148,59 @@ function submitCommand(names: readonly string[]): string {
|
|
|
144
148
|
return `\`mate artifact submit${names.map((name) => ` ${shellQuote(name)}`).join("")}\``;
|
|
145
149
|
}
|
|
146
150
|
|
|
151
|
+
function partList(parts: readonly DeltaFailure[]): string {
|
|
152
|
+
return parts
|
|
153
|
+
.map((part) => `"${inboxText(part.requirement)}" in ${inboxText(part.capability)}`)
|
|
154
|
+
.join(", ");
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const printable = (name: string): boolean => inboxText(name) === name;
|
|
158
|
+
|
|
159
|
+
function resolveCommand(change: string, overwritten: readonly DeltaFailure[]): string | null {
|
|
160
|
+
const resolvable = (part: DeltaFailure): boolean =>
|
|
161
|
+
printable(part.capability) &&
|
|
162
|
+
printable(part.requirement) &&
|
|
163
|
+
part.versions !== undefined &&
|
|
164
|
+
part.versions.ours !== null &&
|
|
165
|
+
part.versions.theirs !== null;
|
|
166
|
+
if (overwritten.length === 0 || !printable(change) || !overwritten.every(resolvable)) {
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
const triples = overwritten.map((part, index) => {
|
|
170
|
+
const file = overwritten.length > 1 ? `<file${index + 1}>` : "<file>";
|
|
171
|
+
return ` --capability ${shellQuote(part.capability)} --requirement ${shellQuote(part.requirement)} --file ${file}`;
|
|
172
|
+
});
|
|
173
|
+
return `\`mate artifact resolve ${shellQuote(change)}${triples.join("")}\``;
|
|
174
|
+
}
|
|
175
|
+
|
|
147
176
|
/**
|
|
148
177
|
* How to get past a failure. With `resubmit`, the changes a submit named, the remedy ends with
|
|
149
178
|
* submitting them again instead of publishing: submit's pre-flight found the failure.
|
|
150
179
|
*/
|
|
151
180
|
export function failureRemedy(failure: ChainFailure, resubmit?: readonly string[]): string {
|
|
152
|
-
const
|
|
153
|
-
// A
|
|
154
|
-
const
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (
|
|
160
|
-
failure.kind === "stale" &&
|
|
161
|
-
printable &&
|
|
162
|
-
versions &&
|
|
163
|
-
versions.ours !== null &&
|
|
164
|
-
versions.theirs !== null
|
|
165
|
-
) {
|
|
181
|
+
const stale = failure.kind === "stale" ? failure : null;
|
|
182
|
+
// A part removed on the default branch only a delta fix gets past: OpenSpec cannot apply to it.
|
|
183
|
+
const removed = stale?.parts.some((part) => part.versions?.theirs === null) ?? false;
|
|
184
|
+
const accepts = stale !== null && !removed && resubmitAccepts(stale.parts);
|
|
185
|
+
const overwritten = stale?.parts.filter((part) => part.overwrites !== false) ?? [];
|
|
186
|
+
const resolve = stale && !removed ? resolveCommand(stale.change, overwritten) : null;
|
|
187
|
+
if (stale && resolve) {
|
|
166
188
|
const next = resubmit ? `run ${submitCommand(resubmit)} again` : "publish again";
|
|
167
|
-
|
|
189
|
+
const more =
|
|
190
|
+
stale.parts.length >= STALE_SCAN_LIMIT
|
|
191
|
+
? " (add a triple per requirement it reports unresolved)"
|
|
192
|
+
: "";
|
|
193
|
+
const rest = stale.parts.filter((part) => !overwritten.includes(part));
|
|
194
|
+
const accepted =
|
|
195
|
+
rest.length > 0 ? ` That also accepts what the delta does to ${partList(rest)}.` : "";
|
|
196
|
+
return `Resolve it from any machine: write each requirement's body as it should read (without its \`### Requirement:\` heading) to a file, run ${resolve}${more}, then ${next}.${accepted}`;
|
|
168
197
|
}
|
|
169
198
|
const change = failure.change === null ? "the change that changes it" : inboxText(failure.change);
|
|
170
|
-
const keep =
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
: "
|
|
199
|
+
const keep = !accepts
|
|
200
|
+
? ""
|
|
201
|
+
: (stale?.parts.length ?? 0) > 1
|
|
202
|
+
? " To keep what the delta does to them, submit it again unchanged: that accepts the conflict."
|
|
203
|
+
: " To keep it as it is, submit it again unchanged: that accepts the conflict.";
|
|
174
204
|
// Submitting the fixed change runs the pre-flight again; only other named changes need a rerun.
|
|
175
205
|
const others = resubmit?.filter((name) => name !== failure.change) ?? [];
|
|
176
206
|
const next = !resubmit
|
|
@@ -447,6 +447,19 @@ export async function staleParts(
|
|
|
447
447
|
return found;
|
|
448
448
|
}
|
|
449
449
|
|
|
450
|
+
/**
|
|
451
|
+
* True when submitting the change again unchanged accepts a block over `parts`, its
|
|
452
|
+
* {@link staleParts}: each replaces no one's text. False when nothing is stale (the block has
|
|
453
|
+
* another cause, which a new base would not lift) or the scan hit {@link STALE_SCAN_LIMIT}.
|
|
454
|
+
*/
|
|
455
|
+
export function resubmitAccepts(parts: readonly Pick<DeltaFailure, "overwrites">[]): boolean {
|
|
456
|
+
return (
|
|
457
|
+
parts.length > 0 &&
|
|
458
|
+
parts.length < STALE_SCAN_LIMIT &&
|
|
459
|
+
parts.every((part) => part.overwrites === false)
|
|
460
|
+
);
|
|
461
|
+
}
|
|
462
|
+
|
|
450
463
|
/**
|
|
451
464
|
* `changes` ordered so each comes after the ones it declares in `dependsOn` among them, else in
|
|
452
465
|
* their given order. A cycle keeps the given order for its members.
|
|
@@ -24,7 +24,7 @@ import {
|
|
|
24
24
|
type AppliedChain,
|
|
25
25
|
type ChainFailure,
|
|
26
26
|
} from "./apply-chain";
|
|
27
|
-
import { sourceDir, type ArtifactType } from "./artifact-type";
|
|
27
|
+
import { recordDir, sourceDir, type ArtifactType } from "./artifact-type";
|
|
28
28
|
import {
|
|
29
29
|
deltaBase,
|
|
30
30
|
orderByDependencies,
|
|
@@ -317,6 +317,12 @@ export async function projectChange(
|
|
|
317
317
|
}
|
|
318
318
|
}
|
|
319
319
|
|
|
320
|
+
async function archivedHere(companionPath: string, type: ArtifactType): Promise<Set<string>> {
|
|
321
|
+
const dir = recordDir(companionPath, type);
|
|
322
|
+
const ids = dir ? await fs.readdir(dir).catch(() => [] as string[]) : [];
|
|
323
|
+
return new Set(ids.filter(type.isRecordId).map(type.recordName));
|
|
324
|
+
}
|
|
325
|
+
|
|
320
326
|
async function project(
|
|
321
327
|
companionPath: string,
|
|
322
328
|
name: string,
|
|
@@ -341,11 +347,20 @@ async function project(
|
|
|
341
347
|
return writeProjection(dir, derived, deps.outRoot ?? os.tmpdir());
|
|
342
348
|
});
|
|
343
349
|
if (run.status === "missing") {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
350
|
+
const archived = await archivedHere(companionPath, type);
|
|
351
|
+
const absent = run.missing.filter((dependency) => !archived.has(dependency));
|
|
352
|
+
const reasons: string[] = [];
|
|
353
|
+
if (absent.length > 0) {
|
|
354
|
+
reasons.push(
|
|
355
|
+
`${name} depends on ${absent.map(inboxText).join(", ")}, which is neither here, submitted nor published.`,
|
|
356
|
+
);
|
|
357
|
+
}
|
|
358
|
+
for (const dependency of run.missing.filter((missing) => archived.has(missing))) {
|
|
359
|
+
reasons.push(
|
|
360
|
+
`${name} depends on ${inboxText(dependency)}, which is archived in this checkout but not published; run \`${FRAMEWORK_NAME} artifact publish "${inboxText(dependency)}"\` to make it count.`,
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
return failed(name, "error", `mate: ${reasons.join(" ")}`);
|
|
349
364
|
}
|
|
350
365
|
if (run.status === "empty") {
|
|
351
366
|
return {
|
|
@@ -126,7 +126,10 @@ export interface PublicationResult {
|
|
|
126
126
|
dependencies?: PublicationResult[];
|
|
127
127
|
conflictedPaths: string[];
|
|
128
128
|
warnings: string[];
|
|
129
|
+
/** The first of {@link conflicts}, kept for readers of one conflict. */
|
|
129
130
|
conflict?: PublicationConflict;
|
|
131
|
+
/** One per stale requirement of the failing change, in scan order, at most `STALE_SCAN_LIMIT`. */
|
|
132
|
+
conflicts?: PublicationConflict[];
|
|
130
133
|
/** The conflict is recorded as `blocked` in the change's Delivery Record on the pending branch. */
|
|
131
134
|
blocked?: boolean;
|
|
132
135
|
secretFindings?: SecretFinding[];
|
|
@@ -828,22 +831,18 @@ function chainConflict(
|
|
|
828
831
|
tip: string,
|
|
829
832
|
): Outcome {
|
|
830
833
|
const reason = describeFailure(failure, run.remote.defaultBranch);
|
|
831
|
-
const
|
|
834
|
+
const conflicts: PublicationConflict[] =
|
|
835
|
+
failure.kind === "stale"
|
|
836
|
+
? failure.parts.flatMap(({ capability, requirement, versions }) =>
|
|
837
|
+
versions ? [{ change: failure.change, capability, requirement, ...versions }] : [],
|
|
838
|
+
)
|
|
839
|
+
: [];
|
|
832
840
|
return {
|
|
833
841
|
...base,
|
|
834
842
|
status: "conflict",
|
|
835
843
|
conflictedPaths: failurePaths(failure, capabilitySpecPath),
|
|
836
844
|
blocker: { change: failure.change, reason, tip },
|
|
837
|
-
...(
|
|
838
|
-
? {
|
|
839
|
-
conflict: {
|
|
840
|
-
change: failure.change,
|
|
841
|
-
capability: failure.failure.capability,
|
|
842
|
-
requirement: failure.failure.requirement,
|
|
843
|
-
...versions,
|
|
844
|
-
},
|
|
845
|
-
}
|
|
846
|
-
: {}),
|
|
845
|
+
...(conflicts[0] ? { conflict: conflicts[0], conflicts } : {}),
|
|
847
846
|
message: `mate: ${base.group} cannot be published: ${reason}. Nothing was published and the submitted changes are unchanged. ${failureRemedy(failure)}`,
|
|
848
847
|
};
|
|
849
848
|
}
|
|
@@ -46,7 +46,7 @@ import {
|
|
|
46
46
|
import { isSettled } from "../refresh";
|
|
47
47
|
import { recordDir, sourceDir, type ArtifactType } from "./artifact-type";
|
|
48
48
|
import { deliveryGroupFor, type DeliveryGroupName } from "./naming";
|
|
49
|
-
import { sourcePathOf, staleParts
|
|
49
|
+
import { resubmitAccepts, sourcePathOf, staleParts } from "./pending";
|
|
50
50
|
import { commitToPending } from "./pending-edit";
|
|
51
51
|
import {
|
|
52
52
|
defaultRef,
|
|
@@ -424,13 +424,7 @@ export async function acceptsBlock(
|
|
|
424
424
|
base: string,
|
|
425
425
|
tip: string,
|
|
426
426
|
): Promise<boolean> {
|
|
427
|
-
|
|
428
|
-
// Nothing stale: the block has another cause, which a new base would not lift.
|
|
429
|
-
return (
|
|
430
|
-
stale.length > 0 &&
|
|
431
|
-
stale.length < STALE_SCAN_LIMIT &&
|
|
432
|
-
stale.every((part) => part.overwrites === false)
|
|
433
|
-
);
|
|
427
|
+
return resubmitAccepts(await staleParts(type, work, ref, folder, base, tip));
|
|
434
428
|
}
|
|
435
429
|
|
|
436
430
|
/** {@link acceptsBlock} for the folder as staged in the pending checkout `work`. */
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
companionGit,
|
|
8
8
|
describeGitFailure,
|
|
9
9
|
isAuthenticationFailure,
|
|
10
|
+
LITERAL_PATHSPECS,
|
|
11
|
+
nulPaths,
|
|
10
12
|
outputLines,
|
|
11
13
|
type GitResult,
|
|
12
14
|
type UpstreamTarget,
|
|
@@ -25,6 +27,7 @@ import {
|
|
|
25
27
|
import { FRAMEWORK_NAME } from "../../framework";
|
|
26
28
|
import { artifactTypes, defaultArtifactType } from "../delivery/staging/registry";
|
|
27
29
|
import { loadWorkflow } from "../workflow/declaration";
|
|
30
|
+
import { mateManagedSkillNames } from "../../tools/setup";
|
|
28
31
|
import { LaunchPreflightError } from "./types";
|
|
29
32
|
|
|
30
33
|
type GitCommandResult = GitResult;
|
|
@@ -121,11 +124,24 @@ const MANAGED_ROOTS = [".mate", ".opencode", ".claude", ".agents", ".graphify"];
|
|
|
121
124
|
|
|
122
125
|
type SyncTarget = UpstreamTarget;
|
|
123
126
|
|
|
124
|
-
|
|
125
|
-
|
|
127
|
+
const SKILL_ROOTS = new Set([".claude/skills", ".agents/skills", ".opencode/skills"]);
|
|
128
|
+
|
|
129
|
+
function normalizedPath(filePath: string): string {
|
|
130
|
+
return filePath.replaceAll("\\", "/").replace(/^\.\//, "");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function isManagedPath(normalized: string): boolean {
|
|
126
134
|
return MANAGED_ROOTS.some((root) => normalized === root || normalized.startsWith(`${root}/`));
|
|
127
135
|
}
|
|
128
136
|
|
|
137
|
+
function isForcedPath(filePath: string, mateSkillNames: ReadonlySet<string>): boolean {
|
|
138
|
+
const normalized = normalizedPath(filePath);
|
|
139
|
+
if (!isManagedPath(normalized)) return false;
|
|
140
|
+
const [root, folder, entry] = normalized.split("/");
|
|
141
|
+
if (entry === undefined || !SKILL_ROOTS.has(`${root}/${folder}`)) return true;
|
|
142
|
+
return mateSkillNames.has(entry);
|
|
143
|
+
}
|
|
144
|
+
|
|
129
145
|
export class CompanionGitSync {
|
|
130
146
|
constructor(private readonly options: CompanionGitSyncOptions = {}) {}
|
|
131
147
|
|
|
@@ -308,8 +324,10 @@ export class CompanionGitSync {
|
|
|
308
324
|
"--no-progress",
|
|
309
325
|
"--no-edit",
|
|
310
326
|
]);
|
|
327
|
+
if (merge.status === 0 && !stashRef) return;
|
|
328
|
+
const skillNames = await mateManagedSkillNames(companionPath);
|
|
311
329
|
if (merge.status !== 0) {
|
|
312
|
-
await this.resolveManagedConflicts(companionPath, target.ref);
|
|
330
|
+
await this.resolveManagedConflicts(companionPath, target.ref, skillNames);
|
|
313
331
|
const conflicts = await this.unresolvedPaths(companionPath);
|
|
314
332
|
if (conflicts.length > 0) {
|
|
315
333
|
throw this.failure(
|
|
@@ -334,7 +352,7 @@ export class CompanionGitSync {
|
|
|
334
352
|
const apply = await this.command(companionPath, ["stash", "apply", "--index", stashRef]);
|
|
335
353
|
if (apply.status !== 0) {
|
|
336
354
|
const applyConflicts = await this.unresolvedPaths(companionPath);
|
|
337
|
-
await this.resolveManagedConflicts(companionPath, target.ref);
|
|
355
|
+
await this.resolveManagedConflicts(companionPath, target.ref, skillNames);
|
|
338
356
|
const conflicts = await this.unresolvedPaths(companionPath);
|
|
339
357
|
if (conflicts.length > 0) {
|
|
340
358
|
throw this.failure(
|
|
@@ -354,7 +372,7 @@ export class CompanionGitSync {
|
|
|
354
372
|
}
|
|
355
373
|
}
|
|
356
374
|
|
|
357
|
-
await this.discardManagedChanges(companionPath);
|
|
375
|
+
await this.discardManagedChanges(companionPath, skillNames);
|
|
358
376
|
const remaining = await this.unresolvedPaths(companionPath);
|
|
359
377
|
if (remaining.length > 0) {
|
|
360
378
|
throw this.failure(
|
|
@@ -467,10 +485,15 @@ export class CompanionGitSync {
|
|
|
467
485
|
return result.status === 0 ? outputLines(result.stdout) : [];
|
|
468
486
|
}
|
|
469
487
|
|
|
470
|
-
private async resolveManagedConflicts(
|
|
488
|
+
private async resolveManagedConflicts(
|
|
489
|
+
companionPath: string,
|
|
490
|
+
targetRef: string,
|
|
491
|
+
skillNames: ReadonlySet<string>,
|
|
492
|
+
): Promise<void> {
|
|
471
493
|
const conflicts = await this.unresolvedPaths(companionPath);
|
|
472
|
-
for (const conflict of conflicts.filter(
|
|
494
|
+
for (const conflict of conflicts.filter((entry) => isForcedPath(entry, skillNames))) {
|
|
473
495
|
const restore = await this.command(companionPath, [
|
|
496
|
+
...LITERAL_PATHSPECS,
|
|
474
497
|
"restore",
|
|
475
498
|
`--source=${targetRef}`,
|
|
476
499
|
"--staged",
|
|
@@ -485,26 +508,41 @@ export class CompanionGitSync {
|
|
|
485
508
|
[conflict],
|
|
486
509
|
);
|
|
487
510
|
}
|
|
488
|
-
await this.command(companionPath, ["add", "-A", "--", conflict]);
|
|
511
|
+
await this.command(companionPath, [...LITERAL_PATHSPECS, "add", "-A", "--", conflict]);
|
|
489
512
|
}
|
|
490
513
|
}
|
|
491
514
|
|
|
492
|
-
private async discardManagedChanges(
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
515
|
+
private async discardManagedChanges(
|
|
516
|
+
companionPath: string,
|
|
517
|
+
skillNames: ReadonlySet<string>,
|
|
518
|
+
): Promise<void> {
|
|
519
|
+
const committed = await this.command(companionPath, [
|
|
520
|
+
"ls-tree",
|
|
521
|
+
"-r",
|
|
522
|
+
"--name-only",
|
|
523
|
+
"-z",
|
|
524
|
+
"HEAD",
|
|
496
525
|
"--",
|
|
497
526
|
...MANAGED_ROOTS,
|
|
498
527
|
]);
|
|
499
|
-
|
|
500
|
-
|
|
528
|
+
if (committed.status !== 0) {
|
|
529
|
+
throw this.failure(
|
|
530
|
+
companionPath,
|
|
531
|
+
`Unable to list managed paths in HEAD: ${this.detail(committed)}`,
|
|
532
|
+
);
|
|
533
|
+
}
|
|
534
|
+
const committedPaths = nulPaths(committed.stdout).filter((entry) =>
|
|
535
|
+
isForcedPath(entry, skillNames),
|
|
536
|
+
);
|
|
537
|
+
if (committedPaths.length > 0) {
|
|
501
538
|
const restore = await this.command(companionPath, [
|
|
539
|
+
...LITERAL_PATHSPECS,
|
|
502
540
|
"restore",
|
|
503
541
|
"--source=HEAD",
|
|
504
542
|
"--staged",
|
|
505
543
|
"--worktree",
|
|
506
544
|
"--",
|
|
507
|
-
...
|
|
545
|
+
...committedPaths,
|
|
508
546
|
]);
|
|
509
547
|
if (restore.status !== 0) {
|
|
510
548
|
throw this.failure(
|
|
@@ -513,15 +551,6 @@ export class CompanionGitSync {
|
|
|
513
551
|
);
|
|
514
552
|
}
|
|
515
553
|
}
|
|
516
|
-
|
|
517
|
-
// -x is intentionally omitted: ignored files are local state and must survive.
|
|
518
|
-
const clean = await this.command(companionPath, ["clean", "-fd", "--", ...MANAGED_ROOTS]);
|
|
519
|
-
if (clean.status !== 0) {
|
|
520
|
-
throw this.failure(
|
|
521
|
-
companionPath,
|
|
522
|
-
`Unable to remove unmanaged managed-path files: ${this.detail(clean)}`,
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
554
|
}
|
|
526
555
|
|
|
527
556
|
private command(companionPath: string, args: readonly string[]): Promise<GitCommandResult> {
|
|
@@ -336,7 +336,13 @@ function orderHandoff(
|
|
|
336
336
|
const next = nextStage(workflow, id);
|
|
337
337
|
if (!next) return NOTHING;
|
|
338
338
|
optional.push(...next.optional.map((stage) => skill(stage.entry, name)));
|
|
339
|
-
if (next.kind === "skill")
|
|
339
|
+
if (next.kind === "skill") {
|
|
340
|
+
const stage = workflow.stages.find((each) => each.id === next.id);
|
|
341
|
+
return buildHandoff(optional, [
|
|
342
|
+
...freshSessionAfterStep(workflow, finished, stage, NO_PROGRESS),
|
|
343
|
+
skill(next.entry!, name),
|
|
344
|
+
]);
|
|
345
|
+
}
|
|
340
346
|
// Nothing to review yet.
|
|
341
347
|
id = next.id;
|
|
342
348
|
}
|
|
@@ -357,6 +363,19 @@ function stepToRun(
|
|
|
357
363
|
return { skill: stage.steps.find((step) => step.own)?.skill ?? stage.entry, open: reason };
|
|
358
364
|
}
|
|
359
365
|
|
|
366
|
+
function freshSessionAfterStep(
|
|
367
|
+
workflow: Workflow,
|
|
368
|
+
finished: WorkflowSkillStage | null,
|
|
369
|
+
stage: WorkflowStage | undefined,
|
|
370
|
+
progress: PathProgress,
|
|
371
|
+
): TextAction[] {
|
|
372
|
+
if (!finished || stage?.id !== "apply") return [];
|
|
373
|
+
const started =
|
|
374
|
+
(progress.steps[stage.id]?.length ?? 0) > 0 || (progress.plan?.completedTasks ?? 0) > 0;
|
|
375
|
+
const before = workflow.stages.indexOf(finished) < workflow.stages.indexOf(stage);
|
|
376
|
+
return !started && before ? [text("Start a fresh session")] : [];
|
|
377
|
+
}
|
|
378
|
+
|
|
360
379
|
interface Placed {
|
|
361
380
|
progress: PathProgress;
|
|
362
381
|
stage: WorkflowStage | null;
|
|
@@ -405,7 +424,14 @@ function progressHandoff(
|
|
|
405
424
|
// null for a stage held by state.
|
|
406
425
|
const open = heldByState(position) && finished ? missing(position, progress) : next.open;
|
|
407
426
|
const action = skill(next.skill, name);
|
|
408
|
-
return buildHandoff(
|
|
427
|
+
return buildHandoff(
|
|
428
|
+
passed(at),
|
|
429
|
+
[
|
|
430
|
+
...freshSessionAfterStep(workflow, finished, position, progress),
|
|
431
|
+
here && open ? { ...action, note: open } : action,
|
|
432
|
+
],
|
|
433
|
+
counted,
|
|
434
|
+
);
|
|
409
435
|
}
|
|
410
436
|
// The reviews up to the next skill stage, then that stage as following them.
|
|
411
437
|
const artifacts = subject.artifacts ?? [];
|
|
@@ -429,6 +455,7 @@ function progressHandoff(
|
|
|
429
455
|
passed(follower),
|
|
430
456
|
[
|
|
431
457
|
...reviews,
|
|
458
|
+
...freshSessionAfterStep(workflow, finished, next, progress),
|
|
432
459
|
...(next?.kind === "skill"
|
|
433
460
|
? [{ ...skill(next.entry, name), afterReview: true as const }]
|
|
434
461
|
: []),
|
|
@@ -439,6 +439,7 @@ async function recordTarget(companionPath: string, worksetId: string): Promise<T
|
|
|
439
439
|
if (record) return record;
|
|
440
440
|
return [
|
|
441
441
|
`no valid Workset ${worksetId}`,
|
|
442
|
+
`a Workset submitted to the inbox but not in this checkout needs \`${FRAMEWORK_NAME} artifact take "<change>"\` first, or pass --change <change>`,
|
|
442
443
|
...problems.map((problem) => `${problem.path}: ${problem.reason}`),
|
|
443
444
|
];
|
|
444
445
|
}
|
|
@@ -97,7 +97,9 @@ export async function refuseForkedCompanionWrite(
|
|
|
97
97
|
): Promise<void> {
|
|
98
98
|
if (!filePath || !isArtifactPath(filePath)) return;
|
|
99
99
|
if (!isCompanionTarget(context, filePath)) return;
|
|
100
|
-
const refusal = await companionForkRefusal(env, context.companionPath
|
|
100
|
+
const refusal = await companionForkRefusal(env, context.companionPath, {
|
|
101
|
+
target: resolveArtifactTarget(filePath, context.repositoryPath),
|
|
102
|
+
});
|
|
101
103
|
if (refusal) throw new GuardRefusal("fork", refusal);
|
|
102
104
|
}
|
|
103
105
|
|
|
@@ -14,6 +14,8 @@ export interface ArtifactRefusalInput {
|
|
|
14
14
|
companion: string;
|
|
15
15
|
/** The Working Repository root relative targets resolve against. */
|
|
16
16
|
repoRoot: string;
|
|
17
|
+
/** A shell expansion in the target, as written, that the command text does not settle. */
|
|
18
|
+
unresolved?: string;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
/** The absolute path both guards judge: a relative target resolves against the repo root, never a `cd`. */
|
|
@@ -34,9 +36,10 @@ export function artifactRefusal({
|
|
|
34
36
|
resolved,
|
|
35
37
|
companion,
|
|
36
38
|
repoRoot,
|
|
39
|
+
unresolved,
|
|
37
40
|
}: ArtifactRefusalInput): string {
|
|
38
|
-
const isRelative = !path.isAbsolute(target);
|
|
39
|
-
const inside = relativeInside(resolved, repoRoot);
|
|
41
|
+
const isRelative = !unresolved && !path.isAbsolute(target);
|
|
42
|
+
const inside = unresolved ? null : relativeInside(resolved, repoRoot);
|
|
40
43
|
const suggested = inside ? path.join(companion, inside) : null;
|
|
41
44
|
|
|
42
45
|
const lines = [
|
|
@@ -51,11 +54,18 @@ export function artifactRefusal({
|
|
|
51
54
|
"Relative paths resolve against the working repository; a preceding `cd` is not followed.",
|
|
52
55
|
);
|
|
53
56
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
if (unresolved) {
|
|
58
|
+
lines.push(
|
|
59
|
+
`The guardrail cannot expand ${unresolved}: it follows only a variable assigned a literal value earlier in the same straight-line command, quoted where the value holds a space or glob character.`,
|
|
60
|
+
`Use a literal absolute path under ${companion}.`,
|
|
61
|
+
);
|
|
62
|
+
} else {
|
|
63
|
+
lines.push(
|
|
64
|
+
suggested
|
|
65
|
+
? "Rewrite to the suggested absolute path and retry."
|
|
66
|
+
: `Use an absolute path under ${companion}.`,
|
|
67
|
+
);
|
|
68
|
+
}
|
|
59
69
|
if (path.basename(target) === "CLAUDE.md") {
|
|
60
70
|
lines.push(`Note: CLAUDE.md already lives in the companion repo at ${companion}/CLAUDE.md.`);
|
|
61
71
|
}
|
|
@@ -115,7 +115,7 @@ const SECRET_HANDLING_RULE = ` <rule id="secret-handling" severity="critical"
|
|
|
115
115
|
|
|
116
116
|
export const FRICTION_GUIDANCE = `## Friction
|
|
117
117
|
|
|
118
|
-
When ${FRAMEWORK_NAME} gets in your way without a refusal or error to point at, such as a skill step that does not fit or missing guidance, record it
|
|
118
|
+
When ${FRAMEWORK_NAME} gets in your way without a refusal or error to point at, such as a skill step that does not fit or missing guidance, record it: \`${FRAMEWORK_NAME} friction report --kind <${REPORT_KINDS.join("|")}> --subject <${SUBJECT_TYPES.join("|")}>:<name> --expected "<what you expected>" --evidence "<what you saw>"\`. Run it on its own, without \`cd\` or chaining; it only writes a local file. Record one report per problem, then keep working. When nothing went wrong, record nothing.`;
|
|
119
119
|
|
|
120
120
|
function withFriction(policy: string, friction: boolean | undefined): string {
|
|
121
121
|
return friction ? `${policy}\n\n${FRICTION_GUIDANCE}` : policy;
|
|
@@ -273,7 +273,7 @@ export function buildCompanionPolicyXml(
|
|
|
273
273
|
if (hasOpenspecCapability(context.capabilities)) {
|
|
274
274
|
lines.push(
|
|
275
275
|
` <rule id="openspec-scope" severity="critical">In OpenSpec, the frontmatter repository identifies the Working Repository; areas are repository-relative paths within that repository. Canonical specs use repository plus flat areas; change artifacts use paired scopes entries. In a monorepo, an Area normally stops at the package root. A cross-repository change may declare multiple scopes, but each resulting spec remains owned by one repository, and each requirement must bind its Area explicitly.</rule>`,
|
|
276
|
-
` <rule id="openspec-publish" severity="critical">Submit publishes nothing: it pushes an OpenSpec change folder (state: submitted) to the inbox mate/inbox to await its merge. A submitted change is not the truth: only publication lands it on the companion's default branch. openspec/specs/ is current; ${FRAMEWORK_NAME} artifact project "<name>" shows the unpublished outcome. ${FRAMEWORK_NAME} artifact pending --json --no-merge-check lists them with author, touched requirements, ref and path; read one (git show <ref>:<path>/<file>) only where it touches your work or the user names it; implement or revise one only when the user names it: ${FRAMEWORK_NAME} artifact take "<name>" brings it into the checkout when it is missing there, then resubmit it with mate-submit-change. Publish only through mate-publish-artifact (${FRAMEWORK_NAME} artifact publish "<name>" --json), after the user selects and confirms the commit and push, for a Delivery Group whose delivery branch is merged. It creates no tag. Never hand-commit or hand-tag one. Publish archives submitted changes and never submits: submitting is a precondition (mate-submit-change, before the merge).</rule>`,
|
|
276
|
+
` <rule id="openspec-publish" severity="critical">Submit publishes nothing: it pushes an OpenSpec change folder (state: submitted) to the inbox mate/inbox to await its merge. A submitted change is not the truth: only publication lands it on the companion's default branch. An active change folder under openspec/changes/ stays uncommitted until publication; never commit one by hand. openspec/specs/ is current; ${FRAMEWORK_NAME} artifact project "<name>" shows the unpublished outcome. ${FRAMEWORK_NAME} artifact pending --json --no-merge-check lists them with author, touched requirements, ref and path; read one (git show <ref>:<path>/<file>) only where it touches your work or the user names it; implement or revise one only when the user names it: ${FRAMEWORK_NAME} artifact take "<name>" brings it into the checkout when it is missing there, then resubmit it with mate-submit-change. Publish only through mate-publish-artifact (${FRAMEWORK_NAME} artifact publish "<name>" --json), after the user selects and confirms the commit and push, for a Delivery Group whose delivery branch is merged. It creates no tag. Never hand-commit or hand-tag one. Publish archives submitted changes and never submits: submitting is a precondition (mate-submit-change, before the merge).</rule>`,
|
|
277
277
|
);
|
|
278
278
|
}
|
|
279
279
|
|
|
@@ -369,6 +369,11 @@ export interface ForkGuardOptions {
|
|
|
369
369
|
homeDir?: string;
|
|
370
370
|
}
|
|
371
371
|
|
|
372
|
+
export interface ForkRefusalOptions extends ForkGuardOptions {
|
|
373
|
+
/** Absolute path being written; an ignored one is never refused. */
|
|
374
|
+
target?: string;
|
|
375
|
+
}
|
|
376
|
+
|
|
372
377
|
/**
|
|
373
378
|
* The verdict both runtimes' artifact guards share, cached per interval so a
|
|
374
379
|
* retry loop cannot spawn Git per write. `null` means "no refusal" — including
|
|
@@ -378,7 +383,7 @@ export interface ForkGuardOptions {
|
|
|
378
383
|
export async function companionForkRefusal(
|
|
379
384
|
env: Record<string, string | undefined>,
|
|
380
385
|
companionPath: string,
|
|
381
|
-
options:
|
|
386
|
+
options: ForkRefusalOptions = {},
|
|
382
387
|
): Promise<string | null> {
|
|
383
388
|
if (!companionPath) return null;
|
|
384
389
|
/**
|
|
@@ -392,9 +397,24 @@ export async function companionForkRefusal(
|
|
|
392
397
|
|
|
393
398
|
const fork = await cachedCompanionForkState(companionPath, options);
|
|
394
399
|
if (!fork?.forked) return null;
|
|
400
|
+
if (options.target && (await isIgnoredByCompanion(companionPath, options.target, options))) {
|
|
401
|
+
return null;
|
|
402
|
+
}
|
|
395
403
|
return forkRefusalMessage(companionPath, fork);
|
|
396
404
|
}
|
|
397
405
|
|
|
406
|
+
// Sync skips ignored files but reconciles tracked ones; `icase`: a case-insensitive disk lands `kept.md` on a tracked `Kept.md`.
|
|
407
|
+
async function isIgnoredByCompanion(
|
|
408
|
+
companionPath: string,
|
|
409
|
+
target: string,
|
|
410
|
+
{ timeoutMs = GIT_QUERY_TIMEOUT_MS }: ForkGuardOptions,
|
|
411
|
+
): Promise<boolean> {
|
|
412
|
+
const git = companionGit(companionPath, { prompt: "never", commandCapMs: timeoutMs });
|
|
413
|
+
if ((await git.run(["check-ignore", "-q", "--", target])).status !== 0) return false;
|
|
414
|
+
const tracked = await git.run(["ls-files", "-z", "--", `:(icase,literal)${target}`]);
|
|
415
|
+
return tracked.status === 0 && tracked.stdout === "";
|
|
416
|
+
}
|
|
417
|
+
|
|
398
418
|
export async function cachedCompanionForkState(
|
|
399
419
|
companionPath: string,
|
|
400
420
|
options: ForkGuardOptions = {},
|