@evomap/evolver-cli 2.0.0-beta.2 → 2.0.0-beta.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assetHealth.d.ts +6 -0
- package/dist/assetHealth.js +105 -0
- package/dist/assetSidecarRecovery.d.ts +14 -0
- package/dist/assetSidecarRecovery.js +171 -0
- package/dist/assetTrust.d.ts +24 -0
- package/dist/assetTrust.js +218 -0
- package/dist/autoexec.d.ts +9 -2
- package/dist/autoexec.js +48 -8
- package/dist/cycleConsumer.d.ts +4 -2
- package/dist/cycleConsumer.js +194 -36
- package/dist/dashboard.d.ts +3 -1
- package/dist/dashboard.js +22 -4
- package/dist/dispatch.d.ts +9 -1
- package/dist/dispatch.js +9 -0
- package/dist/doctor.d.ts +2 -0
- package/dist/doctor.js +18 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +76 -8
- package/dist/lifecycle.d.ts +19 -1
- package/dist/lifecycle.js +220 -27
- package/dist/localMemoryGraph.d.ts +97 -0
- package/dist/localMemoryGraph.js +889 -0
- package/dist/migrate/v1Import.d.ts +7 -1
- package/dist/migrate/v1Import.js +132 -11
- package/dist/runtimeCapabilities.d.ts +18 -0
- package/dist/runtimeCapabilities.js +81 -0
- package/package.json +11 -7
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { assetstore } from '@evomap/evolver-core';
|
|
2
|
+
import { type AssetSidecarRecoveryCommandDeps } from './assetSidecarRecovery.js';
|
|
3
|
+
export interface AssetHealthDeps extends AssetSidecarRecoveryCommandDeps {
|
|
4
|
+
inspect?: (assetsDir: string) => assetstore.AssetStoreHealthReport;
|
|
5
|
+
}
|
|
6
|
+
export declare function runAssetHealthCommand(argv: readonly string[], deps?: AssetHealthDeps): Promise<number>;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { assetstore, events } from '@evomap/evolver-core';
|
|
2
|
+
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
3
|
+
import { ASSET_SIDECAR_RECOVERY_USAGE, runAssetSidecarRecoveryCommand, } from './assetSidecarRecovery.js';
|
|
4
|
+
const GROUP = 'asset-health';
|
|
5
|
+
const USAGE = [
|
|
6
|
+
'Usage:',
|
|
7
|
+
' evolver asset-health [--json]',
|
|
8
|
+
ASSET_SIDECAR_RECOVERY_USAGE,
|
|
9
|
+
'',
|
|
10
|
+
].join('\n');
|
|
11
|
+
function writeJson(write, value) {
|
|
12
|
+
write(`${JSON.stringify(value)}\n`);
|
|
13
|
+
}
|
|
14
|
+
function renderText(report, stdout) {
|
|
15
|
+
stdout([
|
|
16
|
+
`asset health: status=${report.status}`,
|
|
17
|
+
`unique=${report.totals.uniqueAssets}`,
|
|
18
|
+
`corrupt=${report.totals.corruptRows}`,
|
|
19
|
+
`duplicate=${report.totals.duplicateRows}`,
|
|
20
|
+
`hash_mismatch=${report.totals.hashMismatchRows}`,
|
|
21
|
+
`schema_invalid=${report.totals.schemaInvalidRows}`,
|
|
22
|
+
`unsafe=${report.totals.unsafeFiles}`,
|
|
23
|
+
`unavailable=${report.totals.unavailableFiles}`,
|
|
24
|
+
].join(' ') + '\n');
|
|
25
|
+
for (const file of report.files) {
|
|
26
|
+
stdout([
|
|
27
|
+
file.kind,
|
|
28
|
+
file.file,
|
|
29
|
+
`status=${file.status}`,
|
|
30
|
+
`rows=${file.rows}`,
|
|
31
|
+
`unique=${file.uniqueAssets}`,
|
|
32
|
+
`corrupt=${file.corruptRows}`,
|
|
33
|
+
`duplicate=${file.duplicateRows}`,
|
|
34
|
+
`hash_mismatch=${file.hashMismatchRows}`,
|
|
35
|
+
`schema_invalid=${file.schemaInvalidRows}`,
|
|
36
|
+
...(file.unterminated ? ['unterminated=true'] : []),
|
|
37
|
+
...(file.reason ? [`reason=${file.reason}`] : []),
|
|
38
|
+
].join(' ') + '\n');
|
|
39
|
+
}
|
|
40
|
+
stdout([
|
|
41
|
+
'sidecar health:',
|
|
42
|
+
`corrupt=${report.sidecarTotals.corruptRows}`,
|
|
43
|
+
`unterminated=${report.sidecarTotals.unterminatedFiles}`,
|
|
44
|
+
`unsafe=${report.sidecarTotals.unsafeFiles}`,
|
|
45
|
+
`unavailable=${report.sidecarTotals.unavailableFiles}`,
|
|
46
|
+
].join(' ') + '\n');
|
|
47
|
+
for (const sidecar of report.sidecars) {
|
|
48
|
+
stdout([
|
|
49
|
+
sidecar.kind,
|
|
50
|
+
sidecar.file,
|
|
51
|
+
`status=${sidecar.status}`,
|
|
52
|
+
`rows=${sidecar.rows}`,
|
|
53
|
+
`valid=${sidecar.validRows}`,
|
|
54
|
+
`corrupt=${sidecar.corruptRows}`,
|
|
55
|
+
...(sidecar.unterminated ? ['unterminated=true'] : []),
|
|
56
|
+
...(sidecar.reason ? [`reason=${sidecar.reason}`] : []),
|
|
57
|
+
].join(' ') + '\n');
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
export async function runAssetHealthCommand(argv, deps = {}) {
|
|
61
|
+
const stdout = deps.stdout ?? ((text) => { process.stdout.write(text); });
|
|
62
|
+
const stderr = deps.stderr ?? ((text) => { process.stderr.write(text); });
|
|
63
|
+
const json = argv.includes('--json');
|
|
64
|
+
if (argv.includes('--help') || argv.includes('-h')) {
|
|
65
|
+
stdout(USAGE);
|
|
66
|
+
return 0;
|
|
67
|
+
}
|
|
68
|
+
const repairIndex = argv.indexOf('repair-sidecar');
|
|
69
|
+
if (repairIndex >= 0) {
|
|
70
|
+
const repairArgs = ['repair-sidecar', ...argv.slice(0, repairIndex), ...argv.slice(repairIndex + 1)];
|
|
71
|
+
return runAssetSidecarRecoveryCommand(repairArgs, deps);
|
|
72
|
+
}
|
|
73
|
+
if (argv.some((arg) => arg !== '--json')) {
|
|
74
|
+
if (json)
|
|
75
|
+
writeJson(stdout, { ok: false, group: GROUP, reason: 'unknown_argument' });
|
|
76
|
+
else
|
|
77
|
+
stderr(`[asset-health] unknown_argument\n${USAGE}`);
|
|
78
|
+
return 2;
|
|
79
|
+
}
|
|
80
|
+
const env = deps.env ?? process.env;
|
|
81
|
+
const envFile = loadEnvFileFromEnv(env);
|
|
82
|
+
if (envFile.error) {
|
|
83
|
+
if (json)
|
|
84
|
+
writeJson(stdout, { ok: false, group: GROUP, reason: 'env_file_unavailable' });
|
|
85
|
+
else
|
|
86
|
+
stderr('[asset-health] env_file_unavailable\n');
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
const inspect = deps.inspect ?? assetstore.inspectLocalAssetStore;
|
|
90
|
+
const report = inspect(deps.assetsDir ?? (deps.resolveAssetsDir ?? events.assetsDir)());
|
|
91
|
+
const result = {
|
|
92
|
+
ok: report.ok,
|
|
93
|
+
group: GROUP,
|
|
94
|
+
status: report.status,
|
|
95
|
+
totals: report.totals,
|
|
96
|
+
files: report.files,
|
|
97
|
+
sidecarTotals: report.sidecarTotals,
|
|
98
|
+
sidecars: report.sidecars,
|
|
99
|
+
};
|
|
100
|
+
if (json)
|
|
101
|
+
writeJson(stdout, result);
|
|
102
|
+
else
|
|
103
|
+
renderText(report, stdout);
|
|
104
|
+
return report.ok ? 0 : 1;
|
|
105
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { assetstore, events } from '@evomap/evolver-core';
|
|
2
|
+
export declare const ASSET_SIDECAR_RECOVERY_USAGE: string;
|
|
3
|
+
type RecoveryEventWriter = Pick<events.Ingestor, 'ingest'>;
|
|
4
|
+
export interface AssetSidecarRecoveryCommandDeps {
|
|
5
|
+
env?: Record<string, string | undefined>;
|
|
6
|
+
assetsDir?: string;
|
|
7
|
+
resolveAssetsDir?: () => string;
|
|
8
|
+
recover?: typeof assetstore.recoverAssetSidecar;
|
|
9
|
+
ingestor?: RecoveryEventWriter;
|
|
10
|
+
stdout?: (text: string) => void;
|
|
11
|
+
stderr?: (text: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function runAssetSidecarRecoveryCommand(argv: readonly string[], deps?: AssetSidecarRecoveryCommandDeps): Promise<number>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { assetstore, events, hub } from '@evomap/evolver-core';
|
|
2
|
+
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
3
|
+
const GROUP = 'asset-health.repair';
|
|
4
|
+
const ACTOR_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_.@:-]{0,79}$/;
|
|
5
|
+
export const ASSET_SIDECAR_RECOVERY_USAGE = [
|
|
6
|
+
' evolver asset-health repair-sidecar --sidecar <provenance|review|asset-sync> --replacement <file>',
|
|
7
|
+
' [--write --acknowledge-corrupt-history] [--json]',
|
|
8
|
+
].join('\n');
|
|
9
|
+
function writeJson(write, value) {
|
|
10
|
+
write(`${JSON.stringify(value)}\n`);
|
|
11
|
+
}
|
|
12
|
+
function parseRepairArgs(argv) {
|
|
13
|
+
let sidecar;
|
|
14
|
+
let replacementPath;
|
|
15
|
+
let write = false;
|
|
16
|
+
let acknowledgeCorruptHistory = false;
|
|
17
|
+
let json = false;
|
|
18
|
+
for (let index = 1; index < argv.length; index += 1) {
|
|
19
|
+
const arg = argv[index];
|
|
20
|
+
if (arg === '--json') {
|
|
21
|
+
if (json)
|
|
22
|
+
return 'duplicate_argument';
|
|
23
|
+
json = true;
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (arg === '--write') {
|
|
27
|
+
if (write)
|
|
28
|
+
return 'duplicate_argument';
|
|
29
|
+
write = true;
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
if (arg === '--acknowledge-corrupt-history') {
|
|
33
|
+
if (acknowledgeCorruptHistory)
|
|
34
|
+
return 'duplicate_argument';
|
|
35
|
+
acknowledgeCorruptHistory = true;
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
if (arg === '--sidecar') {
|
|
39
|
+
if (sidecar !== undefined)
|
|
40
|
+
return 'duplicate_argument';
|
|
41
|
+
const value = argv[index + 1];
|
|
42
|
+
if (value !== 'provenance' && value !== 'review' && value !== 'asset-sync')
|
|
43
|
+
return 'invalid_sidecar';
|
|
44
|
+
sidecar = value;
|
|
45
|
+
index += 1;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (arg === '--replacement') {
|
|
49
|
+
if (replacementPath !== undefined)
|
|
50
|
+
return 'duplicate_argument';
|
|
51
|
+
const value = argv[index + 1];
|
|
52
|
+
if (!value || value.startsWith('--'))
|
|
53
|
+
return 'replacement_required';
|
|
54
|
+
replacementPath = value;
|
|
55
|
+
index += 1;
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
return 'unknown_argument';
|
|
59
|
+
}
|
|
60
|
+
if (!sidecar)
|
|
61
|
+
return 'sidecar_required';
|
|
62
|
+
if (!replacementPath)
|
|
63
|
+
return 'replacement_required';
|
|
64
|
+
if (acknowledgeCorruptHistory && !write)
|
|
65
|
+
return 'acknowledgement_requires_write';
|
|
66
|
+
if (write && !acknowledgeCorruptHistory)
|
|
67
|
+
return 'acknowledgement_required';
|
|
68
|
+
return { sidecar, replacementPath, write, acknowledgeCorruptHistory, json };
|
|
69
|
+
}
|
|
70
|
+
function safeActorId(env) {
|
|
71
|
+
const raw = env['EVOLVER_ACTOR_ID'] ?? env['USER'] ?? env['LOGNAME'] ?? env['USERNAME'] ?? 'cli';
|
|
72
|
+
const trimmed = raw.trim();
|
|
73
|
+
return ACTOR_ID_RE.test(trimmed) && hub.redactString(trimmed) === trimmed ? trimmed : 'cli';
|
|
74
|
+
}
|
|
75
|
+
function failure(reason, json, stdout, stderr, exitCode) {
|
|
76
|
+
if (json)
|
|
77
|
+
writeJson(stdout, { ok: false, group: GROUP, reason });
|
|
78
|
+
else
|
|
79
|
+
stderr(`[asset-health] repair-sidecar ${reason}\n${exitCode === 2 ? ASSET_SIDECAR_RECOVERY_USAGE + '\n' : ''}`);
|
|
80
|
+
return exitCode;
|
|
81
|
+
}
|
|
82
|
+
function recoveryReason(error) {
|
|
83
|
+
if (error instanceof assetstore.AssetSidecarRecoveryError)
|
|
84
|
+
return error.reason;
|
|
85
|
+
if (typeof error === 'object' && error !== null && 'code' in error) {
|
|
86
|
+
if (error.code === 'UNSAFE_ASSET_STORE_PATH')
|
|
87
|
+
return 'unsafe_path';
|
|
88
|
+
if (error.code === 'LOCK_RELEASE_FAILED')
|
|
89
|
+
return 'lock_unavailable';
|
|
90
|
+
}
|
|
91
|
+
return 'recovery_failed';
|
|
92
|
+
}
|
|
93
|
+
async function recordRecoveryEvent(ingestor, result, actorId) {
|
|
94
|
+
if (!result.changed || !result.backupId)
|
|
95
|
+
return false;
|
|
96
|
+
try {
|
|
97
|
+
await ingestor.ingest({
|
|
98
|
+
type: 'actor.human.sidecar.recover',
|
|
99
|
+
payload: {
|
|
100
|
+
sidecar: result.sidecar,
|
|
101
|
+
backupId: result.backupId,
|
|
102
|
+
currentDigest: result.current.digest,
|
|
103
|
+
replacementDigest: result.replacement.digest,
|
|
104
|
+
corruptRows: result.current.corruptRows,
|
|
105
|
+
unterminated: result.current.unterminated,
|
|
106
|
+
},
|
|
107
|
+
human: { title: `recover ${result.sidecar} sidecar`, severity: 'warn' },
|
|
108
|
+
actor: { kind: 'human', id: actorId },
|
|
109
|
+
});
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
export async function runAssetSidecarRecoveryCommand(argv, deps = {}) {
|
|
117
|
+
const stdout = deps.stdout ?? ((text) => { process.stdout.write(text); });
|
|
118
|
+
const stderr = deps.stderr ?? ((text) => { process.stderr.write(text); });
|
|
119
|
+
const parsed = parseRepairArgs(argv);
|
|
120
|
+
const json = argv.includes('--json');
|
|
121
|
+
if (typeof parsed === 'string')
|
|
122
|
+
return failure(parsed, json, stdout, stderr, 2);
|
|
123
|
+
const env = deps.env ?? process.env;
|
|
124
|
+
const envFile = loadEnvFileFromEnv(env);
|
|
125
|
+
if (envFile.error)
|
|
126
|
+
return failure('env_file_unavailable', parsed.json, stdout, stderr, 1);
|
|
127
|
+
let result;
|
|
128
|
+
try {
|
|
129
|
+
result = (deps.recover ?? assetstore.recoverAssetSidecar)({
|
|
130
|
+
baseDir: deps.assetsDir ?? (deps.resolveAssetsDir ?? events.assetsDir)(),
|
|
131
|
+
sidecar: parsed.sidecar,
|
|
132
|
+
replacementPath: parsed.replacementPath,
|
|
133
|
+
write: parsed.write,
|
|
134
|
+
acknowledgeCorruptHistory: parsed.acknowledgeCorruptHistory,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
return failure(recoveryReason(error), parsed.json, stdout, stderr, 1);
|
|
139
|
+
}
|
|
140
|
+
let auditEventRecorded = false;
|
|
141
|
+
if (result.mode === 'write' && result.changed) {
|
|
142
|
+
try {
|
|
143
|
+
const ingestor = deps.ingestor ?? new events.Ingestor({ path: events.rootEventsPath() });
|
|
144
|
+
auditEventRecorded = await recordRecoveryEvent(ingestor, result, safeActorId(env));
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
auditEventRecorded = false;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (result.mode === 'write' && result.changed && !auditEventRecorded) {
|
|
151
|
+
stderr('[asset-health] sidecar recovered; root event unavailable\n');
|
|
152
|
+
}
|
|
153
|
+
if (result.lockReleaseWarning) {
|
|
154
|
+
stderr(`[asset-health] sidecar recovered; lock release incomplete: ${result.lockReleaseWarning}\n`);
|
|
155
|
+
}
|
|
156
|
+
const output = { ok: true, group: GROUP, ...result, auditEventRecorded };
|
|
157
|
+
if (parsed.json)
|
|
158
|
+
writeJson(stdout, output);
|
|
159
|
+
else {
|
|
160
|
+
stdout([
|
|
161
|
+
`sidecar recovery: mode=${result.mode}`,
|
|
162
|
+
`sidecar=${result.sidecar}`,
|
|
163
|
+
`changed=${result.changed}`,
|
|
164
|
+
`would_write=${result.wouldWrite}`,
|
|
165
|
+
`corrupt=${result.current.corruptRows}`,
|
|
166
|
+
`unterminated=${result.current.unterminated}`,
|
|
167
|
+
...(result.backupId ? [`backup=${result.backupId}`] : []),
|
|
168
|
+
].join(' ') + '\n');
|
|
169
|
+
}
|
|
170
|
+
return 0;
|
|
171
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { assetstore, events } from '@evomap/evolver-core';
|
|
2
|
+
type TrustEventWriter = Pick<events.Ingestor, 'ingest'>;
|
|
3
|
+
export interface AssetTrustDeps {
|
|
4
|
+
env?: Record<string, string | undefined>;
|
|
5
|
+
store?: assetstore.AssetStoreProvider;
|
|
6
|
+
provenance?: assetstore.ProvenanceStore;
|
|
7
|
+
ingestor?: TrustEventWriter;
|
|
8
|
+
assetsDir?: string;
|
|
9
|
+
stdout?: (text: string) => void;
|
|
10
|
+
stderr?: (text: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export interface AssetTrustView {
|
|
13
|
+
assetId: string;
|
|
14
|
+
type: assetstore.AssetKind;
|
|
15
|
+
logicalId?: string;
|
|
16
|
+
source: assetstore.ProvenanceSource | 'local_default';
|
|
17
|
+
trusted: boolean;
|
|
18
|
+
at?: string;
|
|
19
|
+
decision?: assetstore.ProvenanceDecision;
|
|
20
|
+
decidedBy?: string;
|
|
21
|
+
reason?: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function runAssetTrustCommand(argv: readonly string[], deps?: AssetTrustDeps): Promise<number>;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { assetstore, events, hub } from '@evomap/evolver-core';
|
|
2
|
+
import { loadEnvFileFromEnv } from '@evomap/evolver-mcp';
|
|
3
|
+
const GROUP = 'asset-trust';
|
|
4
|
+
const DEFAULT_LIMIT = 50;
|
|
5
|
+
const MAX_LIMIT = 200;
|
|
6
|
+
const MAX_REASON_INPUT = 1_000;
|
|
7
|
+
const MAX_REASON = 240;
|
|
8
|
+
const ASSET_ID_RE = /^sha256:[a-f0-9]{64}$/;
|
|
9
|
+
const ACTOR_ID_RE = /^[A-Za-z0-9][A-Za-z0-9_.@:-]{0,79}$/;
|
|
10
|
+
const USAGE = [
|
|
11
|
+
'Usage:',
|
|
12
|
+
' evolver asset-trust list [--limit N] [--json]',
|
|
13
|
+
' evolver asset-trust show <asset_id> [--json]',
|
|
14
|
+
' evolver asset-trust promote <asset_id> --reason <text> [--json]',
|
|
15
|
+
' evolver asset-trust revoke <asset_id> --reason <text> [--json]',
|
|
16
|
+
'',
|
|
17
|
+
].join('\n');
|
|
18
|
+
function parseArgs(argv) {
|
|
19
|
+
const action = argv[0];
|
|
20
|
+
if (action !== 'list' && action !== 'show' && action !== 'promote' && action !== 'revoke')
|
|
21
|
+
return 'invalid_action';
|
|
22
|
+
let assetId;
|
|
23
|
+
let reason;
|
|
24
|
+
let limit = DEFAULT_LIMIT;
|
|
25
|
+
let json = false;
|
|
26
|
+
let index = 1;
|
|
27
|
+
if (action !== 'list') {
|
|
28
|
+
assetId = argv[index];
|
|
29
|
+
index += 1;
|
|
30
|
+
if (!assetId || !ASSET_ID_RE.test(assetId))
|
|
31
|
+
return 'invalid_asset_id';
|
|
32
|
+
}
|
|
33
|
+
while (index < argv.length) {
|
|
34
|
+
const arg = argv[index];
|
|
35
|
+
if (arg === '--json') {
|
|
36
|
+
json = true;
|
|
37
|
+
index += 1;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (arg === '--reason' && (action === 'promote' || action === 'revoke')) {
|
|
41
|
+
const value = argv[index + 1];
|
|
42
|
+
if (!value || value.startsWith('--'))
|
|
43
|
+
return 'reason_required';
|
|
44
|
+
reason = value;
|
|
45
|
+
index += 2;
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
if (arg === '--limit' && action === 'list') {
|
|
49
|
+
const value = argv[index + 1];
|
|
50
|
+
if (!value || !/^\d+$/.test(value))
|
|
51
|
+
return 'invalid_limit';
|
|
52
|
+
limit = Math.min(MAX_LIMIT, Math.max(1, Number(value)));
|
|
53
|
+
index += 2;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
return 'unknown_argument';
|
|
57
|
+
}
|
|
58
|
+
if ((action === 'promote' || action === 'revoke') && !reason)
|
|
59
|
+
return 'reason_required';
|
|
60
|
+
return { action, ...(assetId ? { assetId } : {}), ...(reason ? { reason } : {}), limit, json };
|
|
61
|
+
}
|
|
62
|
+
function safeActorId(env) {
|
|
63
|
+
const raw = env['EVOLVER_ACTOR_ID'] ?? env['USER'] ?? env['LOGNAME'] ?? env['USERNAME'] ?? 'cli';
|
|
64
|
+
const trimmed = raw.trim();
|
|
65
|
+
return ACTOR_ID_RE.test(trimmed) && hub.redactString(trimmed) === trimmed ? trimmed : 'cli';
|
|
66
|
+
}
|
|
67
|
+
function safeReason(raw, env) {
|
|
68
|
+
if (raw.length > MAX_REASON_INPUT)
|
|
69
|
+
return null;
|
|
70
|
+
const redacted = hub.redactString(raw).replace(/\s+/g, ' ').trim().slice(0, MAX_REASON);
|
|
71
|
+
if (!redacted || hub.fullLeakCheck(redacted, env).found)
|
|
72
|
+
return null;
|
|
73
|
+
return redacted;
|
|
74
|
+
}
|
|
75
|
+
function safeOutputText(value, env, max = MAX_REASON) {
|
|
76
|
+
if (!value)
|
|
77
|
+
return undefined;
|
|
78
|
+
const redacted = hub.redactString(value).replace(/\s+/g, ' ').trim().slice(0, max);
|
|
79
|
+
return redacted && !hub.fullLeakCheck(redacted, env).found ? redacted : '[redacted]';
|
|
80
|
+
}
|
|
81
|
+
function safeActorOutput(value) {
|
|
82
|
+
if (!value)
|
|
83
|
+
return undefined;
|
|
84
|
+
const trimmed = value.trim();
|
|
85
|
+
return ACTOR_ID_RE.test(trimmed) && hub.redactString(trimmed) === trimmed ? trimmed : '[redacted]';
|
|
86
|
+
}
|
|
87
|
+
function viewFor(asset, record, env) {
|
|
88
|
+
const logicalId = typeof asset['id'] === 'string' && asset['id'].trim() ? asset['id'].trim() : undefined;
|
|
89
|
+
const decidedBy = safeActorOutput(record?.decidedBy ?? record?.promotedBy);
|
|
90
|
+
const reason = safeOutputText(record?.reason, env);
|
|
91
|
+
return {
|
|
92
|
+
assetId: asset.asset_id,
|
|
93
|
+
type: asset.type,
|
|
94
|
+
...(logicalId ? { logicalId: safeOutputText(logicalId, env, 120) } : {}),
|
|
95
|
+
source: record?.source ?? 'local_default',
|
|
96
|
+
trusted: record?.trusted ?? true,
|
|
97
|
+
...(record?.at ? { at: record.at } : {}),
|
|
98
|
+
...(record?.decision ? { decision: record.decision } : {}),
|
|
99
|
+
...(decidedBy ? { decidedBy } : {}),
|
|
100
|
+
...(reason ? { reason } : {}),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function storeBaseDir(store, deps) {
|
|
104
|
+
if (deps.assetsDir)
|
|
105
|
+
return deps.assetsDir;
|
|
106
|
+
return store instanceof assetstore.LocalJsonlProvider ? store.baseDir : events.assetsDir();
|
|
107
|
+
}
|
|
108
|
+
function writeJson(write, value) {
|
|
109
|
+
write(`${JSON.stringify(value)}\n`);
|
|
110
|
+
}
|
|
111
|
+
function parseFailure(reason, json, stdout, stderr) {
|
|
112
|
+
if (json)
|
|
113
|
+
writeJson(stdout, { ok: false, group: GROUP, reason });
|
|
114
|
+
else
|
|
115
|
+
stderr(`[asset-trust] ${reason}\n${USAGE}`);
|
|
116
|
+
return 2;
|
|
117
|
+
}
|
|
118
|
+
function renderView(view) {
|
|
119
|
+
return `${view.type} ${view.assetId} source=${view.source} trusted=${view.trusted}${view.logicalId ? ` id=${view.logicalId}` : ''}`;
|
|
120
|
+
}
|
|
121
|
+
async function recordTrustEvent(ingestor, action, view, reason, actorId) {
|
|
122
|
+
try {
|
|
123
|
+
await ingestor.ingest({
|
|
124
|
+
type: action === 'promote' ? 'actor.human.trust.promote' : 'actor.human.trust.revoke',
|
|
125
|
+
payload: { assetId: view.assetId, assetType: view.type, source: view.source, reason },
|
|
126
|
+
human: { title: `${action} ${view.type} ${view.assetId.slice(0, 19)}`, severity: 'notice' },
|
|
127
|
+
actor: { kind: 'human', id: actorId },
|
|
128
|
+
});
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
catch {
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export async function runAssetTrustCommand(argv, deps = {}) {
|
|
136
|
+
const stdout = deps.stdout ?? ((text) => { process.stdout.write(text); });
|
|
137
|
+
const stderr = deps.stderr ?? ((text) => { process.stderr.write(text); });
|
|
138
|
+
if (argv.includes('--help') || argv.includes('-h')) {
|
|
139
|
+
stdout(USAGE);
|
|
140
|
+
return 0;
|
|
141
|
+
}
|
|
142
|
+
const json = argv.includes('--json');
|
|
143
|
+
const parsed = parseArgs(argv);
|
|
144
|
+
if (typeof parsed === 'string')
|
|
145
|
+
return parseFailure(parsed, json, stdout, stderr);
|
|
146
|
+
const env = deps.env ?? process.env;
|
|
147
|
+
const envFile = loadEnvFileFromEnv(env);
|
|
148
|
+
if (envFile.error)
|
|
149
|
+
return parseFailure('env_file_unavailable', parsed.json, stdout, stderr);
|
|
150
|
+
const store = deps.store ?? new assetstore.LocalJsonlProvider(deps.assetsDir ?? events.assetsDir());
|
|
151
|
+
const provenance = deps.provenance ?? new assetstore.ProvenanceStore(storeBaseDir(store, deps));
|
|
152
|
+
if (parsed.action === 'list') {
|
|
153
|
+
const snapshot = provenance.snapshot();
|
|
154
|
+
const allAssets = (await store.list(undefined, Number.MAX_SAFE_INTEGER))
|
|
155
|
+
.map((asset) => viewFor(asset, snapshot.get(asset.asset_id) ?? null, env))
|
|
156
|
+
.sort((left, right) => Number(left.trusted) - Number(right.trusted)
|
|
157
|
+
|| left.assetId.localeCompare(right.assetId));
|
|
158
|
+
const assets = allAssets.slice(0, parsed.limit);
|
|
159
|
+
const counts = {
|
|
160
|
+
total: allAssets.length,
|
|
161
|
+
trusted: allAssets.filter((asset) => asset.trusted).length,
|
|
162
|
+
untrusted: allAssets.filter((asset) => !asset.trusted).length,
|
|
163
|
+
returned: assets.length,
|
|
164
|
+
};
|
|
165
|
+
const truncated = assets.length < allAssets.length;
|
|
166
|
+
const result = { ok: true, group: GROUP, mode: 'list', counts, truncated, assets };
|
|
167
|
+
if (parsed.json)
|
|
168
|
+
writeJson(stdout, result);
|
|
169
|
+
else {
|
|
170
|
+
stdout(`asset trust: total=${counts.total} trusted=${counts.trusted} untrusted=${counts.untrusted} returned=${counts.returned} truncated=${truncated}\n`);
|
|
171
|
+
for (const asset of assets)
|
|
172
|
+
stdout(`${renderView(asset)}\n`);
|
|
173
|
+
}
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
176
|
+
const asset = await store.get(parsed.assetId);
|
|
177
|
+
if (!asset) {
|
|
178
|
+
if (parsed.json)
|
|
179
|
+
writeJson(stdout, { ok: false, group: GROUP, reason: 'asset_not_found' });
|
|
180
|
+
else
|
|
181
|
+
stderr('[asset-trust] asset_not_found\n');
|
|
182
|
+
return 1;
|
|
183
|
+
}
|
|
184
|
+
if (parsed.action === 'show') {
|
|
185
|
+
const result = { ok: true, group: GROUP, mode: 'show', asset: viewFor(asset, provenance.get(asset.asset_id), env) };
|
|
186
|
+
if (parsed.json)
|
|
187
|
+
writeJson(stdout, result);
|
|
188
|
+
else
|
|
189
|
+
stdout(`${renderView(result.asset)}\n`);
|
|
190
|
+
return 0;
|
|
191
|
+
}
|
|
192
|
+
const reason = safeReason(parsed.reason, env);
|
|
193
|
+
if (!reason)
|
|
194
|
+
return parseFailure('unsafe_reason', parsed.json, stdout, stderr);
|
|
195
|
+
const actorId = safeActorId(env);
|
|
196
|
+
const desiredTrust = parsed.action === 'promote';
|
|
197
|
+
const change = provenance.changeTrust(asset.asset_id, desiredTrust, actorId, reason);
|
|
198
|
+
const view = viewFor(asset, change.record, env);
|
|
199
|
+
const ingestor = deps.ingestor ?? new events.Ingestor({ path: events.rootEventsPath() });
|
|
200
|
+
const auditEventRecorded = change.changed
|
|
201
|
+
? await recordTrustEvent(ingestor, parsed.action, view, reason, actorId)
|
|
202
|
+
: false;
|
|
203
|
+
if (change.changed && !auditEventRecorded)
|
|
204
|
+
stderr('[asset-trust] trust decision saved; root event unavailable\n');
|
|
205
|
+
const result = {
|
|
206
|
+
ok: true,
|
|
207
|
+
group: GROUP,
|
|
208
|
+
mode: parsed.action,
|
|
209
|
+
changed: change.changed,
|
|
210
|
+
auditEventRecorded,
|
|
211
|
+
asset: view,
|
|
212
|
+
};
|
|
213
|
+
if (parsed.json)
|
|
214
|
+
writeJson(stdout, result);
|
|
215
|
+
else
|
|
216
|
+
stdout(`${change.changed ? 'updated' : 'unchanged'} ${renderView(view)}\n`);
|
|
217
|
+
return 0;
|
|
218
|
+
}
|
package/dist/autoexec.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { events, assetstore, algo, exec, hooks, material as materialNs, verify, hub as hubNs } from '@evomap/evolver-core';
|
|
1
|
+
import { events, assetstore, algo, exec, hooks, material as materialNs, util, verify, hub as hubNs } from '@evomap/evolver-core';
|
|
2
2
|
import { type Beat } from './daemonLoop.js';
|
|
3
3
|
import { connectPublicHub, ReuseCache } from '@evomap/evolver-adapter-public';
|
|
4
4
|
import type { FetchLike, MemoryGraphEventReceipt, MemoryGraphEventReport, OfflinePermitStore, OutcomeReport, OutcomeReceipt } from '@evomap/evolver-adapter-public';
|
|
@@ -19,7 +19,7 @@ export interface AutoExecConfig {
|
|
|
19
19
|
allowedRoots: string[];
|
|
20
20
|
pollMs: number;
|
|
21
21
|
timeoutMs: number;
|
|
22
|
-
runner: 'claude' | 'codex' | 'cursor';
|
|
22
|
+
runner: 'claude' | 'codex' | 'cursor' | 'gemini';
|
|
23
23
|
}
|
|
24
24
|
/** Create the queue layout under <home>/autoexec/{tasks,done,refused}. */
|
|
25
25
|
export declare function ensureAutoExecDirs(base: string): AutoExecDirs;
|
|
@@ -113,6 +113,13 @@ export declare function verdictToOutcomeStatus(status: exec.AutoExecVerdict['sta
|
|
|
113
113
|
export declare function questionGeneratorStatePath(home?: string): string;
|
|
114
114
|
export declare function makeHubQuestionLink(cap: hubNs.HubCapability, options?: HubQuestionLinkOptions): HubQuestionLink;
|
|
115
115
|
export declare function shouldSubmitProactiveQuestionsForTask(task: exec.AutoExecTask): boolean;
|
|
116
|
+
export declare function autoexecLockFailureMessage(error: unknown): string;
|
|
117
|
+
export declare function autoexecLockReleaseFailureMessage(error: unknown): string;
|
|
118
|
+
export interface AutoexecLockReleaseDeps {
|
|
119
|
+
releaseLock?: (path: string) => util.ReleaseLockResult | void;
|
|
120
|
+
stderr?: (text: string) => void;
|
|
121
|
+
}
|
|
122
|
+
export declare function releaseAutoexecLock(lockPath: string, deps?: AutoexecLockReleaseDeps): boolean;
|
|
116
123
|
export declare function urgentQuestionRuntimeWiringStatus(): typeof hubNs.URGENT_QUESTION_RUNTIME_WIRING_STATUS;
|
|
117
124
|
export declare function submitDistillTickExplorationQuestion(questions: HubQuestionLink | undefined, source: DistillTickQuestionSource | undefined): Promise<HubQuestionSubmitResult>;
|
|
118
125
|
export declare function scheduleAutoExecHubSideEffects(task: exec.AutoExecTask, verdict: exec.AutoExecVerdict, links: {
|