@evomap/evolver-cli 2.0.19 → 2.0.24
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/dist/autoDistillAntiGene.js +7 -5
- package/dist/autoDistillLlm.js +10 -12
- package/dist/autoexec.js +39 -7
- package/dist/cliContracts.d.ts +5 -0
- package/dist/cliContracts.js +85 -29
- package/dist/commandCatalog.d.ts +1 -0
- package/dist/commandCatalog.js +1 -0
- package/dist/cycleConsumer.js +3 -3
- package/dist/dispatch.js +2 -0
- package/dist/distillObserver.js +6 -4
- package/dist/doctor.d.ts +11 -0
- package/dist/doctor.js +24 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +98 -31
- package/dist/lifecycle.d.ts +23 -0
- package/dist/lifecycle.js +108 -6
- package/dist/modelCompatibility.d.ts +10 -0
- package/dist/modelCompatibility.js +296 -0
- package/dist/recipe.d.ts +7 -1
- package/dist/recipe.js +112 -10
- package/dist/requiredSandboxValidation.d.ts +2 -1
- package/dist/requiredSandboxValidation.js +36 -2
- package/dist/reviewFilter.d.ts +3 -1
- package/dist/reviewFilter.js +3 -1
- package/dist/setupHooks.js +12 -6
- package/dist/skill2gep.js +72 -8
- package/dist/valueDigest.js +8 -1
- package/dist/windowsLegacyTaskCleanup.d.ts +228 -0
- package/dist/windowsLegacyTaskCleanup.js +1475 -0
- package/dist/workflowRuntime.js +2 -2
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { assetstore, algo, signals, material as materialNs } from '@evomap/evolv
|
|
|
5
5
|
import { loadPriceTable } from '@evomap/evolver-adapter-public';
|
|
6
6
|
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
7
7
|
import { makeInjectEmitter } from './autoexec.js';
|
|
8
|
-
import { listApprovedGenes, provenanceStoreForStore, reviewLedgerForStore } from './reviewFilter.js';
|
|
8
|
+
import { listApprovedGenes, pendingGeneReviewRecords, provenanceStoreForStore, reviewLedgerForStore } from './reviewFilter.js';
|
|
9
9
|
import { ADAPTERS, parseJsonlLines } from '@evomap/evolver-runtime-adapters';
|
|
10
10
|
import { draftGeneCandidate } from './distillPrimitives.js';
|
|
11
11
|
import { assessDraftAdmissionFromStore } from './distillAdmission.js';
|
|
@@ -17,6 +17,7 @@ import { dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
|
17
17
|
import { applyImportV1Plan, planImportV1 } from './migrate/v1Import.js';
|
|
18
18
|
import { explicitRecipeHomes } from './recipe.js';
|
|
19
19
|
import { maybeAutoRestartProxyForSessionStart, sessionStartHookVerboseEnabled, dailyConnectionStatus, lifecyclePaths } from './lifecycle.js';
|
|
20
|
+
import { maybeCleanupLegacyWindowsDaemonTasks } from './windowsLegacyTaskCleanup.js';
|
|
20
21
|
import { formatAntiGeneEvidenceAction, formatAntiGeneEvidenceSummary, summarizeAntiGeneEvidence } from './antiGeneEvidence.js';
|
|
21
22
|
import { buildRuntimeSessionMaterialSnapshot } from './materialSnapshot.js';
|
|
22
23
|
import { maybeEmitNonGitWorkspaceNotice } from './nonGitWorkspaceNotice.js';
|
|
@@ -1146,10 +1147,22 @@ export async function runReview(argv, store, review, deps = {}) {
|
|
|
1146
1147
|
.map((e) => String(e.payload?.['assetId'] ?? ''))
|
|
1147
1148
|
.filter(Boolean));
|
|
1148
1149
|
const autoPending = [...autoDrafted].filter((a) => rev.get(a)?.state === 'quarantined').length;
|
|
1149
|
-
const
|
|
1150
|
+
const pending = await pendingGeneReviewRecords(s, rev);
|
|
1151
|
+
const pendingRows = [];
|
|
1152
|
+
for (const record of pending) {
|
|
1153
|
+
const gene = await s.get(record.assetId);
|
|
1154
|
+
if (gene && gene.type === 'Gene')
|
|
1155
|
+
pendingRows.push(gene);
|
|
1156
|
+
}
|
|
1157
|
+
const autoPendingRows = pendingRows.filter((gene) => autoDrafted.has(String(gene.asset_id))).length;
|
|
1158
|
+
const manualPending = pendingRows.length - autoPendingRows;
|
|
1159
|
+
const listed = await s.list('Gene', Math.max(limit, 1));
|
|
1160
|
+
const pendingIds = new Set(pendingRows.map((gene) => String(gene.asset_id)));
|
|
1161
|
+
const rest = listed.filter((gene) => !pendingIds.has(String(gene.asset_id)));
|
|
1162
|
+
const genes = [...pendingRows, ...rest].slice(0, limit);
|
|
1150
1163
|
if (genes.length === 0)
|
|
1151
|
-
process.stdout.write('(no genes)\n'); // no early return: the
|
|
1152
|
-
for (const g of genes) { // computed from the full
|
|
1164
|
+
process.stdout.write('(no genes)\n'); // no early return: the pending footer below is
|
|
1165
|
+
for (const g of genes) { // computed from the full ledger, so it must print
|
|
1153
1166
|
const id = typeof g['id'] === 'string' ? String(g['id']) : String(g.asset_id);
|
|
1154
1167
|
const view = await assetstore.aggregateLearningHistory(s, id);
|
|
1155
1168
|
const cat = String(g['category'] ?? '?');
|
|
@@ -1162,8 +1175,10 @@ export async function runReview(argv, store, review, deps = {}) {
|
|
|
1162
1175
|
const promote = state === 'quarantined' ? ` promote:${promoteHint(view)}` : '';
|
|
1163
1176
|
process.stdout.write(`${id.padEnd(28)} ${cat.padEnd(10)} total=${view.total} succ=${rate} [${reviewStatus(view)}] {${state}}${promote}${auto}\n`);
|
|
1164
1177
|
}
|
|
1178
|
+
if (manualPending > 0)
|
|
1179
|
+
process.stdout.write(`\n${manualPending} gene(s) awaiting review — approve with \`evolver review --approve <id>\`\n`);
|
|
1165
1180
|
if (autoPending > 0)
|
|
1166
|
-
process.stdout.write(
|
|
1181
|
+
process.stdout.write(`${manualPending > 0 ? '' : '\n'}${autoPending} auto-drafted gene(s) awaiting review — approve with \`evolver review --approve <id>\`\n`);
|
|
1167
1182
|
const antiGenePending = (await listReviewVisibleAntiGenes(s, rev)).filter((asset) => rev.get(String(asset.asset_id))?.state === 'quarantined').length;
|
|
1168
1183
|
if (antiGenePending > 0)
|
|
1169
1184
|
process.stdout.write(`\n${antiGenePending} anti-gene(s) awaiting review - inspect with \`evolver review --anti-gene\`\n`);
|
|
@@ -1540,6 +1555,9 @@ export async function runInject(argv, deps = {}) {
|
|
|
1540
1555
|
process.stderr.write(`[evolver-session-start] proxy auto-restart failed: ${msg}\n`);
|
|
1541
1556
|
}
|
|
1542
1557
|
}
|
|
1558
|
+
// NOTE: the legacy v1 Windows scheduled-task sweep (#956) deliberately runs AFTER the injection
|
|
1559
|
+
// is written to stdout below — a worst-case sweep (probe + lock wait + cleanup ≈ 170s) must never
|
|
1560
|
+
// delay the injection past the host SessionStart hook timeout (see the write-out point below).
|
|
1543
1561
|
maybeEmitNonGitWorkspaceNotice(deps.nonGitNotice);
|
|
1544
1562
|
}
|
|
1545
1563
|
const store = deps.store ?? new assetstore.LocalJsonlProvider(events.assetsDir());
|
|
@@ -1580,6 +1598,36 @@ export async function runInject(argv, deps = {}) {
|
|
|
1580
1598
|
// them, but the preamble explicitly tells it not to narrate routine Evolver work to the user.
|
|
1581
1599
|
if (inj.genes.length > 0 && inj.systemPrompt.trim().length > 0)
|
|
1582
1600
|
process.stdout.write(inj.systemPrompt + '\n');
|
|
1601
|
+
// Legacy v1 Windows scheduled-task sweep (#956): runs AFTER the injection is on stdout so a worst-case
|
|
1602
|
+
// sweep (probe 20s + lock wait 3s + 2×(export 20s + mutation 40s) ≈ 143s) can never push the injection
|
|
1603
|
+
// past the host SessionStart hook timeout and lose it — injection lands first, sweep is trailing.
|
|
1604
|
+
// The owner-lock wait budget is tightened to 3s for the hook path: a held lock almost always means
|
|
1605
|
+
// another evolver process is sweeping right now, and the negative backoff marker covers the retry.
|
|
1606
|
+
// Throttled by a 24h cooldown marker (negative backoff on inconclusive/failed), opt-out via
|
|
1607
|
+
// EVOLVER_SKIP_LEGACY_TASK_PROBE (read AFTER the env-file load so a pointer in the env file is
|
|
1608
|
+
// honored), never throws, and never reports an unprobed host clean.
|
|
1609
|
+
if (fromHookStdin) {
|
|
1610
|
+
try {
|
|
1611
|
+
(deps.legacyTaskSweep ?? (() => {
|
|
1612
|
+
loadEnvFileFromEnv(process.env);
|
|
1613
|
+
const result = maybeCleanupLegacyWindowsDaemonTasks({ env: process.env, lock: { maxTries: 30, waitMs: 100 } });
|
|
1614
|
+
if (result && (result.status === 'cleaned' || result.status === 'failed' || result.status === 'inconclusive')
|
|
1615
|
+
&& sessionStartHookVerboseEnabled(process.env)) {
|
|
1616
|
+
const names = result.tasks.filter((task) => task.outcome === 'removed').map((task) => task.name);
|
|
1617
|
+
const suffix = result.status === 'cleaned' && names.length > 0 ? `: removed ${names.join(', ')}` : result.detail ? `: ${result.detail}` : '';
|
|
1618
|
+
process.stderr.write(`[evolver-session-start] legacy v1 scheduled-task cleanup ${result.status}${suffix}\n`);
|
|
1619
|
+
}
|
|
1620
|
+
}))();
|
|
1621
|
+
}
|
|
1622
|
+
catch {
|
|
1623
|
+
if (sessionStartHookVerboseEnabled(process.env)) {
|
|
1624
|
+
// Do not surface raw PowerShell/OS errors here: they may contain lifecycle paths,
|
|
1625
|
+
// usernames, or command arguments. The cleanup module already returns bounded detail
|
|
1626
|
+
// for structured outcomes; an unexpected throw gets a generic diagnostic.
|
|
1627
|
+
process.stderr.write('[evolver-session-start] legacy task sweep failed\n');
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
}
|
|
1583
1631
|
return 0;
|
|
1584
1632
|
}
|
|
1585
1633
|
/** Fixed preamble for the SessionStart injection (the head block the recap + gene lines hang off of). */
|
|
@@ -1644,6 +1692,9 @@ export function formatDailyReport(report) {
|
|
|
1644
1692
|
L.push('Queue');
|
|
1645
1693
|
L.push(` genes ${q.genesApproved} approved ${q.genesQuarantined} quarantined ${q.genesRejected} rejected`);
|
|
1646
1694
|
L.push(` anti-gene ${q.antiGeneApproved} approved ${q.antiGeneQuarantined} quarantined ${q.antiGeneUnreviewed} unreviewed`);
|
|
1695
|
+
if (q.genesQuarantined > 0) {
|
|
1696
|
+
L.push(` → ${q.genesQuarantined} gene(s) awaiting review — evolver review --approve <id>`);
|
|
1697
|
+
}
|
|
1647
1698
|
return `${L.join('\n')}\n`;
|
|
1648
1699
|
}
|
|
1649
1700
|
export async function collectDailyReport(deps = {}) {
|
|
@@ -1675,37 +1726,53 @@ export async function collectDailyReport(deps = {}) {
|
|
|
1675
1726
|
const reviewRecords = review.records();
|
|
1676
1727
|
const geneReviewCounts = { approved: 0, quarantined: 0, rejected: 0 };
|
|
1677
1728
|
const antiGeneReviewCounts = { approved: 0, quarantined: 0, unreviewed: 0 };
|
|
1678
|
-
//
|
|
1679
|
-
const
|
|
1680
|
-
const
|
|
1681
|
-
const
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1729
|
+
// LocalJsonlProvider 可读取完整索引;其他 provider 使用有界 list,并对未解析记录回退到 get。
|
|
1730
|
+
const localStore = store instanceof assetstore.LocalJsonlProvider;
|
|
1731
|
+
const allGenes = localStore ? store.listAll('Gene') : await store.list('Gene', 10_000);
|
|
1732
|
+
const allAntiGenes = localStore ? store.listAll('AntiGene') : await store.list('AntiGene', 10_000);
|
|
1733
|
+
const geneIds = new Set(allGenes.map((asset) => asset.asset_id));
|
|
1734
|
+
const antiGeneIds = new Set(allAntiGenes.map((asset) => asset.asset_id));
|
|
1735
|
+
const geneReviewRecords = [];
|
|
1736
|
+
const antiGeneReviewRecords = [];
|
|
1737
|
+
// ReviewLedger 可能保留已删除资产或超出 provider list 窗口的资产;get 是这些记录的类型权威。
|
|
1738
|
+
for (const record of reviewRecords) {
|
|
1739
|
+
let kind;
|
|
1740
|
+
if (geneIds.has(record.assetId))
|
|
1741
|
+
kind = 'Gene';
|
|
1742
|
+
else if (antiGeneIds.has(record.assetId))
|
|
1743
|
+
kind = 'AntiGene';
|
|
1692
1744
|
else {
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
geneReviewCounts.quarantined++;
|
|
1696
|
-
else if (r.state === 'rejected')
|
|
1697
|
-
geneReviewCounts.rejected++;
|
|
1698
|
-
else if (r.state === 'approved')
|
|
1699
|
-
geneReviewCounts.approved++;
|
|
1745
|
+
const asset = await store.get(record.assetId);
|
|
1746
|
+
kind = asset?.type;
|
|
1700
1747
|
}
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1748
|
+
if (kind === 'Gene')
|
|
1749
|
+
geneReviewRecords.push(record);
|
|
1750
|
+
else if (kind === 'AntiGene')
|
|
1751
|
+
antiGeneReviewRecords.push(record);
|
|
1752
|
+
}
|
|
1753
|
+
// Count only review records whose asset still exists and has the matching type.
|
|
1754
|
+
for (const record of geneReviewRecords) {
|
|
1755
|
+
if (record.state === 'quarantined')
|
|
1756
|
+
geneReviewCounts.quarantined++;
|
|
1757
|
+
else if (record.state === 'rejected')
|
|
1758
|
+
geneReviewCounts.rejected++;
|
|
1759
|
+
else if (record.state === 'approved')
|
|
1760
|
+
geneReviewCounts.approved++;
|
|
1761
|
+
}
|
|
1762
|
+
for (const record of antiGeneReviewRecords) {
|
|
1763
|
+
if (record.state === 'quarantined')
|
|
1764
|
+
antiGeneReviewCounts.quarantined++;
|
|
1765
|
+
else if (record.state === 'approved')
|
|
1766
|
+
antiGeneReviewCounts.approved++;
|
|
1767
|
+
}
|
|
1768
|
+
// Gene without a review record remains default-approved.
|
|
1769
|
+
const reviewedGeneIds = new Set(geneReviewRecords.map((record) => record.assetId));
|
|
1770
|
+
const antiGeneReviewById = new Map(antiGeneReviewRecords.map((record) => [record.assetId, record]));
|
|
1771
|
+
const unreviewedGeneCount = allGenes.filter((gene) => !reviewedGeneIds.has(gene.asset_id)).length;
|
|
1705
1772
|
geneReviewCounts.approved += unreviewedGeneCount;
|
|
1706
1773
|
// AntiGenes without explicit approval are unreviewed (fail-closed)
|
|
1707
1774
|
for (const ag of allAntiGenes) {
|
|
1708
|
-
const r =
|
|
1775
|
+
const r = antiGeneReviewById.get(ag.asset_id);
|
|
1709
1776
|
if (!r || (r.state !== 'approved' && r.state !== 'quarantined')) {
|
|
1710
1777
|
antiGeneReviewCounts.unreviewed++;
|
|
1711
1778
|
}
|
package/dist/lifecycle.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { spawn } from 'node:child_process';
|
|
2
2
|
import { bootstrap as coreBootstrap, util as coreUtil } from '@evomap/evolver-core';
|
|
3
3
|
import { type BootstrapTransactionJournal, type BootstrapArtifactIdentity, type LegacyBootstrapMarkerRead } from './lifecycleBootstrapTransaction.js';
|
|
4
|
+
import { type LegacyTaskCleanupResult, type LegacyTaskRun } from './windowsLegacyTaskCleanup.js';
|
|
4
5
|
export declare function selectExistingPosixCommand(candidates: readonly string[], exists?: (path: string) => boolean): string;
|
|
5
6
|
export type ServiceTarget = 'launchd' | 'systemd' | 'windows';
|
|
6
7
|
export interface DaemonCommand {
|
|
@@ -59,6 +60,25 @@ interface RunLifecycleDeps {
|
|
|
59
60
|
loadUnixRecoveryController?: LoadUnixRecoveryController;
|
|
60
61
|
removeAutoexecService?: (target: ServiceTarget, dryRun: boolean) => LifecycleResult;
|
|
61
62
|
bootstrap?: BootstrapServiceDeps;
|
|
63
|
+
/** Test seam for the legacy v1 Windows scheduled-task cleanup subcommand (#956). */
|
|
64
|
+
cleanupLegacyTasks?: (options: {
|
|
65
|
+
env: NodeJS.ProcessEnv;
|
|
66
|
+
stateDir?: string;
|
|
67
|
+
dryRun?: boolean;
|
|
68
|
+
platform?: NodeJS.Platform;
|
|
69
|
+
run?: LegacyTaskRun;
|
|
70
|
+
}) => LegacyTaskCleanupResult;
|
|
71
|
+
/** Test seam for the legacy v1 task preimage restore subcommand (#956). */
|
|
72
|
+
restoreLegacyTaskPreimage?: (preimagePath: string, options: {
|
|
73
|
+
env: NodeJS.ProcessEnv;
|
|
74
|
+
platform?: NodeJS.Platform;
|
|
75
|
+
run?: LegacyTaskRun;
|
|
76
|
+
stateDir?: string;
|
|
77
|
+
}) => {
|
|
78
|
+
status: 'restored' | 'failed';
|
|
79
|
+
task?: string;
|
|
80
|
+
detail: string;
|
|
81
|
+
};
|
|
62
82
|
stdout?: (text: string) => void;
|
|
63
83
|
stderr?: (text: string) => void;
|
|
64
84
|
}
|
|
@@ -78,6 +98,8 @@ export interface BootstrapServiceDeps {
|
|
|
78
98
|
install?: (target: ServiceTarget, flags: Record<string, string | true>, env: NodeJS.ProcessEnv, argv1: string | undefined, loadUnixRecoveryController?: LoadUnixRecoveryController, options?: InstallServiceOptions) => Promise<LifecycleResult>;
|
|
79
99
|
writeMarker?: (path: string, marker: coreBootstrap.LifecycleBootstrapMarker) => void;
|
|
80
100
|
inspectSelfUpdate?: InspectDurableSelfUpdate;
|
|
101
|
+
/** Test seam for the post-activation legacy v1 Windows task sweep (#956). */
|
|
102
|
+
legacyTaskCleanupRun?: LegacyTaskRun;
|
|
81
103
|
}
|
|
82
104
|
interface ServiceControlResult {
|
|
83
105
|
status: number | null;
|
|
@@ -180,6 +202,7 @@ interface LegacyWindowsInstallerProof {
|
|
|
180
202
|
}
|
|
181
203
|
declare function parseLegacyWindowsInstallerDefaults(source: string): LegacyWindowsInstallerProof;
|
|
182
204
|
export declare const _parseLegacyWindowsInstallerDefaultsForTest: typeof parseLegacyWindowsInstallerDefaults;
|
|
205
|
+
export declare function trustedWindowsPowerShell(): string;
|
|
183
206
|
declare function renderWindowsProxyLauncherBytes(defaults: WindowsInstallerDefaults): Buffer;
|
|
184
207
|
declare function renderLegacyWindowsProxyLauncherBytes(proof: LegacyWindowsInstallerProof): Buffer;
|
|
185
208
|
export declare const _renderWindowsProxyLauncherBytesForTest: typeof renderWindowsProxyLauncherBytes;
|
package/dist/lifecycle.js
CHANGED
|
@@ -8,6 +8,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
8
8
|
import { bootstrap as coreBootstrap, util as coreUtil } from '@evomap/evolver-core';
|
|
9
9
|
import { expandHomePath, loadEnvFile, loadEnvFileFromEnv, parseEnvFile } from '@evomap/evolver-mcp';
|
|
10
10
|
import { acquireBootstrapOwnerLock, acquireBootstrapReadinessLock, adoptLegacyBootstrapMarker, applyBootstrapCanonicalQuarantine, assertTrustedArtifactParent, assertActiveBootstrapRegistrationIntentToken, assertPlannedArtifactsAbsent, assertBootstrapTransactionClaimsAbsent, bootstrapArtifactClaimPath, bootstrapArtifactContentIdentityForFile, bootstrapArtifactIdentityForBytes, bootstrapJournalPath, bootstrapJournalFromMarker, bootstrapJournalManagerArtifactPath, bootstrapMarkerPath, bootstrapReadinessPath, captureBootstrapArtifactIdentities, createLegacyBootstrapRemovalJournal, createBootstrapJournal, ensureBootstrapManualTransition, finalizeBootstrapCanonicalQuarantine, planBootstrapCanonicalQuarantine, readBootstrapJournal, readBootstrapArtifactFile, readLegacyBootstrapMarker, readBootstrapManualTransition, readBootstrapMarker, readBootstrapReadiness, recordPublishedBootstrapArtifact, removeBootstrapJournal, removeBootstrapManualTransition, removeBootstrapReadiness, removeDurableFile, removeOwnedBootstrapArtifacts, restoreBootstrapCanonicalQuarantine, updateBootstrapJournal, writeBootstrapJournal, writeDurableBytesExclusive, writeDurableJsonExclusive, writeDurableTextExclusive, LEGACY_BOOTSTRAP_REMOVAL_OPERATION, } from './lifecycleBootstrapTransaction.js';
|
|
11
|
+
import { cleanupLegacyWindowsDaemonTasks, legacyTaskProbeSkipped, restoreLegacyTaskPreimage, sweepLegacyWindowsDaemonTasksAfterBootstrap, LEGACY_TASK_SKIP_ENV, } from './windowsLegacyTaskCleanup.js';
|
|
11
12
|
const requireFromHere = createRequire(import.meta.url);
|
|
12
13
|
const DEFAULT_DAEMON_NAME = 'evolver-proxy';
|
|
13
14
|
const DEFAULT_LABEL = 'com.evomap.evolver-proxy';
|
|
@@ -35,7 +36,7 @@ const PS_PATH = selectExistingPosixCommand([
|
|
|
35
36
|
const LAUNCHCTL_PATH = '/bin/launchctl';
|
|
36
37
|
const UNIX_RECOVERY_CONTROLLER_FILENAME = 'evolver-recovery-controller';
|
|
37
38
|
const HOST_WINDOWS_SYSTEM_ROOT = process.env['SystemRoot']?.trim() || 'C:\\Windows';
|
|
38
|
-
const LIFECYCLE_USAGE = 'Usage: evolver lifecycle <start|stop|restart|status|check|watch|install-service --target=launchd|systemd|windows [--with-autoexec] [--autoexec-home=<path>]|remove-service --target=launchd|systemd|windows [--dry-run] [--env-file=<path>]|bootstrap [--target=launchd|systemd|windows] [--dry-run]|remove-autoexec-service --target=launchd|systemd|windows [--dry-run]
|
|
39
|
+
const LIFECYCLE_USAGE = 'Usage: evolver lifecycle <start|stop|restart|status|check|watch|install-service --target=launchd|systemd|windows [--with-autoexec] [--autoexec-home=<path>]|remove-service --target=launchd|systemd|windows [--dry-run] [--env-file=<path>]|bootstrap [--target=launchd|systemd|windows] [--dry-run]|remove-autoexec-service --target=launchd|systemd|windows [--dry-run]|cleanup-legacy-tasks [--dry-run]|restore-legacy-task-preimage --preimage=<path>>\n';
|
|
39
40
|
export function selectExistingPosixCommand(candidates, exists = existsSync) {
|
|
40
41
|
if (candidates.length === 0 || candidates.some((candidate) => !posix.isAbsolute(candidate))) {
|
|
41
42
|
throw new Error('trusted command candidates must be non-empty absolute POSIX paths');
|
|
@@ -336,9 +337,41 @@ async function runLifecycleCommandInner(argv, deps) {
|
|
|
336
337
|
: loadEnvFileFromEnv(env);
|
|
337
338
|
if (envFileResult.error)
|
|
338
339
|
throw new Error('failed to load lifecycle environment file');
|
|
340
|
+
// Like install-service: recompute AFTER the env-file load so a state-dir pointer in
|
|
341
|
+
// the env file is honored by the piggyback legacy sweep below (the `paths` captured
|
|
342
|
+
// before the load would put owner lock/preimage/cooldown state in the wrong dir).
|
|
343
|
+
const removeStateDir = lifecyclePaths(env).stateDir;
|
|
339
344
|
const result = await removeBootstrapService(removeFlags.target, removeFlags.dryRun, env, deps.bootstrap ?? {}, deps.argv1 ?? process.argv[1], deps.loadUnixRecoveryController, removeFlags.envFile ? { 'env-file': removeFlags.envFile } : {});
|
|
340
|
-
|
|
341
|
-
|
|
345
|
+
const payload = { ...result };
|
|
346
|
+
let exitCode = 0;
|
|
347
|
+
if (removeFlags.target === 'windows') {
|
|
348
|
+
// #956 uninstall path: after the owned v2 manager removal, sweep legacy v1 residue.
|
|
349
|
+
// The sweep keeps its own fail-closed semantics and is reported in the payload.
|
|
350
|
+
// This composite command must also return non-zero when the sweep cannot prove a
|
|
351
|
+
// conclusive result, so payload-aware and exit-code-aware automation see the same truth.
|
|
352
|
+
// Unlike that explicit command, this piggyback sweep honors the opt-out so suites
|
|
353
|
+
// and opted-out hosts never touch the real Task Scheduler.
|
|
354
|
+
if (legacyTaskProbeSkipped(env)) {
|
|
355
|
+
payload.legacyTaskCleanup = {
|
|
356
|
+
status: 'skipped',
|
|
357
|
+
detail: `${LEGACY_TASK_SKIP_ENV} is set; run evolver lifecycle cleanup-legacy-tasks explicitly`,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
const sweep = (deps.cleanupLegacyTasks ?? cleanupLegacyWindowsDaemonTasks)({
|
|
362
|
+
env,
|
|
363
|
+
stateDir: removeStateDir,
|
|
364
|
+
dryRun: removeFlags.dryRun,
|
|
365
|
+
});
|
|
366
|
+
payload.legacyTaskCleanup = sweep;
|
|
367
|
+
if (sweep.status === 'failed' || sweep.status === 'inconclusive') {
|
|
368
|
+
exitCode = 1;
|
|
369
|
+
stderr(`legacy v1 scheduled-task cleanup ${sweep.status}${sweep.detail ? `: ${sweep.detail}` : ''}; run evolver lifecycle cleanup-legacy-tasks\n`);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
stdout(`${JSON.stringify(payload, null, 2)}\n`);
|
|
374
|
+
return exitCode;
|
|
342
375
|
}
|
|
343
376
|
case 'remove-autoexec-service': {
|
|
344
377
|
if (flags['dry-run'] !== undefined && flags['dry-run'] !== true) {
|
|
@@ -349,6 +382,42 @@ async function runLifecycleCommandInner(argv, deps) {
|
|
|
349
382
|
stdout(`${JSON.stringify(result, null, 2)}\n`);
|
|
350
383
|
return 0;
|
|
351
384
|
}
|
|
385
|
+
case 'cleanup-legacy-tasks': {
|
|
386
|
+
if (flags['dry-run'] !== undefined && flags['dry-run'] !== true) {
|
|
387
|
+
throw new Error('--dry-run is a boolean flag and does not accept a value');
|
|
388
|
+
}
|
|
389
|
+
const cleanupEnvFileResult = loadEnvFileFromEnv(env);
|
|
390
|
+
if (cleanupEnvFileResult.error)
|
|
391
|
+
throw new Error('failed to load lifecycle environment file');
|
|
392
|
+
// Read AFTER the env-file load so a pointer in the env file is honored
|
|
393
|
+
// (mirrors the session-start sweep in index.ts).
|
|
394
|
+
const result = (deps.cleanupLegacyTasks ?? cleanupLegacyWindowsDaemonTasks)({
|
|
395
|
+
env,
|
|
396
|
+
stateDir: lifecyclePaths(env).stateDir,
|
|
397
|
+
dryRun: flags['dry-run'] === true,
|
|
398
|
+
});
|
|
399
|
+
stdout(`${JSON.stringify(result, null, 2)}\n`);
|
|
400
|
+
// An inconclusive or failed run must surface a non-zero exit: automation that reads
|
|
401
|
+
// the status field and automation that reads the exit code get the same truth.
|
|
402
|
+
return result.status === 'inconclusive' || result.status === 'failed' ? 1 : 0;
|
|
403
|
+
}
|
|
404
|
+
case 'restore-legacy-task-preimage': {
|
|
405
|
+
const preimage = typeof flags['preimage'] === 'string' ? flags['preimage'] : undefined;
|
|
406
|
+
if (!preimage) {
|
|
407
|
+
throw new Error('restore-legacy-task-preimage requires --preimage=<path>');
|
|
408
|
+
}
|
|
409
|
+
const restoreEnvFileResult = loadEnvFileFromEnv(env);
|
|
410
|
+
if (restoreEnvFileResult.error)
|
|
411
|
+
throw new Error('failed to load lifecycle environment file');
|
|
412
|
+
// Read AFTER the env-file load so a pointer in the env file is honored
|
|
413
|
+
// (mirrors the session-start sweep in index.ts).
|
|
414
|
+
const result = (deps.restoreLegacyTaskPreimage ?? restoreLegacyTaskPreimage)(preimage, {
|
|
415
|
+
env,
|
|
416
|
+
stateDir: lifecyclePaths(env).stateDir,
|
|
417
|
+
});
|
|
418
|
+
stdout(`${JSON.stringify(result, null, 2)}\n`);
|
|
419
|
+
return result.status === 'restored' ? 0 : 1;
|
|
420
|
+
}
|
|
352
421
|
default:
|
|
353
422
|
stderr(LIFECYCLE_USAGE);
|
|
354
423
|
return action === undefined ? 0 : 1;
|
|
@@ -812,7 +881,7 @@ function trustedWindowsSystemExecutable(name) {
|
|
|
812
881
|
}
|
|
813
882
|
return win32.join(HOST_WINDOWS_SYSTEM_ROOT, 'System32', name);
|
|
814
883
|
}
|
|
815
|
-
function trustedWindowsPowerShell() {
|
|
884
|
+
export function trustedWindowsPowerShell() {
|
|
816
885
|
return trustedWindowsSystemExecutable('WindowsPowerShell\\v1.0\\powershell.exe');
|
|
817
886
|
}
|
|
818
887
|
function renderWindowsProxyLauncherBytes(defaults) {
|
|
@@ -2495,6 +2564,12 @@ async function bootstrapService(flags, env, argv1, deps, loadUnixRecoveryControl
|
|
|
2495
2564
|
if (!plannedArtifactIdentities)
|
|
2496
2565
|
throw new Error('bootstrap install plan did not declare expected artifact identities');
|
|
2497
2566
|
requireBootstrapManagerState(probeBootstrapManagerState(target, ownerRun, uid, commandTimeout(deadlineMs, now, BOOTSTRAP_ROLLBACK_RESERVE_MS)), ['absent'], 'preflight existing service check');
|
|
2567
|
+
// Trust the artifact-parent chain with the HOST platform, never the injected target platform.
|
|
2568
|
+
// The deeper owner-lock guard (assertTrustedArtifactParent at .bootstrap-owner) already uses
|
|
2569
|
+
// process.platform; matching it here keeps preflight consistent. Routing this preflight through an
|
|
2570
|
+
// injected POSIX platform on a Windows host would run the POSIX mode-bit chain against a real NTFS
|
|
2571
|
+
// directory, where Node simulates group/world-writable bits and the guard false-positives (#972: the
|
|
2572
|
+
// native-CI bootstrap suite runs with platform:'linux'/'darwin' fixtures on a Windows runner).
|
|
2498
2573
|
assertPlannedArtifactsAbsent(plannedArtifacts, process.platform, uid);
|
|
2499
2574
|
assertForwardMutationBudget(deadlineMs, now());
|
|
2500
2575
|
let journal = createBootstrapJournal({
|
|
@@ -2557,7 +2632,7 @@ async function bootstrapService(flags, env, argv1, deps, loadUnixRecoveryControl
|
|
|
2557
2632
|
assertForwardMutationBudget(deadlineMs, now());
|
|
2558
2633
|
return result;
|
|
2559
2634
|
};
|
|
2560
|
-
const actions = activateBootstrapTarget(target, files, forwardRun, uid, deadlineMs, now);
|
|
2635
|
+
const actions = [...activateBootstrapTarget(target, files, forwardRun, uid, deadlineMs, now)];
|
|
2561
2636
|
const managerPid = await waitForBootstrapManagerBinding(journal, forwardRun, uid, deadlineMs, now, deps.healthTimeoutMs ?? BOOTSTRAP_HEALTH_TIMEOUT_MS, assertOwner);
|
|
2562
2637
|
assertOwner();
|
|
2563
2638
|
const healthyReadiness = await requireBootstrapProxyHealth(lifecyclePaths(env), env, journal, managerPid, deps, forwardRun, uid, deadlineMs, now, assertOwner);
|
|
@@ -2621,6 +2696,18 @@ async function bootstrapService(flags, env, argv1, deps, loadUnixRecoveryControl
|
|
|
2621
2696
|
catch {
|
|
2622
2697
|
// The durable versioned marker is the commit point. Recovery recognizes its transaction id.
|
|
2623
2698
|
}
|
|
2699
|
+
if (target === 'windows') {
|
|
2700
|
+
// Post-activation sweep (#956): remove legacy V1 scheduled-task residue under the
|
|
2701
|
+
// already-held owner lock. Best-effort for the bootstrap (the committed marker is
|
|
2702
|
+
// the commit point and a sweep error can never roll it back), but an inconclusive
|
|
2703
|
+
// or failed sweep is reported in `actions` instead of being hidden.
|
|
2704
|
+
actions.push(...sweepLegacyWindowsDaemonTasksAfterBootstrap({
|
|
2705
|
+
env,
|
|
2706
|
+
stateDir,
|
|
2707
|
+
assertOwner,
|
|
2708
|
+
...(deps.legacyTaskCleanupRun ? { run: deps.legacyTaskCleanupRun } : {}),
|
|
2709
|
+
}));
|
|
2710
|
+
}
|
|
2624
2711
|
return {
|
|
2625
2712
|
status: 'bootstrapped',
|
|
2626
2713
|
transactionId: marker.transactionId,
|
|
@@ -5263,11 +5350,26 @@ function normalizeFsIdentity(value) {
|
|
|
5263
5350
|
function isPidRunning(pid) {
|
|
5264
5351
|
try {
|
|
5265
5352
|
process.kill(pid, 0);
|
|
5266
|
-
return true;
|
|
5267
5353
|
}
|
|
5268
5354
|
catch (err) {
|
|
5269
5355
|
return err.code === 'EPERM';
|
|
5270
5356
|
}
|
|
5357
|
+
// Detached Unix children that have already exited can remain zombies while kill(0)
|
|
5358
|
+
// still succeeds. Treat zombie / defunct state as not running so stop waits complete.
|
|
5359
|
+
if (process.platform === 'win32')
|
|
5360
|
+
return true;
|
|
5361
|
+
try {
|
|
5362
|
+
const state = execFileSync(PS_PATH, ['-p', String(pid), '-o', 'state='], {
|
|
5363
|
+
encoding: 'utf8',
|
|
5364
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
5365
|
+
}).trim();
|
|
5366
|
+
if (state.startsWith('Z'))
|
|
5367
|
+
return false;
|
|
5368
|
+
}
|
|
5369
|
+
catch {
|
|
5370
|
+
// Keep the kill(0) success if process-state inspection is unavailable.
|
|
5371
|
+
}
|
|
5372
|
+
return true;
|
|
5271
5373
|
}
|
|
5272
5374
|
function waitForExit(pid, timeoutMs) {
|
|
5273
5375
|
const start = Date.now();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { compatibility, exec, verify } from '@evomap/evolver-core';
|
|
2
|
+
export interface ModelCompatibilityReplayDeps {
|
|
3
|
+
spawn?: typeof exec.spawnCapture;
|
|
4
|
+
validation?: typeof verify.runSandboxedValidation;
|
|
5
|
+
isolationAvailable?: () => boolean;
|
|
6
|
+
}
|
|
7
|
+
declare function claudeArgs(test: compatibility.ReplayCase): string[];
|
|
8
|
+
export declare function runModelCompatibilityReplay(argv: string[], deps?: ModelCompatibilityReplayDeps): Promise<number>;
|
|
9
|
+
export declare const modelCompatibilityClaudeArgs: typeof claudeArgs;
|
|
10
|
+
export {};
|