peaks-loop 4.1.5 → 4.1.7
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-plugin/marketplace.json +2 -2
- package/CHANGELOG.md +67 -0
- package/README-en.md +47 -183
- package/README.md +24 -188
- package/dist/cli/commands/best-practice-scan-command.d.ts +11 -6
- package/dist/cli/commands/best-practice-scan-command.js +35 -20
- package/dist/cli/commands/best-practice-scan-helpers.d.ts +47 -0
- package/dist/cli/commands/best-practice-scan-helpers.js +88 -5
- package/dist/cli/commands/best-practice-scan-lookup-results.d.ts +13 -0
- package/dist/cli/commands/best-practice-scan-lookup-results.js +237 -0
- package/dist/cli/commands/core/skill-registry-commands.js +9 -4
- package/dist/cli/commands/dispatch-command-spec.js +1 -1
- package/dist/cli/commands/dispatch-isolation-lease.d.ts +1 -1
- package/dist/cli/commands/dispatch-isolation-lease.js +6 -53
- package/dist/cli/commands/dispatch-prompt-blocks.d.ts +1 -1
- package/dist/cli/commands/dispatch-prompt-composition.d.ts +1 -1
- package/dist/cli/commands/dispatch-record-write.d.ts +1 -1
- package/dist/cli/commands/dispatch-tool-call.d.ts +1 -1
- package/dist/cli/commands/openspec-command-shared.js +2 -2
- package/dist/cli/commands/request-transition-failures.js +31 -4
- package/dist/cli/commands/request-transition-preflight.js +1 -1
- package/dist/cli/commands/slice-decompose-artifacts.js +2 -1
- package/dist/cli/commands/verdict-aggregate-command.js +2 -1
- package/dist/cli/commands/workflow-gate-commands.js +4 -4
- package/dist/cli/program.js +0 -2
- package/dist/services/artifacts/artifact-contract-block.js +21 -2
- package/dist/services/artifacts/artifact-prerequisites.d.ts +1 -0
- package/dist/services/artifacts/artifact-prerequisites.js +11 -99
- package/dist/services/artifacts/backcompat-acceptance.d.ts +66 -0
- package/dist/services/artifacts/backcompat-acceptance.js +220 -0
- package/dist/services/artifacts/prerequisite-checks.d.ts +8 -0
- package/dist/services/artifacts/prerequisite-checks.js +7 -2
- package/dist/services/artifacts/prerequisite-path-resolver.d.ts +39 -0
- package/dist/services/artifacts/prerequisite-path-resolver.js +110 -0
- package/dist/services/artifacts/rd-transition-gates.d.ts +33 -0
- package/dist/services/artifacts/rd-transition-gates.js +71 -0
- package/dist/services/artifacts/request-artifact-service.js +22 -20
- package/dist/services/artifacts/request-artifact-state-helpers.d.ts +9 -1
- package/dist/services/artifacts/request-artifact-state-helpers.js +6 -4
- package/dist/services/audit-independent/judged-declaration-check.d.ts +1 -0
- package/dist/services/audit-independent/judged-declaration-check.js +62 -1
- package/dist/services/context/build-dispatch-system-prompt.d.ts +5 -9
- package/dist/services/context/build-dispatch-system-prompt.js +11 -11
- package/dist/services/context/post-compact-reinjection.js +1 -1
- package/dist/services/dispatch/test-tool-detection.d.ts +17 -1
- package/dist/services/dispatch/test-tool-detection.js +12 -1
- package/dist/services/doctor/doctor-service/checks/backcompat-acceptance.d.ts +15 -0
- package/dist/services/doctor/doctor-service/checks/backcompat-acceptance.js +53 -0
- package/dist/services/doctor/doctor-service/checks/skill-reference-parity.d.ts +38 -0
- package/dist/services/doctor/doctor-service/checks/skill-reference-parity.js +243 -0
- package/dist/services/doctor/doctor-service/plugin-registry.js +4 -0
- package/dist/services/doctor/doctor-service/types.d.ts +12 -0
- package/dist/services/evidence/evidence-generator.js +8 -4
- package/dist/services/openspec/coverage-evidence-reader.d.ts +9 -9
- package/dist/services/openspec/coverage-evidence-reader.js +8 -8
- package/dist/services/openspec/openspec-archive-service.d.ts +1 -1
- package/dist/services/openspec/openspec-archive-service.js +6 -6
- package/dist/services/scan/file-size-baseline.d.ts +13 -6
- package/dist/services/scan/file-size-baseline.js +54 -31
- package/dist/services/scan/file-size-scan.d.ts +7 -14
- package/dist/services/scan/file-size-scan.js +6 -1
- package/dist/services/scan/type-corroboration.d.ts +32 -0
- package/dist/services/scan/type-corroboration.js +51 -0
- package/dist/services/scan/type-sanity-service.d.ts +14 -0
- package/dist/services/scan/type-sanity-service.js +10 -19
- package/dist/services/security/safe-settings-path.d.ts +5 -0
- package/dist/services/security/safe-settings-path.js +64 -8
- package/dist/services/skill/resume-detector.js +8 -8
- package/dist/services/workflow/pipeline-verify-gate-support.d.ts +28 -9
- package/dist/services/workflow/pipeline-verify-gate-support.js +40 -117
- package/dist/services/workflow/pipeline-verify-qa-phase.d.ts +102 -0
- package/dist/services/workflow/pipeline-verify-qa-phase.js +176 -0
- package/dist/services/workflow/pipeline-verify-rd-phase.d.ts +67 -0
- package/dist/services/workflow/pipeline-verify-rd-phase.js +122 -0
- package/dist/services/workflow/pipeline-verify-service.js +42 -44
- package/dist/services/workflow/request-type-resolution.d.ts +99 -0
- package/dist/services/workflow/request-type-resolution.js +130 -0
- package/dist/services/workflow/workflow-skip-service.d.ts +1 -0
- package/dist/services/workflow/workflow-skip-service.js +19 -21
- package/dist/services/workflow/workflow-state-store.d.ts +9 -0
- package/dist/services/workflow/workflow-state-store.js +26 -1
- package/dist/services/workspace/workspace-service.js +4 -16
- package/dist/shared/incrementing-number.d.ts +23 -2
- package/dist/shared/incrementing-number.js +57 -15
- package/package.json +5 -7
- package/schemas/doctor-report.schema.json +2 -2
- package/skills/bee/peaks-prd/SKILL.md +3 -2
- package/skills/peaks-code/SKILL.md +32 -15
- package/dist/cli/commands/vm-command-shared.d.ts +0 -23
- package/dist/cli/commands/vm-command-shared.js +0 -23
- package/dist/cli/commands/vm-commands.d.ts +0 -3
- package/dist/cli/commands/vm-commands.js +0 -45
- package/dist/cli/commands/vm-hypervisor-probe.d.ts +0 -27
- package/dist/cli/commands/vm-hypervisor-probe.js +0 -78
- package/dist/cli/commands/vm-hypervisor-runtime.d.ts +0 -15
- package/dist/cli/commands/vm-hypervisor-runtime.js +0 -64
- package/dist/cli/commands/vm-release-command.d.ts +0 -5
- package/dist/cli/commands/vm-release-command.js +0 -101
- package/dist/cli/commands/vm-spawn-command.d.ts +0 -5
- package/dist/cli/commands/vm-spawn-command.js +0 -177
- package/dist/cli/commands/vm-status-command.d.ts +0 -3
- package/dist/cli/commands/vm-status-command.js +0 -50
- package/dist/services/vm/vm-lease.d.ts +0 -40
- package/dist/services/vm/vm-lease.js +0 -160
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
// src/cli/commands/vm-hypervisor-runtime.ts
|
|
2
|
-
//
|
|
3
|
-
// The two hypervisor dispatch helpers `peaks vm spawn` / `peaks vm release`
|
|
4
|
-
// call: create a domain and destroy one. Split out of `vm-commands.ts`; every
|
|
5
|
-
// command line, cwd, stdio tuple and `windowsHide` flag is unchanged.
|
|
6
|
-
import { execSync } from 'node:child_process';
|
|
7
|
-
import { writeFileSync } from 'node:fs';
|
|
8
|
-
export function spawnVmWithHypervisor(args) {
|
|
9
|
-
if (args.hypervisor === 'kvm') {
|
|
10
|
-
// virsh create expects a domain XML file. We emit a minimal
|
|
11
|
-
// XML with the image, mount, and our peaks labels.
|
|
12
|
-
const xml = `<?xml version="1.0"?>
|
|
13
|
-
<domain type="kvm">
|
|
14
|
-
<name>peaks-${args.leaseId}</name>
|
|
15
|
-
<metadata><peaks:label xmlns:peaks="urn:peaks">peaks.leaseId=${args.leaseId};peaks.rid=${args.rid}</peaks:label></metadata>
|
|
16
|
-
<memory>1048576</memory>
|
|
17
|
-
<vcpu>1</vcpu>
|
|
18
|
-
<os><type arch="x86_64">hvm</type></os>
|
|
19
|
-
<devices>
|
|
20
|
-
<disk type="file"><source file="${args.image}"/><target dev="vda"/></disk>
|
|
21
|
-
<filesystem type="mount"><source dir="${args.mount}"/><target dir="/work"/></filesystem>
|
|
22
|
-
</devices>
|
|
23
|
-
</domain>`;
|
|
24
|
-
const xmlPath = `${args.workdir}/.peaks-vm-${args.leaseId}.xml`;
|
|
25
|
-
writeFileSync(xmlPath, xml, 'utf8');
|
|
26
|
-
const out = execSync(`virsh create ${xmlPath}`, {
|
|
27
|
-
cwd: args.workdir,
|
|
28
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
29
|
-
encoding: 'utf8',
|
|
30
|
-
windowsHide: true
|
|
31
|
-
});
|
|
32
|
-
return { vmId: out.trim() };
|
|
33
|
-
}
|
|
34
|
-
if (args.hypervisor === 'hyperkit') {
|
|
35
|
-
const out = execSync(`hvftool create --image ${args.image} --mount ${args.mount}:/work --label peaks.leaseId=${args.leaseId} --label peaks.rid=${args.rid} --entrypoint sleep -- infinity`, { cwd: args.workdir, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', windowsHide: true });
|
|
36
|
-
return { vmId: out.trim() };
|
|
37
|
-
}
|
|
38
|
-
// hyperv: the hvc shim writes a vhdx + emits the new VM id.
|
|
39
|
-
const out = execSync(`hvc create --image ${args.image} --mount ${args.mount} --label peaks.leaseId=${args.leaseId} --label peaks.rid=${args.rid}`, { cwd: args.workdir, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', windowsHide: true });
|
|
40
|
-
return { vmId: out.trim() };
|
|
41
|
-
}
|
|
42
|
-
export function destroyVmWithHypervisor(args) {
|
|
43
|
-
try {
|
|
44
|
-
if (args.hypervisor === 'kvm') {
|
|
45
|
-
execSync(`virsh destroy ${args.vmId}`, {
|
|
46
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
47
|
-
windowsHide: true
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
else if (args.hypervisor === 'hyperkit') {
|
|
51
|
-
execSync(`hvftool stop ${args.vmId}`, {
|
|
52
|
-
stdio: ['ignore', 'pipe', 'pipe'],
|
|
53
|
-
windowsHide: true
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
else {
|
|
57
|
-
execSync(`hvc stop ${args.vmId}`, { stdio: ['ignore', 'pipe', 'pipe'], windowsHide: true });
|
|
58
|
-
}
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
catch {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Command } from 'commander';
|
|
2
|
-
import { type ProgramIO } from '../cli-helpers.js';
|
|
3
|
-
import { type ReleaseOptions } from './vm-command-shared.js';
|
|
4
|
-
export declare function runVmRelease(io: ProgramIO, options: ReleaseOptions): void;
|
|
5
|
-
export declare function registerVmReleaseCommand(cmd: Command, io: ProgramIO): void;
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// src/cli/commands/vm-release-command.ts
|
|
2
|
-
//
|
|
3
|
-
// `peaks vm release` — transition a VM lease to released and run the
|
|
4
|
-
// hypervisor destroy command. Split out of `vm-commands.ts`; every refusal
|
|
5
|
-
// code, message, `data` field, warning and next-action string is unchanged.
|
|
6
|
-
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
-
import { fail, getErrorMessage, ok } from 'peaks-loop-shared/result';
|
|
8
|
-
import { addJsonOption, printResult } from '../cli-helpers.js';
|
|
9
|
-
import { findProjectRoot } from '../../services/config/config-safety.js';
|
|
10
|
-
import { atomicWriteJson } from '../../services/ide/shared/atomic-json.js';
|
|
11
|
-
import { deserializeVmLease, markVmReleased, vmLeaseFilePath } from '../../services/vm/vm-lease.js';
|
|
12
|
-
import { destroyVmWithHypervisor } from './vm-hypervisor-runtime.js';
|
|
13
|
-
import { joinPathSession, resolveVmSessionId } from './vm-command-shared.js';
|
|
14
|
-
/** Print a `vm.release` refusal; the caller stops. */
|
|
15
|
-
function emitReleaseRefusal(io, options, refusal) {
|
|
16
|
-
printResult(io, fail('vm.release', refusal.code, refusal.message, refusal.data, refusal.nextActions), options.json ?? false);
|
|
17
|
-
process.exitCode = 1;
|
|
18
|
-
}
|
|
19
|
-
/** The lease on disk, or null after the matching refusal envelope was printed. */
|
|
20
|
-
function readLeaseOrRefuse(io, options, file) {
|
|
21
|
-
if (!existsSync(file)) {
|
|
22
|
-
emitReleaseRefusal(io, options, {
|
|
23
|
-
code: 'LEASE_NOT_FOUND',
|
|
24
|
-
message: `no VM lease on disk at ${file}`,
|
|
25
|
-
data: { leaseId: options.leaseId, file },
|
|
26
|
-
nextActions: [
|
|
27
|
-
'Run `peaks vm list` (follow-up) to inspect active leases.',
|
|
28
|
-
'For a never-spawned lease, this is a no-op.'
|
|
29
|
-
]
|
|
30
|
-
});
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
return deserializeVmLease(readFileSync(file, 'utf8'));
|
|
35
|
-
}
|
|
36
|
-
catch (err) {
|
|
37
|
-
emitReleaseRefusal(io, options, {
|
|
38
|
-
code: 'LEASE_FILE_INVALID',
|
|
39
|
-
message: getErrorMessage(err),
|
|
40
|
-
data: { leaseId: options.leaseId, file },
|
|
41
|
-
nextActions: ['Delete the malformed lease file manually and re-spawn.']
|
|
42
|
-
});
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
function emitAlreadyReleased(io, options, target, lease) {
|
|
47
|
-
printResult(io, ok('vm.release', {
|
|
48
|
-
lease,
|
|
49
|
-
sessionId: target.sessionId,
|
|
50
|
-
projectRoot: target.projectRoot,
|
|
51
|
-
alreadyReleased: true
|
|
52
|
-
}, [], [`Lease ${lease.leaseId} already released; nothing to do.`]), options.json ?? false);
|
|
53
|
-
}
|
|
54
|
-
function emitReleaseSuccess(io, options, target, lease) {
|
|
55
|
-
const destroyed = destroyVmWithHypervisor({ hypervisor: lease.hypervisor, vmId: lease.vmId });
|
|
56
|
-
const released = markVmReleased(lease);
|
|
57
|
-
atomicWriteJson(target.file, released);
|
|
58
|
-
printResult(io, ok('vm.release', {
|
|
59
|
-
lease: released,
|
|
60
|
-
sessionId: target.sessionId,
|
|
61
|
-
projectRoot: target.projectRoot,
|
|
62
|
-
vmDestroyed: destroyed
|
|
63
|
-
}, destroyed
|
|
64
|
-
? []
|
|
65
|
-
: [`${lease.hypervisor} destroy command failed; the lease was marked released anyway.`], [
|
|
66
|
-
`Lease ${lease.leaseId} marked released.`,
|
|
67
|
-
destroyed
|
|
68
|
-
? `${lease.hypervisor} domain ${lease.vmId} stopped.`
|
|
69
|
-
: `Manual \`${lease.hypervisor} stop ${lease.vmId}\` may be needed.`
|
|
70
|
-
]), options.json ?? false);
|
|
71
|
-
}
|
|
72
|
-
export function runVmRelease(io, options) {
|
|
73
|
-
try {
|
|
74
|
-
const projectRoot = options.project ?? findProjectRoot(process.cwd()) ?? process.cwd();
|
|
75
|
-
const sessionId = resolveVmSessionId(projectRoot, options.session);
|
|
76
|
-
const file = vmLeaseFilePath(joinPathSession(projectRoot, sessionId), options.leaseId);
|
|
77
|
-
const lease = readLeaseOrRefuse(io, options, file);
|
|
78
|
-
if (lease === null)
|
|
79
|
-
return;
|
|
80
|
-
if (lease.status === 'released') {
|
|
81
|
-
emitAlreadyReleased(io, options, { projectRoot, sessionId, file }, lease);
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
emitReleaseSuccess(io, options, { projectRoot, sessionId, file }, lease);
|
|
85
|
-
}
|
|
86
|
-
catch (err) {
|
|
87
|
-
printResult(io, fail('vm.release', 'RELEASE_FAILED', getErrorMessage(err), {
|
|
88
|
-
leaseId: options.leaseId,
|
|
89
|
-
sessionId: options.session ?? process.env.PEAKS_SESSION_ID ?? 'unknown-sid'
|
|
90
|
-
}, ['Verify the lease id and re-run.']), options.json ?? false);
|
|
91
|
-
process.exitCode = 1;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
export function registerVmReleaseCommand(cmd, io) {
|
|
95
|
-
addJsonOption(cmd
|
|
96
|
-
.command('release')
|
|
97
|
-
.description('Transition a VM lease to released and run the hypervisor destroy command. Idempotent on already-released leases.')
|
|
98
|
-
.requiredOption('--lease-id <id>', 'lease id returned by `peaks vm spawn`')
|
|
99
|
-
.option('--session <sid>', 'override session id')
|
|
100
|
-
.option('--project <path>', 'project root (default: findProjectRoot(cwd))')).action((options) => runVmRelease(io, options));
|
|
101
|
-
}
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { Command } from 'commander';
|
|
2
|
-
import { type ProgramIO } from '../cli-helpers.js';
|
|
3
|
-
import { type SpawnOptions } from './vm-command-shared.js';
|
|
4
|
-
export declare function runVmSpawn(io: ProgramIO, options: SpawnOptions): void;
|
|
5
|
-
export declare function registerVmSpawnCommand(cmd: Command, io: ProgramIO): void;
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
// src/cli/commands/vm-spawn-command.ts
|
|
2
|
-
//
|
|
3
|
-
// `peaks vm spawn` — pick a hypervisor, probe it, spawn the VM and write the
|
|
4
|
-
// lease. Split out of `vm-commands.ts`; every refusal code, message, `data`
|
|
5
|
-
// field, next-action string and exit code is unchanged.
|
|
6
|
-
import { existsSync } from 'node:fs';
|
|
7
|
-
import { fail, getErrorMessage, ok } from 'peaks-loop-shared/result';
|
|
8
|
-
import { addJsonOption, printResult } from '../cli-helpers.js';
|
|
9
|
-
import { findProjectRoot } from '../../services/config/config-safety.js';
|
|
10
|
-
import { atomicWriteJson } from '../../services/ide/shared/atomic-json.js';
|
|
11
|
-
import { DEFAULT_VM_IMAGE, finalizeVmLease, generateVmLeaseId, vmLeaseFilePath } from '../../services/vm/vm-lease.js';
|
|
12
|
-
import { detectHypervisor } from './vm-hypervisor-probe.js';
|
|
13
|
-
import { spawnVmWithHypervisor } from './vm-hypervisor-runtime.js';
|
|
14
|
-
import { joinPathSession, resolveTtlMs, resolveVmSessionId } from './vm-command-shared.js';
|
|
15
|
-
/** Explicit `--hypervisor` wins; otherwise only `/dev/kvm` auto-detects. */
|
|
16
|
-
function pickHypervisor(explicit) {
|
|
17
|
-
if (explicit !== undefined)
|
|
18
|
-
return explicit;
|
|
19
|
-
// No platform detector for hyperkit / hyperv — those require --hypervisor.
|
|
20
|
-
if (existsSync('/dev/kvm'))
|
|
21
|
-
return 'kvm';
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
function buildSpawnContext(options, projectRoot, sessionId, hypervisor) {
|
|
25
|
-
return {
|
|
26
|
-
projectRoot,
|
|
27
|
-
sessionId,
|
|
28
|
-
hypervisor,
|
|
29
|
-
image: options.image ?? DEFAULT_VM_IMAGE,
|
|
30
|
-
mount: options.mount ?? projectRoot,
|
|
31
|
-
ttlMs: resolveTtlMs(options.ttl, options.role),
|
|
32
|
-
leaseId: generateVmLeaseId(),
|
|
33
|
-
now: Date.now()
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
function emitSpawnRefusal(io, options, refusal) {
|
|
37
|
-
printResult(io, fail('vm.spawn', refusal.code, refusal.message, refusal.data, refusal.nextActions), options.json ?? false);
|
|
38
|
-
process.exitCode = 1;
|
|
39
|
-
}
|
|
40
|
-
function emitHypervisorUnspecified(io, options, sessionId) {
|
|
41
|
-
emitSpawnRefusal(io, options, {
|
|
42
|
-
code: 'VM_HYPERVISOR_UNSPECIFIED',
|
|
43
|
-
message: 'No --hypervisor given and the host does not advertise /dev/kvm. Pass --hypervisor hyperkit|hyperv to force one.',
|
|
44
|
-
data: { rid: options.rid, sessionId },
|
|
45
|
-
nextActions: [
|
|
46
|
-
'Linux KVM: ensure /dev/kvm exists and the kvm kernel module is loaded.',
|
|
47
|
-
'macOS HyperKit: install hvftool (brew install hyperkit) and pass --hypervisor hyperkit.',
|
|
48
|
-
'Windows Hyper-V: install the hvc shim and pass --hypervisor hyperv.'
|
|
49
|
-
]
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function emitRuntimeUnavailable(io, options, detail) {
|
|
53
|
-
emitSpawnRefusal(io, options, {
|
|
54
|
-
code: 'VM_RUNTIME_UNAVAILABLE',
|
|
55
|
-
message: `${detail.hypervisor} runtime not available: ${detail.stderr}`,
|
|
56
|
-
data: { rid: options.rid, hypervisor: detail.hypervisor, sessionId: detail.sessionId },
|
|
57
|
-
nextActions: [
|
|
58
|
-
`Install the ${detail.hypervisor} runtime binary on PATH.`,
|
|
59
|
-
'The dispatch fail-fast prevents fallback to a different hypervisor (caller chose this mode for a reason).'
|
|
60
|
-
]
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
/** Spawn, or print the spawn failure and return null. */
|
|
64
|
-
function spawnOrFail(io, options, ctx) {
|
|
65
|
-
try {
|
|
66
|
-
return spawnVmWithHypervisor({
|
|
67
|
-
hypervisor: ctx.hypervisor,
|
|
68
|
-
image: ctx.image,
|
|
69
|
-
mount: ctx.mount,
|
|
70
|
-
leaseId: ctx.leaseId,
|
|
71
|
-
rid: options.rid,
|
|
72
|
-
workdir: ctx.projectRoot
|
|
73
|
-
}).vmId;
|
|
74
|
-
}
|
|
75
|
-
catch (err) {
|
|
76
|
-
emitSpawnRefusal(io, options, {
|
|
77
|
-
code: 'VM_SPAWN_FAILED',
|
|
78
|
-
message: getErrorMessage(err),
|
|
79
|
-
data: {
|
|
80
|
-
rid: options.rid,
|
|
81
|
-
hypervisor: ctx.hypervisor,
|
|
82
|
-
image: ctx.image,
|
|
83
|
-
sessionId: ctx.sessionId
|
|
84
|
-
},
|
|
85
|
-
nextActions: [
|
|
86
|
-
'Verify the image / vhdx is reachable on the host.',
|
|
87
|
-
`For ${ctx.hypervisor}: the spawn helper expects domain XML / hvftool args / hvc shim.`
|
|
88
|
-
]
|
|
89
|
-
});
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function emitSpawnSuccess(io, options, spawned) {
|
|
94
|
-
const { ctx, vmId, binary } = spawned;
|
|
95
|
-
const lease = finalizeVmLease({
|
|
96
|
-
leaseId: ctx.leaseId,
|
|
97
|
-
rid: options.rid,
|
|
98
|
-
role: options.role,
|
|
99
|
-
path: ctx.mount,
|
|
100
|
-
hypervisor: ctx.hypervisor,
|
|
101
|
-
image: ctx.image,
|
|
102
|
-
vmId,
|
|
103
|
-
createdAt: ctx.now,
|
|
104
|
-
expiresAt: ctx.now + ctx.ttlMs,
|
|
105
|
-
purpose: options.purpose
|
|
106
|
-
});
|
|
107
|
-
atomicWriteJson(vmLeaseFilePath(joinPathSession(ctx.projectRoot, ctx.sessionId), ctx.leaseId), lease);
|
|
108
|
-
printResult(io, ok('vm.spawn', {
|
|
109
|
-
lease,
|
|
110
|
-
sessionId: ctx.sessionId,
|
|
111
|
-
projectRoot: ctx.projectRoot,
|
|
112
|
-
hypervisor: ctx.hypervisor,
|
|
113
|
-
runtime: binary,
|
|
114
|
-
ttlMs: ctx.ttlMs,
|
|
115
|
-
nextActions: [
|
|
116
|
-
`VM domain id: ${vmId}`,
|
|
117
|
-
`Image: ${ctx.image}`,
|
|
118
|
-
`Lease expires at: ${new Date(lease.expiresAt).toISOString()}`,
|
|
119
|
-
'Run `peaks vm release --lease-id <lease-id>` when done',
|
|
120
|
-
'For inside-the-VM exec, a follow-up rid adds `peaks vm exec` (Part 35 ships lease + spawn/release only).'
|
|
121
|
-
]
|
|
122
|
-
}, [], []), options.json ?? false);
|
|
123
|
-
}
|
|
124
|
-
export function runVmSpawn(io, options) {
|
|
125
|
-
try {
|
|
126
|
-
const projectRoot = options.project ?? findProjectRoot(process.cwd()) ?? process.cwd();
|
|
127
|
-
const sessionId = resolveVmSessionId(projectRoot, options.session);
|
|
128
|
-
const detected = pickHypervisor(options.hypervisor);
|
|
129
|
-
if (detected === null) {
|
|
130
|
-
emitHypervisorUnspecified(io, options, sessionId);
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const probe = detectHypervisor(detected);
|
|
134
|
-
if (!probe.ok) {
|
|
135
|
-
emitRuntimeUnavailable(io, options, {
|
|
136
|
-
sessionId,
|
|
137
|
-
hypervisor: detected,
|
|
138
|
-
stderr: probe.stderr
|
|
139
|
-
});
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const ctx = buildSpawnContext(options, projectRoot, sessionId, detected);
|
|
143
|
-
const vmId = spawnOrFail(io, options, ctx);
|
|
144
|
-
if (vmId === null)
|
|
145
|
-
return;
|
|
146
|
-
emitSpawnSuccess(io, options, { ctx, vmId, binary: probe.binary });
|
|
147
|
-
}
|
|
148
|
-
catch (err) {
|
|
149
|
-
emitSpawnRefusal(io, options, {
|
|
150
|
-
code: 'SPAWN_FAILED',
|
|
151
|
-
message: getErrorMessage(err),
|
|
152
|
-
data: {
|
|
153
|
-
rid: options.rid,
|
|
154
|
-
sessionId: options.session ?? process.env.PEAKS_SESSION_ID ?? 'unknown-sid'
|
|
155
|
-
},
|
|
156
|
-
nextActions: [
|
|
157
|
-
'See error message; if the lease was not written, retry after fixing the underlying issue.'
|
|
158
|
-
]
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
export function registerVmSpawnCommand(cmd, io) {
|
|
163
|
-
addJsonOption(cmd
|
|
164
|
-
.command('spawn')
|
|
165
|
-
.description('Spawn a VM via the requested hypervisor (kvm | hyperkit | hyperv) and write a VM lease. ' +
|
|
166
|
-
'Default TTL is role-aware (rd=30m / qa=15m / ui=1h); pass --ttl <ms> to override. ' +
|
|
167
|
-
'Default image is `peaks-base:22-slim`; pass --image <name> to override.')
|
|
168
|
-
.requiredOption('--rid <rid>', 'peaks request id the lease is associated with')
|
|
169
|
-
.requiredOption('--role <role>', 'sub-agent role (rd | qa | ui | sc | prd | general-purpose)')
|
|
170
|
-
.requiredOption('--purpose <text>', 'why this VM was spawned (audit log)')
|
|
171
|
-
.option('--hypervisor <name>', 'hypervisor to use: kvm | hyperkit | hyperv (default: auto-detect from host)')
|
|
172
|
-
.option('--image <name>', `container image / vhdx to boot (default ${DEFAULT_VM_IMAGE})`)
|
|
173
|
-
.option('--ttl <ms>', 'time-to-live in ms (default role-aware; override with positive number)')
|
|
174
|
-
.option('--mount <path>', 'host path to mount as the VM working dir (default: <projectRoot>)')
|
|
175
|
-
.option('--session <sid>', 'override session id')
|
|
176
|
-
.option('--project <path>', 'project root (default: findProjectRoot(cwd))')).action((options) => runVmSpawn(io, options));
|
|
177
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// src/cli/commands/vm-status-command.ts
|
|
2
|
-
//
|
|
3
|
-
// `peaks vm status` — the read-only host probe that rides on the `vm` parent.
|
|
4
|
-
//
|
|
5
|
-
// `peaks vm spawn` refuses with VM_RUNTIME_UNAVAILABLE and
|
|
6
|
-
// `peaks sub-agent dispatch --isolation vm` refuses with
|
|
7
|
-
// ISOLATION_VM_NOT_YET_IMPLEMENTED, but neither said WHICH prerequisite is
|
|
8
|
-
// missing on the machine actually running the command: the hypervisor binary,
|
|
9
|
-
// the KVM device node, or a host with no hypervisor at all. The only way to
|
|
10
|
-
// find out was to attempt a spawn that was going to fail.
|
|
11
|
-
//
|
|
12
|
-
// This reports it, and it does not pretend the runtime exists: a probe that
|
|
13
|
-
// finds libvirt on PATH still leaves `--isolation vm` refused, because the
|
|
14
|
-
// missing piece is peaks' VM runtime (image, `vm exec`, per-OS bindings), not
|
|
15
|
-
// the hypervisor. The envelope says so rather than letting a green probe read
|
|
16
|
-
// as "vm works now".
|
|
17
|
-
//
|
|
18
|
-
import { probeHypervisors } from './vm-hypervisor-probe.js';
|
|
19
|
-
import { addJsonOption, printResult } from '../cli-helpers.js';
|
|
20
|
-
import { fail, ok } from 'peaks-loop-shared/result';
|
|
21
|
-
export function registerVmStatusCommand(vm, io) {
|
|
22
|
-
addJsonOption(vm
|
|
23
|
-
.command('status')
|
|
24
|
-
.description('Report which VM hypervisor this host offers (read-only probe; the peaks VM runtime is a separate rid)')).action((options) => {
|
|
25
|
-
const rows = probeHypervisors();
|
|
26
|
-
const anyAvailable = rows.some((row) => row.available);
|
|
27
|
-
const data = {
|
|
28
|
-
platform: process.platform,
|
|
29
|
-
hypervisors: rows,
|
|
30
|
-
anyAvailable,
|
|
31
|
-
// The runtime statement, kept next to the probe result so the two can
|
|
32
|
-
// never be read apart.
|
|
33
|
-
dispatchIsolationVm: 'not implemented'
|
|
34
|
-
};
|
|
35
|
-
for (const row of rows) {
|
|
36
|
-
io.stdout(`${row.hypervisor} ${row.available ? 'present' : 'absent'} ${row.binary}: ${row.detail}`);
|
|
37
|
-
}
|
|
38
|
-
io.stdout(`platform: ${process.platform}`);
|
|
39
|
-
const nextActions = [
|
|
40
|
-
'The peaks VM runtime (image build, `peaks vm exec`, Hyper-V/HyperKit bindings) is not implemented yet: `peaks sub-agent dispatch --isolation vm` stays refused even when a hypervisor is present.',
|
|
41
|
-
'For isolation today use --isolation worktree (L2, production) or --isolation container (L4, docker/podman).'
|
|
42
|
-
];
|
|
43
|
-
if (!anyAvailable) {
|
|
44
|
-
printResult(io, fail('vm.status', 'VM_RUNTIME_UNAVAILABLE', `no VM hypervisor is usable on ${process.platform}: install one of virsh (KVM/libvirt, Linux), hvftool (HyperKit, macOS) or hvc (Hyper-V, Windows) — and on Linux the /dev/kvm device node — or drop --isolation and use worktree/container.`, data, nextActions), options.json);
|
|
45
|
-
process.exitCode = 1;
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
printResult(io, ok('vm.status', data, [], nextActions), options.json);
|
|
49
|
-
});
|
|
50
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
export type VmHypervisor = 'kvm' | 'hyperkit' | 'hyperv';
|
|
2
|
-
export declare const VM_HYPERVISORS: ReadonlyArray<VmHypervisor>;
|
|
3
|
-
export declare const DEFAULT_TTL_BY_ROLE: Readonly<Record<string, number>>;
|
|
4
|
-
export declare const DEFAULT_TTL_MS: number | undefined;
|
|
5
|
-
export declare const DEFAULT_VM_IMAGE = "peaks-base:22-slim";
|
|
6
|
-
export type VmLeaseStatus = 'active' | 'released' | 'expired' | 'gc';
|
|
7
|
-
export interface VmLease {
|
|
8
|
-
readonly leaseId: string;
|
|
9
|
-
readonly rid: string;
|
|
10
|
-
readonly role: string;
|
|
11
|
-
/** Host path mounted into the VM working dir. */
|
|
12
|
-
readonly path: string;
|
|
13
|
-
/** Hypervisor the VM runs under (kvm | hyperkit | hyperv). */
|
|
14
|
-
readonly hypervisor: VmHypervisor;
|
|
15
|
-
/** VM image name (e.g. 'peaks-base:22-slim'). */
|
|
16
|
-
readonly image: string;
|
|
17
|
-
/** VM domain id reported by virsh / hvftool / hvc. */
|
|
18
|
-
readonly vmId: string;
|
|
19
|
-
/** Unix epoch ms when the lease was created. */
|
|
20
|
-
readonly createdAt: number;
|
|
21
|
-
/** Unix epoch ms when the lease expires. */
|
|
22
|
-
readonly expiresAt: number;
|
|
23
|
-
/** Operator-supplied purpose text (audit log). */
|
|
24
|
-
readonly purpose: string;
|
|
25
|
-
readonly status: VmLeaseStatus;
|
|
26
|
-
readonly consumedBySubAgents: ReadonlyArray<string>;
|
|
27
|
-
}
|
|
28
|
-
export type VmLeaseDraft = Omit<VmLease, 'status' | 'consumedBySubAgents'>;
|
|
29
|
-
export declare function vmLeaseStoreDir(sessionRuntimeDir: string): string;
|
|
30
|
-
export declare function vmLeaseFilePath(sessionRuntimeDir: string, leaseId: string): string;
|
|
31
|
-
export declare function generateVmLeaseId(): string;
|
|
32
|
-
export declare function ttlForVmRole(role: string): number;
|
|
33
|
-
export declare function finalizeVmLease(draft: VmLeaseDraft): VmLease;
|
|
34
|
-
export declare function markVmReleased(lease: VmLease): VmLease;
|
|
35
|
-
export declare function markVmExpired(lease: VmLease): VmLease;
|
|
36
|
-
export declare function markVmGc(lease: VmLease): VmLease;
|
|
37
|
-
export declare function recordVmConsumption(lease: VmLease, subAgentId: string): VmLease;
|
|
38
|
-
export declare function isVmLeaseActive(lease: VmLease, now?: number): boolean;
|
|
39
|
-
export declare function serializeVmLease(lease: VmLease): string;
|
|
40
|
-
export declare function deserializeVmLease(raw: string): VmLease;
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* vm-lease — pure-function lease store for `peaks vm spawn`.
|
|
3
|
-
*
|
|
4
|
-
* Parallels the design of `worktree-lease.ts` (Part 1) and
|
|
5
|
-
* `container-lease.ts` (Part 12). The L4 VM isolation mode
|
|
6
|
-
* (`--isolation vm` in dispatch) needs its own lease surface
|
|
7
|
-
* so the PreToolUse gate can grant `docker`-class operations
|
|
8
|
-
* to sub-agents that own a VM lease.
|
|
9
|
-
*
|
|
10
|
-
* Hypervisor support:
|
|
11
|
-
* - kvm: virsh create + virsh destroy (Linux KVM via libvirt)
|
|
12
|
-
* - hyperkit: hvftool create + hvftool stop (macOS HyperKit)
|
|
13
|
-
* - hyperv: hvc create + hvc stop (Windows Hyper-V via the
|
|
14
|
-
* Hyper-V cmdlets; the operator wires the entry shim)
|
|
15
|
-
*
|
|
16
|
-
* Each hypervisor has its own spawn pattern; the lease file
|
|
17
|
-
* records which hypervisor was used so `peaks vm release`
|
|
18
|
-
* can dispatch to the right cleanup command.
|
|
19
|
-
*/
|
|
20
|
-
import { randomBytes } from 'node:crypto';
|
|
21
|
-
import { posix as path } from 'node:path';
|
|
22
|
-
import { normalizePath } from '../../shared/path-utils.js';
|
|
23
|
-
export const VM_HYPERVISORS = Object.freeze([
|
|
24
|
-
'kvm',
|
|
25
|
-
'hyperkit',
|
|
26
|
-
'hyperv'
|
|
27
|
-
]);
|
|
28
|
-
// PRD-002b slice 2 — extract lease-TTL primitives (same shape as
|
|
29
|
-
// container-lease.ts / worktree-lease.ts). See config diff comment.
|
|
30
|
-
const MINUTES_PER_HOUR = 60;
|
|
31
|
-
const MS_PER_MINUTE = MINUTES_PER_HOUR * 1_000;
|
|
32
|
-
const LEASE_RD_TTL_MINUTES = 30;
|
|
33
|
-
const LEASE_QA_TTL_MINUTES = 15;
|
|
34
|
-
const LEASE_UI_TTL_MINUTES = MINUTES_PER_HOUR;
|
|
35
|
-
const LEASE_SC_TTL_MINUTES = 30;
|
|
36
|
-
const LEASE_PRD_TTL_MINUTES = 15;
|
|
37
|
-
const LEASE_GENERAL_TTL_MINUTES = 30;
|
|
38
|
-
const LEASE_ID_RANDOM_BYTES = 8;
|
|
39
|
-
export const DEFAULT_TTL_BY_ROLE = Object.freeze({
|
|
40
|
-
rd: LEASE_RD_TTL_MINUTES * MS_PER_MINUTE,
|
|
41
|
-
qa: LEASE_QA_TTL_MINUTES * MS_PER_MINUTE,
|
|
42
|
-
ui: LEASE_UI_TTL_MINUTES * MS_PER_MINUTE,
|
|
43
|
-
sc: LEASE_SC_TTL_MINUTES * MS_PER_MINUTE,
|
|
44
|
-
prd: LEASE_PRD_TTL_MINUTES * MS_PER_MINUTE,
|
|
45
|
-
general: LEASE_GENERAL_TTL_MINUTES * MS_PER_MINUTE
|
|
46
|
-
});
|
|
47
|
-
export const DEFAULT_TTL_MS = DEFAULT_TTL_BY_ROLE.rd;
|
|
48
|
-
export const DEFAULT_VM_IMAGE = 'peaks-base:22-slim';
|
|
49
|
-
export function vmLeaseStoreDir(sessionRuntimeDir) {
|
|
50
|
-
return joinPath(sessionRuntimeDir, 'vm-leases');
|
|
51
|
-
}
|
|
52
|
-
export function vmLeaseFilePath(sessionRuntimeDir, leaseId) {
|
|
53
|
-
return joinPath(vmLeaseStoreDir(sessionRuntimeDir), `${leaseId}.json`);
|
|
54
|
-
}
|
|
55
|
-
export function generateVmLeaseId() {
|
|
56
|
-
return randomBytes(LEASE_ID_RANDOM_BYTES).toString('hex');
|
|
57
|
-
}
|
|
58
|
-
export function ttlForVmRole(role) {
|
|
59
|
-
const normalized = role.toLowerCase();
|
|
60
|
-
const candidate = DEFAULT_TTL_BY_ROLE[normalized];
|
|
61
|
-
const fallback = DEFAULT_TTL_BY_ROLE['rd'] ?? LEASE_RD_TTL_MINUTES * MS_PER_MINUTE;
|
|
62
|
-
return candidate ?? fallback;
|
|
63
|
-
}
|
|
64
|
-
export function finalizeVmLease(draft) {
|
|
65
|
-
return { ...draft, status: 'active', consumedBySubAgents: [] };
|
|
66
|
-
}
|
|
67
|
-
export function markVmReleased(lease) {
|
|
68
|
-
return { ...lease, status: 'released' };
|
|
69
|
-
}
|
|
70
|
-
export function markVmExpired(lease) {
|
|
71
|
-
return { ...lease, status: 'expired' };
|
|
72
|
-
}
|
|
73
|
-
export function markVmGc(lease) {
|
|
74
|
-
return { ...lease, status: 'gc' };
|
|
75
|
-
}
|
|
76
|
-
export function recordVmConsumption(lease, subAgentId) {
|
|
77
|
-
if (lease.consumedBySubAgents.includes(subAgentId))
|
|
78
|
-
return lease;
|
|
79
|
-
return { ...lease, consumedBySubAgents: [...lease.consumedBySubAgents, subAgentId] };
|
|
80
|
-
}
|
|
81
|
-
export function isVmLeaseActive(lease, now = Date.now()) {
|
|
82
|
-
return lease.status === 'active' && lease.expiresAt > now;
|
|
83
|
-
}
|
|
84
|
-
export function serializeVmLease(lease) {
|
|
85
|
-
return JSON.stringify(lease, null, 2) + '\n';
|
|
86
|
-
}
|
|
87
|
-
export function deserializeVmLease(raw) {
|
|
88
|
-
const parsed = JSON.parse(raw);
|
|
89
|
-
if (typeof parsed !== 'object' || parsed === null) {
|
|
90
|
-
throw new Error('vm lease file must contain a JSON object');
|
|
91
|
-
}
|
|
92
|
-
const obj = parsed;
|
|
93
|
-
const required = [
|
|
94
|
-
'leaseId',
|
|
95
|
-
'rid',
|
|
96
|
-
'role',
|
|
97
|
-
'path',
|
|
98
|
-
'hypervisor',
|
|
99
|
-
'image',
|
|
100
|
-
'vmId',
|
|
101
|
-
'createdAt',
|
|
102
|
-
'expiresAt',
|
|
103
|
-
'purpose',
|
|
104
|
-
'status',
|
|
105
|
-
'consumedBySubAgents'
|
|
106
|
-
];
|
|
107
|
-
for (const k of required) {
|
|
108
|
-
if (!(k in obj))
|
|
109
|
-
throw new Error(`vm lease missing field: ${k}`);
|
|
110
|
-
}
|
|
111
|
-
if (!VM_HYPERVISORS.includes(obj.hypervisor)) {
|
|
112
|
-
throw new Error(`vm lease hypervisor invalid: ${String(obj.hypervisor)}`);
|
|
113
|
-
}
|
|
114
|
-
if (typeof obj.leaseId !== 'string')
|
|
115
|
-
throw new Error('leaseId missing');
|
|
116
|
-
if (typeof obj.rid !== 'string')
|
|
117
|
-
throw new Error('rid missing');
|
|
118
|
-
if (typeof obj.role !== 'string')
|
|
119
|
-
throw new Error('role missing');
|
|
120
|
-
if (typeof obj.path !== 'string')
|
|
121
|
-
throw new Error('path missing');
|
|
122
|
-
if (typeof obj.image !== 'string')
|
|
123
|
-
throw new Error('image missing');
|
|
124
|
-
if (typeof obj.vmId !== 'string')
|
|
125
|
-
throw new Error('vmId missing');
|
|
126
|
-
if (typeof obj.createdAt !== 'number')
|
|
127
|
-
throw new Error('createdAt missing');
|
|
128
|
-
if (typeof obj.expiresAt !== 'number')
|
|
129
|
-
throw new Error('expiresAt missing');
|
|
130
|
-
if (typeof obj.purpose !== 'string')
|
|
131
|
-
throw new Error('purpose missing');
|
|
132
|
-
if (typeof obj.status !== 'string')
|
|
133
|
-
throw new Error('status missing');
|
|
134
|
-
if (!Array.isArray(obj.consumedBySubAgents))
|
|
135
|
-
throw new Error('consumedBySubAgents missing');
|
|
136
|
-
return {
|
|
137
|
-
leaseId: obj.leaseId,
|
|
138
|
-
rid: obj.rid,
|
|
139
|
-
role: obj.role,
|
|
140
|
-
path: obj.path,
|
|
141
|
-
hypervisor: obj.hypervisor,
|
|
142
|
-
image: obj.image,
|
|
143
|
-
vmId: obj.vmId,
|
|
144
|
-
createdAt: obj.createdAt,
|
|
145
|
-
expiresAt: obj.expiresAt,
|
|
146
|
-
purpose: obj.purpose,
|
|
147
|
-
status: obj.status,
|
|
148
|
-
consumedBySubAgents: obj.consumedBySubAgents
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function joinPath(...segments) {
|
|
152
|
-
if (segments.length === 0)
|
|
153
|
-
return '';
|
|
154
|
-
const normalized = segments.map((s) => normalizePath(s));
|
|
155
|
-
let acc = normalized[0];
|
|
156
|
-
for (let i = 1; i < normalized.length; i++) {
|
|
157
|
-
acc = path.join(acc, normalized[i]);
|
|
158
|
-
}
|
|
159
|
-
return acc;
|
|
160
|
-
}
|