phasegate 0.160.15 → 0.160.16
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/CHANGELOG.md +6 -0
- package/README.ja.md +2 -2
- package/README.md +2 -2
- package/docs/guide/setup-artifacts.md +4 -1
- package/docs/guide/skills-overview.md +1 -1
- package/package.json +1 -1
- package/scripts/harness/installation/application/checks/check-utils.ts +1 -0
- package/scripts/harness/installation/application/checks/claude-skills-symlink-check.ts +4 -3
- package/scripts/harness/installation/application/checks/codex-skills-symlink-check.ts +4 -3
- package/scripts/harness/installation/application/usecases/run-install.ts +96 -1
- package/scripts/harness/installation/application/usecases/run-reconcile.ts +131 -12
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.160.16] - 2026-05-22
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **WI-210 — project install shared skills** — makes `phasegate install` deploy selected bundled skills to root `skills/` for project installs, validates missing skill target content in `doctor`, repairs older empty-skill installs through `reconcile` / `update-skills`, and keeps uninstall scoped to manifest-managed skill directories.
|
|
15
|
+
|
|
10
16
|
## [0.160.12] - 2026-05-20
|
|
11
17
|
|
|
12
18
|
### Added
|
package/README.ja.md
CHANGED
|
@@ -105,7 +105,7 @@ npx phasegate install --apply
|
|
|
105
105
|
npx phasegate doctor
|
|
106
106
|
```
|
|
107
107
|
|
|
108
|
-
`install` は既存の Claude / Codex hooks や Husky script を捨てずに PhaseGate の設定を merge します。書き込み前に変更予定を表示し、package scripts と `phasegate` devDependency、agent skill symlink、未作成の CI workflow、`.phasegate/manifest.json` を整えます。強制的な managed 更新が必要な場合は `npx phasegate install --apply --force` を使います。この場合、置き換え対象は `.phasegate/backups/`
|
|
108
|
+
`install` は既存の Claude / Codex hooks や Husky script を捨てずに PhaseGate の設定を merge します。書き込み前に変更予定を表示し、package scripts と `phasegate` devDependency、root `skills/` への selected bundled skills 配布、agent skill symlink、未作成の CI workflow、`.phasegate/manifest.json` を整えます。強制的な managed 更新が必要な場合は `npx phasegate install --apply --force` を使います。この場合、置き換え対象は `.phasegate/backups/` に退避されます。<!-- @work-item-id WI-210 -->
|
|
109
109
|
|
|
110
110
|
後で PhaseGate を外す場合は、manifest ベースの uninstall を使います。
|
|
111
111
|
|
|
@@ -123,7 +123,7 @@ npx phasegate reconcile --dry-run
|
|
|
123
123
|
npx phasegate reconcile --apply
|
|
124
124
|
```
|
|
125
125
|
|
|
126
|
-
`reconcile` は PhaseGate 管理部分だけを更新し、ユーザーの hook / script / dependency は保持します。新しい deploy target が追加されていれば install
|
|
126
|
+
`reconcile` は PhaseGate 管理部分だけを更新し、ユーザーの hook / script / dependency は保持します。新しい deploy target が追加されていれば install と同じく追加し、project install の shared skills 実体が欠落している場合も修復し、`.phasegate/manifest.json` の version / hash も更新します。install 後に user 改変された managed file は `--force` 無しでは refuse し、force 時は `.phasegate/backups/reconcile-<timestamp>/` に退避してから上書きします。<!-- @work-item-id WI-210 -->
|
|
127
127
|
|
|
128
128
|
### Codex CLI を使う場合
|
|
129
129
|
|
package/README.md
CHANGED
|
@@ -100,7 +100,7 @@ npx phasegate install --apply
|
|
|
100
100
|
npx phasegate doctor
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
-
`install` merges PhaseGate into the current project without discarding existing Claude/Codex hooks or Husky scripts. It reports planned changes before writing, adds package scripts and the `phasegate` devDependency, creates agent skill links, writes `AGENTS.md` / `CLAUDE.md` PhaseGate managed sections for the selected agent targets, writes the CI workflow when missing, and records managed files in `.phasegate/manifest.json`. If an existing file needs a forced managed update, run `npx phasegate install --apply --force`; PhaseGate backs up replaced files under `.phasegate/backups/`. <!-- @work-item-id WI-174 -->
|
|
103
|
+
`install` merges PhaseGate into the current project without discarding existing Claude/Codex hooks or Husky scripts. It reports planned changes before writing, adds package scripts and the `phasegate` devDependency, deploys selected bundled skills to root `skills/`, creates agent skill links to that shared directory, writes `AGENTS.md` / `CLAUDE.md` PhaseGate managed sections for the selected agent targets, writes the CI workflow when missing, and records managed files in `.phasegate/manifest.json`. If an existing file needs a forced managed update, run `npx phasegate install --apply --force`; PhaseGate backs up replaced files under `.phasegate/backups/`. <!-- @work-item-id WI-174 --> <!-- @work-item-id WI-210 -->
|
|
104
104
|
|
|
105
105
|
For personal evaluation inside a team-owned repository, use local-only install:
|
|
106
106
|
|
|
@@ -138,7 +138,7 @@ npx phasegate reconcile --dry-run
|
|
|
138
138
|
npx phasegate reconcile --apply
|
|
139
139
|
```
|
|
140
140
|
|
|
141
|
-
`reconcile` updates only PhaseGate-managed portions, keeps user content, adds newly introduced managed targets, and refreshes `.phasegate/manifest.json` with the current version and hashes. If a managed file was edited after install, `reconcile --apply` refuses that entry until you rerun with `--force`; PhaseGate writes a backup under `.phasegate/backups/reconcile-<timestamp>/`.
|
|
141
|
+
`reconcile` updates only PhaseGate-managed portions, keeps user content, adds newly introduced managed targets, repairs missing shared skill bodies for project installs, and refreshes `.phasegate/manifest.json` with the current version and hashes. If a managed file was edited after install, `reconcile --apply` refuses that entry until you rerun with `--force`; PhaseGate writes a backup under `.phasegate/backups/reconcile-<timestamp>/`. <!-- @work-item-id WI-210 -->
|
|
142
142
|
|
|
143
143
|
### Codex CLI
|
|
144
144
|
|
|
@@ -12,7 +12,7 @@ PhaseGate setup is more than `phasegate.config.json`. A healthy installation is
|
|
|
12
12
|
|
|
13
13
|
| Class | Examples | Owner | Lifecycle |
|
|
14
14
|
|---|---|---|---|
|
|
15
|
-
| Managed target | `phasegate.config.json`, `.claude/settings.json`, `.codex/hooks.json`, `CLAUDE.md`, `AGENTS.md`, `.husky/pre-commit`, `.husky/commit-msg`, `.husky/pre-push`, `.github/workflows/phasegate-aidlc-gate.yml`, `.claude/skills`, `.codex/skills`, `package.json` PhaseGate scripts/devDependency | PhaseGate managed block, real runtime artifact, or symlink plus user content | Created or merged by `install`, refreshed by `reconcile`, removed or reversed by `uninstall` |
|
|
15
|
+
| Managed target | `phasegate.config.json`, `.claude/settings.json`, `.codex/hooks.json`, `CLAUDE.md`, `AGENTS.md`, `.husky/pre-commit`, `.husky/commit-msg`, `.husky/pre-push`, `.github/workflows/phasegate-aidlc-gate.yml`, root `skills/` bundled skill bodies, `.claude/skills`, `.codex/skills`, `package.json` PhaseGate scripts/devDependency | PhaseGate managed block, real runtime artifact, shared skill body, or symlink plus user content | Created or merged by `install`, refreshed by `reconcile`, removed or reversed by `uninstall` |
|
|
16
16
|
| Configuration | `phasegate.config.json`, `package.json` | User owned, PhaseGate assisted | Created by `init` or project install when absent; `install` may merge scripts/devDependency into `package.json` |
|
|
17
17
|
| Generated artifact | `.phasegate/manifest.json`, `.phasegate/backups/*`, `.phasegate/uninstalled-*.json`, `.phasegate/baseline.json` | PhaseGate | Written by lifecycle commands and validators; safe to regenerate only through the owning command |
|
|
18
18
|
| Runtime state/report | `.phasegate/hook-skip-events.jsonl`, explicit `doctor --report-out <path>` output, `reports/regression/*`, resolved `reporting.outputDir` reports | PhaseGate command output | Produced while hooks, doctor, and validation commands run |
|
|
@@ -29,6 +29,7 @@ PhaseGate setup is more than `phasegate.config.json`. A healthy installation is
|
|
|
29
29
|
- Husky scripts when requested: `.husky/pre-commit`, `.husky/commit-msg`, `.husky/pre-push`
|
|
30
30
|
- CI workflow when requested: `.github/workflows/phasegate-aidlc-gate.yml`
|
|
31
31
|
- Agent skill links: `.claude/skills`, `.codex/skills`
|
|
32
|
+
- Project shared bundled skills: selected `skills/<name>/` directories plus `skills/.harness-version`
|
|
32
33
|
- Project config: `phasegate.config.json` when absent, so installed agent hooks have a discoverable runtime config
|
|
33
34
|
- Package metadata: PhaseGate scripts and `devDependencies.phasegate` in `package.json`
|
|
34
35
|
- Manifest: `.phasegate/manifest.json`
|
|
@@ -43,6 +44,8 @@ PhaseGate setup is more than `phasegate.config.json`. A healthy installation is
|
|
|
43
44
|
|
|
44
45
|
If `.claude/*` or `.codex/*` already exists and is not a PhaseGate-managed personal artifact, personal install reports manual review and preserves the existing path. <!-- @work-item-id WI-209 -->
|
|
45
46
|
|
|
47
|
+
Project install uses a different topology: selected bundled skills are deployed once to root `skills/`, and `.claude/skills` / `.codex/skills` point to that shared target. If an older project install has the links but an empty `skills/` target, `phasegate doctor` reports the selected agent skill check and `phasegate reconcile --apply` repairs the shared skill bodies. <!-- @work-item-id WI-210 -->
|
|
48
|
+
|
|
46
49
|
## Doctor Findings
|
|
47
50
|
|
|
48
51
|
`phasegate doctor` evaluates setup health from the managed targets and related project state. Findings include `repairMode`, optional `repairHint`, and optional `suggestedSkill`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Skills Overview
|
|
2
2
|
|
|
3
|
-
Phasegate provides 30 skills covering the full AIDLC (AI-Driven Development Life Cycle). `npx phasegate init`
|
|
3
|
+
Phasegate provides 30 skills covering the full AIDLC (AI-Driven Development Life Cycle). `npx phasegate init` and project `npx phasegate install` deploy skill bodies to root `skills/` and expose them to enabled agents through `.claude/skills/` / `.codex/skills/` links. Personal install instead writes real local-only per-agent skill directories. <!-- @work-item-id WI-210 -->
|
|
4
4
|
|
|
5
5
|
## AIDLC Process — Skill Execution Order
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// @layer application
|
|
3
3
|
// @work-item-id WI-145
|
|
4
4
|
// @work-item-id WI-209
|
|
5
|
+
// @work-item-id WI-210
|
|
5
6
|
|
|
6
7
|
import type { FileInspectorPort } from "../ports/file-inspector-port.js";
|
|
7
8
|
import type { HeuristicCheck } from "../../domain/ports/heuristic-check.js";
|
|
@@ -14,15 +15,15 @@ export class ClaudeSkillsSymlinkCheck implements HeuristicCheck {
|
|
|
14
15
|
|
|
15
16
|
async run(projectRoot: string, inspector: FileInspectorPort): Promise<DiagnosticFinding | null> {
|
|
16
17
|
const link = await inspector.readSymlink(projectPath(projectRoot, this.target));
|
|
17
|
-
if (skillTargetLooksValid(link)) return null;
|
|
18
18
|
const files = await inspector.listFiles(projectPath(projectRoot, this.target));
|
|
19
|
-
if (skillDirectoryLooksValid(files)) return null;
|
|
19
|
+
if (skillTargetLooksValid(link) && skillDirectoryLooksValid(files)) return null;
|
|
20
|
+
if (link === null && skillDirectoryLooksValid(files)) return null;
|
|
20
21
|
return createFinding({
|
|
21
22
|
checkId: this.checkId,
|
|
22
23
|
severity: "red",
|
|
23
24
|
target: this.target,
|
|
24
25
|
message: ".claude/skills に phasegate skills がありません",
|
|
25
|
-
repairMode: link === null ? "mechanical" : "manual",
|
|
26
|
+
repairMode: link === null || skillTargetLooksValid(link) ? "mechanical" : "manual",
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// @layer application
|
|
3
3
|
// @work-item-id WI-145
|
|
4
4
|
// @work-item-id WI-209
|
|
5
|
+
// @work-item-id WI-210
|
|
5
6
|
|
|
6
7
|
import type { FileInspectorPort } from "../ports/file-inspector-port.js";
|
|
7
8
|
import type { HeuristicCheck } from "../../domain/ports/heuristic-check.js";
|
|
@@ -14,15 +15,15 @@ export class CodexSkillsSymlinkCheck implements HeuristicCheck {
|
|
|
14
15
|
|
|
15
16
|
async run(projectRoot: string, inspector: FileInspectorPort): Promise<DiagnosticFinding | null> {
|
|
16
17
|
const link = await inspector.readSymlink(projectPath(projectRoot, this.target));
|
|
17
|
-
if (skillTargetLooksValid(link)) return null;
|
|
18
18
|
const files = await inspector.listFiles(projectPath(projectRoot, this.target));
|
|
19
|
-
if (skillDirectoryLooksValid(files)) return null;
|
|
19
|
+
if (skillTargetLooksValid(link) && skillDirectoryLooksValid(files)) return null;
|
|
20
|
+
if (link === null && skillDirectoryLooksValid(files)) return null;
|
|
20
21
|
return createFinding({
|
|
21
22
|
checkId: this.checkId,
|
|
22
23
|
severity: "red",
|
|
23
24
|
target: this.target,
|
|
24
25
|
message: ".codex/skills に phasegate skills がありません",
|
|
25
|
-
repairMode: link === null ? "mechanical" : "manual",
|
|
26
|
+
repairMode: link === null || skillTargetLooksValid(link) ? "mechanical" : "manual",
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
29
|
}
|
|
@@ -10,9 +10,11 @@
|
|
|
10
10
|
// @work-item-id WI-207
|
|
11
11
|
// @work-item-id WI-208
|
|
12
12
|
// @work-item-id WI-209
|
|
13
|
+
// @work-item-id WI-210
|
|
13
14
|
|
|
14
|
-
import { mkdir, readFile, writeFile, copyFile, chmod, access, lstat, readlink, symlink, readdir } from "node:fs/promises";
|
|
15
|
+
import { mkdir, readFile, writeFile, copyFile, chmod, access, lstat, readlink, symlink, readdir, rm } from "node:fs/promises";
|
|
15
16
|
import { dirname, join } from "node:path";
|
|
17
|
+
import { getSkillsForSet, type SkillSet } from "../../../setup/skill-deployer.js";
|
|
16
18
|
import { DeploymentEntry } from "../../domain/deployment-entry.js";
|
|
17
19
|
import { DeploymentManifest } from "../../domain/deployment-manifest.js";
|
|
18
20
|
import type { ManagedBlockInput } from "../../domain/managed-block.js";
|
|
@@ -86,6 +88,7 @@ const MARKDOWN_END = "<!-- phasegate:managed-section:end -->";
|
|
|
86
88
|
const TEXT_BEGIN = "# phasegate personal install exclude (BEGIN)";
|
|
87
89
|
const TEXT_END = "# phasegate personal install exclude (END)";
|
|
88
90
|
const PERSONAL_AGENT_RUNTIME_FILES = new Set([".claude/settings.json", ".codex/hooks.json"]);
|
|
91
|
+
const SHARED_SKILLS_VERSION_PATH = "skills/.harness-version";
|
|
89
92
|
|
|
90
93
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
91
94
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -122,6 +125,16 @@ async function copyDirectory(src: string, dest: string): Promise<void> {
|
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
|
|
128
|
+
async function listSelectedBundledSkills(harnessRoot: string, skillSet: SkillSet): Promise<string[]> {
|
|
129
|
+
const skillsSource = join(harnessRoot, "skills");
|
|
130
|
+
const allowed = new Set(getSkillsForSet(skillSet));
|
|
131
|
+
const entries = await readdir(skillsSource, { withFileTypes: true });
|
|
132
|
+
return entries
|
|
133
|
+
.filter((entry) => entry.isDirectory() && allowed.has(entry.name))
|
|
134
|
+
.map((entry) => entry.name)
|
|
135
|
+
.sort();
|
|
136
|
+
}
|
|
137
|
+
|
|
125
138
|
function normalizeJsonEntry(value: unknown): string {
|
|
126
139
|
return JSON.stringify(value);
|
|
127
140
|
}
|
|
@@ -431,6 +444,32 @@ export class RunInstallUseCase {
|
|
|
431
444
|
}
|
|
432
445
|
}
|
|
433
446
|
|
|
447
|
+
if (!input.personal && (includeClaude || includeCodex)) {
|
|
448
|
+
const sharedSkills = await listSelectedBundledSkills(input.harnessRoot, skillSet);
|
|
449
|
+
const item = await this.planSharedSkillDirectory(input, sharedSkills, baseManifest);
|
|
450
|
+
plan.push(item);
|
|
451
|
+
if (input.apply && item.changed && item.repairMode === "mechanical") {
|
|
452
|
+
try {
|
|
453
|
+
await this.deploySharedSkills(input, sharedSkills, skillSet);
|
|
454
|
+
} catch (error) {
|
|
455
|
+
return this.withApplyError({ plan, refused, changed, backupDir }, item.path, "copyDirectory", error);
|
|
456
|
+
}
|
|
457
|
+
changed.push(item);
|
|
458
|
+
manifest = this.addManifestEntry(baseManifest, manifest, {
|
|
459
|
+
path: SHARED_SKILLS_VERSION_PATH,
|
|
460
|
+
mode: "created",
|
|
461
|
+
contentForHash: this.sharedSkillsVersionHashInput(input.phasegateVersion, skillSet, sharedSkills),
|
|
462
|
+
});
|
|
463
|
+
for (const skill of sharedSkills) {
|
|
464
|
+
manifest = this.addManifestEntry(baseManifest, manifest, {
|
|
465
|
+
path: `skills/${skill}`,
|
|
466
|
+
mode: "created",
|
|
467
|
+
contentForHash: this.sharedSkillHashInput(skill, input.phasegateVersion, skillSet),
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
|
|
434
473
|
const linkSpecs = input.personal
|
|
435
474
|
? []
|
|
436
475
|
: [
|
|
@@ -691,6 +730,62 @@ export class RunInstallUseCase {
|
|
|
691
730
|
return `personal-skills:${path}:${version}:${skillSet}`;
|
|
692
731
|
}
|
|
693
732
|
|
|
733
|
+
private async planSharedSkillDirectory(
|
|
734
|
+
input: RunInstallInput,
|
|
735
|
+
skills: readonly string[],
|
|
736
|
+
baseManifest: DeploymentManifest,
|
|
737
|
+
): Promise<InstallPlanItem> {
|
|
738
|
+
const versionPath = join(input.projectRoot, SHARED_SKILLS_VERSION_PATH);
|
|
739
|
+
const current = await readTextOrNull(versionPath);
|
|
740
|
+
const skillSet = input.skillSet ?? "all";
|
|
741
|
+
const expectedVersion = `"version": "${input.phasegateVersion}"`;
|
|
742
|
+
const expectedSkillSet = `"skillSet": "${skillSet}"`;
|
|
743
|
+
let missingSkill = false;
|
|
744
|
+
for (const skill of skills) {
|
|
745
|
+
if (!(await exists(join(input.projectRoot, "skills", skill, "SKILL.md")))) {
|
|
746
|
+
missingSkill = true;
|
|
747
|
+
break;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
const missingManifest = baseManifest.findEntry(SHARED_SKILLS_VERSION_PATH) === null
|
|
751
|
+
|| skills.some((skill) => baseManifest.findEntry(`skills/${skill}`) === null);
|
|
752
|
+
const changed = current === null || !current.includes(expectedVersion) || !current.includes(expectedSkillSet) || missingSkill || missingManifest;
|
|
753
|
+
return {
|
|
754
|
+
path: "skills",
|
|
755
|
+
action: changed ? "missing" : "will-skip",
|
|
756
|
+
repairMode: "mechanical",
|
|
757
|
+
strategy: "copy-dir",
|
|
758
|
+
changed,
|
|
759
|
+
summary: changed ? "skills: deploy shared bundled skills" : "skills: already up to date",
|
|
760
|
+
diff: changed ? `+ ${skills.length} bundled skills (${skillSet})` : "no changes",
|
|
761
|
+
skillHint: null,
|
|
762
|
+
};
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
private async deploySharedSkills(input: RunInstallInput, skills: readonly string[], skillSet: SkillSet): Promise<void> {
|
|
766
|
+
const targetRoot = join(input.projectRoot, "skills");
|
|
767
|
+
await mkdir(targetRoot, { recursive: true });
|
|
768
|
+
for (const skill of skills) {
|
|
769
|
+
const source = join(input.harnessRoot, "skills", skill);
|
|
770
|
+
const target = join(targetRoot, skill);
|
|
771
|
+
await rm(target, { recursive: true, force: true });
|
|
772
|
+
await copyDirectory(source, target);
|
|
773
|
+
}
|
|
774
|
+
await writeFile(
|
|
775
|
+
join(targetRoot, ".harness-version"),
|
|
776
|
+
`${JSON.stringify({ version: input.phasegateVersion, deployedAt: new Date().toISOString(), skillSet }, null, 2)}\n`,
|
|
777
|
+
"utf8",
|
|
778
|
+
);
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
private sharedSkillsVersionHashInput(version: string, skillSet: SkillSet, skills: readonly string[]): string {
|
|
782
|
+
return `shared-skills-version:${version}:${skillSet}:${skills.join(",")}`;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
private sharedSkillHashInput(skill: string, version: string, skillSet: SkillSet): string {
|
|
786
|
+
return `shared-skill:${skill}:${version}:${skillSet}`;
|
|
787
|
+
}
|
|
788
|
+
|
|
694
789
|
private addManifestEntry(
|
|
695
790
|
baseManifest: DeploymentManifest,
|
|
696
791
|
manifest: DeploymentManifest,
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
// @work-item-id WI-148
|
|
4
4
|
// @work-item-id WI-174
|
|
5
5
|
// @work-item-id WI-198
|
|
6
|
+
// @work-item-id WI-210
|
|
6
7
|
|
|
7
|
-
import { access, chmod, copyFile, lstat, mkdir, readFile, readlink, symlink, writeFile } from "node:fs/promises";
|
|
8
|
+
import { access, chmod, copyFile, lstat, mkdir, readFile, readlink, readdir, rm, symlink, writeFile } from "node:fs/promises";
|
|
8
9
|
import { dirname, join, relative, resolve } from "node:path";
|
|
10
|
+
import { getSkillsForSet, type SkillSet } from "../../../setup/skill-deployer.js";
|
|
9
11
|
import { DeploymentEntry } from "../../domain/deployment-entry.js";
|
|
10
12
|
import { DeploymentManifest } from "../../domain/deployment-manifest.js";
|
|
11
13
|
import type { ManagedBlockInput } from "../../domain/managed-block.js";
|
|
@@ -14,7 +16,7 @@ import type { HashCalculatorPort } from "../ports/hash-calculator-port.js";
|
|
|
14
16
|
import type { ManifestRepositoryPort } from "../ports/manifest-repository-port.js";
|
|
15
17
|
|
|
16
18
|
type ReconcileAction = "missing-manifest" | "update" | "add" | "link" | "skip" | "refuse";
|
|
17
|
-
type StrategyType = "json" | "shell" | "yaml-add" | "package-json" | "markdown-managed" | "symlink" | "unknown";
|
|
19
|
+
type StrategyType = "json" | "shell" | "yaml-add" | "package-json" | "markdown-managed" | "copy-dir" | "symlink" | "unknown";
|
|
18
20
|
|
|
19
21
|
export interface ReconcilePlanItem {
|
|
20
22
|
readonly path: string;
|
|
@@ -56,6 +58,7 @@ const SHELL_BEGIN = "# === phasegate managed (BEGIN) ===";
|
|
|
56
58
|
const SHELL_END = "# === phasegate managed (END) ===";
|
|
57
59
|
const MARKDOWN_BEGIN = "<!-- phasegate:managed-section:start -->";
|
|
58
60
|
const MARKDOWN_END = "<!-- phasegate:managed-section:end -->";
|
|
61
|
+
const SHARED_SKILLS_VERSION_PATH = "skills/.harness-version";
|
|
59
62
|
|
|
60
63
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
61
64
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -78,6 +81,29 @@ async function readTextOrNull(path: string): Promise<string | null> {
|
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
84
|
+
async function copyDirectory(src: string, dest: string): Promise<void> {
|
|
85
|
+
await mkdir(dest, { recursive: true });
|
|
86
|
+
const entries = await readdir(src, { withFileTypes: true });
|
|
87
|
+
for (const entry of entries) {
|
|
88
|
+
const srcPath = join(src, entry.name);
|
|
89
|
+
const destPath = join(dest, entry.name);
|
|
90
|
+
if (entry.isDirectory()) {
|
|
91
|
+
await copyDirectory(srcPath, destPath);
|
|
92
|
+
} else if (entry.isFile()) {
|
|
93
|
+
await copyFile(srcPath, destPath);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function listSelectedBundledSkills(harnessRoot: string, skillSet: SkillSet): Promise<string[]> {
|
|
99
|
+
const allowed = new Set(getSkillsForSet(skillSet));
|
|
100
|
+
const entries = await readdir(join(harnessRoot, "skills"), { withFileTypes: true });
|
|
101
|
+
return entries
|
|
102
|
+
.filter((entry) => entry.isDirectory() && allowed.has(entry.name))
|
|
103
|
+
.map((entry) => entry.name)
|
|
104
|
+
.sort();
|
|
105
|
+
}
|
|
106
|
+
|
|
81
107
|
function normalizeJsonEntry(value: unknown): string {
|
|
82
108
|
return JSON.stringify(value);
|
|
83
109
|
}
|
|
@@ -259,6 +285,13 @@ export class RunReconcileUseCase {
|
|
|
259
285
|
}
|
|
260
286
|
}
|
|
261
287
|
|
|
288
|
+
if (this.manifestIntendsSharedSkills(manifest)) {
|
|
289
|
+
const sharedSkills = await listSelectedBundledSkills(input.harnessRoot, "all");
|
|
290
|
+
const outcome = await this.planSharedSkills(input, manifest, sharedSkills, "all");
|
|
291
|
+
outcomes.push(outcome);
|
|
292
|
+
plan.push(outcome.item);
|
|
293
|
+
}
|
|
294
|
+
|
|
262
295
|
if (!input.apply || refused.length > 0) {
|
|
263
296
|
return { plan, refused, changed, backupDir: null };
|
|
264
297
|
}
|
|
@@ -272,16 +305,24 @@ export class RunReconcileUseCase {
|
|
|
272
305
|
const hashContent = await outcome.apply();
|
|
273
306
|
changed.push(outcome.item);
|
|
274
307
|
if (hashContent !== null) {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
308
|
+
if (outcome.item.strategy === "copy-dir" && outcome.item.path === "skills") {
|
|
309
|
+
const sharedSkills = await listSelectedBundledSkills(input.harnessRoot, "all");
|
|
310
|
+
nextManifest = nextManifest.addEntry(this.createdEntry(SHARED_SKILLS_VERSION_PATH, this.sharedSkillsVersionHashInput(input.phasegateVersion, "all", sharedSkills)));
|
|
311
|
+
for (const skill of sharedSkills) {
|
|
312
|
+
nextManifest = nextManifest.addEntry(this.createdEntry(`skills/${skill}`, this.sharedSkillHashInput(skill, input.phasegateVersion, "all")));
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
const mode = outcome.item.strategy === "symlink" ? "symlink" : outcome.item.action === "add" ? "created" : (manifest.findEntry(outcome.item.path)?.mode ?? "merged");
|
|
316
|
+
nextManifest = nextManifest.addEntry(
|
|
317
|
+
DeploymentEntry.create({
|
|
318
|
+
path: outcome.item.path,
|
|
319
|
+
mode,
|
|
320
|
+
block: mode === "merged" ? this.managedBlockFor(outcome.item.path, outcome.item.strategy) : null,
|
|
321
|
+
hash: this.hashCalculator.compute(hashContent),
|
|
322
|
+
deployedAt: new Date().toISOString(),
|
|
323
|
+
}),
|
|
324
|
+
);
|
|
325
|
+
}
|
|
285
326
|
}
|
|
286
327
|
}
|
|
287
328
|
|
|
@@ -388,6 +429,84 @@ export class RunReconcileUseCase {
|
|
|
388
429
|
}
|
|
389
430
|
}
|
|
390
431
|
|
|
432
|
+
private manifestIntendsSharedSkills(manifest: DeploymentManifest): boolean {
|
|
433
|
+
return manifest.findEntry(".claude/skills") !== null
|
|
434
|
+
|| manifest.findEntry(".codex/skills") !== null
|
|
435
|
+
|| manifest.entries.some((entry) => entry.path.startsWith("skills/"));
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
private async planSharedSkills(
|
|
439
|
+
input: RunReconcileInput,
|
|
440
|
+
manifest: DeploymentManifest,
|
|
441
|
+
skills: readonly string[],
|
|
442
|
+
skillSet: SkillSet,
|
|
443
|
+
) {
|
|
444
|
+
const versionContent = await readTextOrNull(this.resolveProjectPath(input.projectRoot, SHARED_SKILLS_VERSION_PATH));
|
|
445
|
+
const expectedVersion = `"version": "${input.phasegateVersion}"`;
|
|
446
|
+
let missingSkill = false;
|
|
447
|
+
for (const skill of skills) {
|
|
448
|
+
if (!(await exists(this.resolveProjectPath(input.projectRoot, `skills/${skill}/SKILL.md`)))) {
|
|
449
|
+
missingSkill = true;
|
|
450
|
+
break;
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
const missingManifest = manifest.findEntry(SHARED_SKILLS_VERSION_PATH) === null
|
|
454
|
+
|| skills.some((skill) => manifest.findEntry(`skills/${skill}`) === null);
|
|
455
|
+
const changed = versionContent === null || !versionContent.includes(expectedVersion) || missingSkill || missingManifest;
|
|
456
|
+
return {
|
|
457
|
+
item: this.item(
|
|
458
|
+
"skills",
|
|
459
|
+
changed ? "add" : "skip",
|
|
460
|
+
"mechanical",
|
|
461
|
+
"copy-dir",
|
|
462
|
+
changed,
|
|
463
|
+
changed ? "skills: deploy shared bundled skills" : "skills: already up to date",
|
|
464
|
+
changed ? `+ ${skills.length} bundled skills (${skillSet})` : "no changes",
|
|
465
|
+
null,
|
|
466
|
+
),
|
|
467
|
+
needsBackup: false,
|
|
468
|
+
apply: async () => {
|
|
469
|
+
if (!changed) return null;
|
|
470
|
+
await this.deploySharedSkills(input, skills, skillSet);
|
|
471
|
+
return this.sharedSkillsVersionHashInput(input.phasegateVersion, skillSet, skills);
|
|
472
|
+
},
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
private async deploySharedSkills(input: RunReconcileInput, skills: readonly string[], skillSet: SkillSet): Promise<void> {
|
|
477
|
+
const targetRoot = this.resolveProjectPath(input.projectRoot, "skills");
|
|
478
|
+
await mkdir(targetRoot, { recursive: true });
|
|
479
|
+
for (const skill of skills) {
|
|
480
|
+
const source = join(input.harnessRoot, "skills", skill);
|
|
481
|
+
const target = join(targetRoot, skill);
|
|
482
|
+
await rm(target, { recursive: true, force: true });
|
|
483
|
+
await copyDirectory(source, target);
|
|
484
|
+
}
|
|
485
|
+
await writeFile(
|
|
486
|
+
join(targetRoot, ".harness-version"),
|
|
487
|
+
`${JSON.stringify({ version: input.phasegateVersion, deployedAt: new Date().toISOString(), skillSet }, null, 2)}\n`,
|
|
488
|
+
"utf8",
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
private createdEntry(path: string, hashInput: string): DeploymentEntry {
|
|
493
|
+
return DeploymentEntry.create({
|
|
494
|
+
path,
|
|
495
|
+
mode: "created",
|
|
496
|
+
block: null,
|
|
497
|
+
hash: this.hashCalculator.compute(hashInput),
|
|
498
|
+
deployedAt: new Date().toISOString(),
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
private sharedSkillsVersionHashInput(version: string, skillSet: SkillSet, skills: readonly string[]): string {
|
|
503
|
+
return `shared-skills-version:${version}:${skillSet}:${skills.join(",")}`;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
private sharedSkillHashInput(skill: string, version: string, skillSet: SkillSet): string {
|
|
507
|
+
return `shared-skill:${skill}:${version}:${skillSet}`;
|
|
508
|
+
}
|
|
509
|
+
|
|
391
510
|
private reconcileContent(target: ReconcileTarget, before: string | null, template: string, version: string): string {
|
|
392
511
|
if (target.strategy === "yaml-add") return template;
|
|
393
512
|
if (target.strategy === "shell") return reconcileShell(before, template);
|