@lumenflow/cli 5.5.0 → 5.7.12
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/README.md +42 -40
- package/dist/db-journal-recover.js +400 -0
- package/dist/db-journal-recover.js.map +1 -0
- package/dist/docs-sync.js +8 -3
- package/dist/docs-sync.js.map +1 -1
- package/dist/gate-defaults.js +37 -0
- package/dist/gate-defaults.js.map +1 -1
- package/dist/gates/monolithic-file-contention-guard.js +167 -0
- package/dist/gates/monolithic-file-contention-guard.js.map +1 -0
- package/dist/gates/prod-migration-drift.js +207 -0
- package/dist/gates/prod-migration-drift.js.map +1 -0
- package/dist/gates/test-over-deletion-guard.js +255 -0
- package/dist/gates/test-over-deletion-guard.js.map +1 -0
- package/dist/gates-runners.js +44 -3
- package/dist/gates-runners.js.map +1 -1
- package/dist/gates.js +3 -2
- package/dist/gates.js.map +1 -1
- package/dist/lumenflow-setup.js +144 -0
- package/dist/lumenflow-setup.js.map +1 -0
- package/dist/lumenflow-upgrade.js +2 -1
- package/dist/lumenflow-upgrade.js.map +1 -1
- package/dist/mem-create.js +10 -1
- package/dist/mem-create.js.map +1 -1
- package/dist/mem-signal.js +21 -4
- package/dist/mem-signal.js.map +1 -1
- package/dist/orchestrate-initiative.js +28 -3
- package/dist/orchestrate-initiative.js.map +1 -1
- package/dist/public-manifest.js +17 -0
- package/dist/public-manifest.js.map +1 -1
- package/dist/release.js +53 -18
- package/dist/release.js.map +1 -1
- package/dist/wu-done-gates.js +13 -9
- package/dist/wu-done-gates.js.map +1 -1
- package/dist/wu-edit-operations.js +74 -0
- package/dist/wu-edit-operations.js.map +1 -1
- package/dist/wu-edit-validators.js +58 -0
- package/dist/wu-edit-validators.js.map +1 -1
- package/dist/wu-edit.js +106 -4
- package/dist/wu-edit.js.map +1 -1
- package/dist/wu-prep.js +41 -7
- package/dist/wu-prep.js.map +1 -1
- package/dist/wu-recover.js +6 -0
- package/dist/wu-recover.js.map +1 -1
- package/dist/wu-release.js +120 -2
- package/dist/wu-release.js.map +1 -1
- package/dist/wu-sizing-validation.js +47 -17
- package/dist/wu-sizing-validation.js.map +1 -1
- package/dist/wu-status.js +33 -0
- package/dist/wu-status.js.map +1 -1
- package/package.json +13 -11
- package/packs/agent-runtime/package.json +1 -1
- package/packs/sidekick/package.json +1 -1
- package/packs/software-delivery/package.json +1 -1
- package/templates/core/AGENTS.md.template +67 -3
- package/templates/core/LUMENFLOW.md.template +197 -47
- package/packs/agent-runtime/agent-heartbeat.ts +0 -163
- package/packs/agent-runtime/auto-session-integration.ts +0 -888
- package/packs/agent-runtime/capability-factory.ts +0 -104
- package/packs/agent-runtime/constants.ts +0 -21
- package/packs/agent-runtime/delegation-registry-schema.ts +0 -220
- package/packs/agent-runtime/delegation-registry-store.ts +0 -269
- package/packs/agent-runtime/delegation-tree.ts +0 -328
- package/packs/agent-runtime/index.ts +0 -20
- package/packs/agent-runtime/manifest.ts +0 -348
- package/packs/agent-runtime/memory-coordination-contract.ts +0 -86
- package/packs/agent-runtime/orchestration.ts +0 -2027
- package/packs/agent-runtime/pack-registration.ts +0 -110
- package/packs/agent-runtime/policy-factory.ts +0 -165
- package/packs/agent-runtime/remote-controls/index.ts +0 -7
- package/packs/agent-runtime/remote-controls/operations.ts +0 -405
- package/packs/agent-runtime/remote-controls/port.ts +0 -48
- package/packs/agent-runtime/remote-controls/state-store.ts +0 -258
- package/packs/agent-runtime/remote-controls/types.ts +0 -105
- package/packs/agent-runtime/session-schema.ts +0 -467
- package/packs/agent-runtime/tool-impl/agent-turn-tools.ts +0 -793
- package/packs/agent-runtime/tool-impl/index.ts +0 -6
- package/packs/agent-runtime/tool-impl/provider-adapters.ts +0 -1245
- package/packs/agent-runtime/tool-impl/remote-controls.mock.ts +0 -256
- package/packs/agent-runtime/tool-impl/remote-controls.ts +0 -273
- package/packs/agent-runtime/tools/index.ts +0 -4
- package/packs/agent-runtime/tools/types.ts +0 -47
- package/packs/agent-runtime/turn-lifecycle-events.ts +0 -590
- package/packs/agent-runtime/types.ts +0 -128
- package/packs/agent-runtime/vitest.config.ts +0 -11
- package/packs/sidekick/channel-ingress.ts +0 -137
- package/packs/sidekick/constants.ts +0 -10
- package/packs/sidekick/index.ts +0 -8
- package/packs/sidekick/manifest-schema.ts +0 -49
- package/packs/sidekick/manifest.ts +0 -512
- package/packs/sidekick/pack-registration.ts +0 -110
- package/packs/sidekick/policy-factory.ts +0 -38
- package/packs/sidekick/sidekick-events.ts +0 -694
- package/packs/sidekick/src/adapters/cloud-queue.ts +0 -101
- package/packs/sidekick/src/adapters/control-plane-bridge.adapter.ts +0 -386
- package/packs/sidekick/src/adapters/filesystem-bridge.adapter.ts +0 -228
- package/packs/sidekick/src/domain/channel.types.ts +0 -64
- package/packs/sidekick/src/ports/channel-bridge.port.ts +0 -92
- package/packs/sidekick/src/routines/commit.ts +0 -74
- package/packs/sidekick/tool-impl/channel-tools.ts +0 -577
- package/packs/sidekick/tool-impl/channel-transports.ts +0 -75
- package/packs/sidekick/tool-impl/index.ts +0 -29
- package/packs/sidekick/tool-impl/memory-tools.ts +0 -290
- package/packs/sidekick/tool-impl/routine-commit.ts +0 -102
- package/packs/sidekick/tool-impl/routine-tools.ts +0 -440
- package/packs/sidekick/tool-impl/runtime-context.ts +0 -28
- package/packs/sidekick/tool-impl/shared.ts +0 -125
- package/packs/sidekick/tool-impl/storage.ts +0 -325
- package/packs/sidekick/tool-impl/system-tools.ts +0 -160
- package/packs/sidekick/tool-impl/task-tools.ts +0 -506
- package/packs/sidekick/tools/channel-tools.ts +0 -53
- package/packs/sidekick/tools/index.ts +0 -9
- package/packs/sidekick/tools/memory-tools.ts +0 -53
- package/packs/sidekick/tools/routine-tools.ts +0 -53
- package/packs/sidekick/tools/system-tools.ts +0 -47
- package/packs/sidekick/tools/task-tools.ts +0 -61
- package/packs/sidekick/tools/types.ts +0 -57
- package/packs/sidekick/vitest.config.ts +0 -11
- package/packs/software-delivery/constants.ts +0 -10
- package/packs/software-delivery/extensions.ts +0 -140
- package/packs/software-delivery/gate-policies.ts +0 -134
- package/packs/software-delivery/index.ts +0 -8
- package/packs/software-delivery/manifest-schema.ts +0 -268
- package/packs/software-delivery/manifest.ts +0 -657
- package/packs/software-delivery/pack-registration.ts +0 -113
- package/packs/software-delivery/src/commands/index.ts +0 -5
- package/packs/software-delivery/src/config/delivery-review-contract.ts +0 -256
- package/packs/software-delivery/src/config/env-accessors.ts +0 -66
- package/packs/software-delivery/src/config/index.ts +0 -8
- package/packs/software-delivery/src/config/normalize-config-keys.ts +0 -9
- package/packs/software-delivery/src/config/schemas/lumenflow-config-schema-types.ts +0 -460
- package/packs/software-delivery/src/config/workspace-reader.ts +0 -375
- package/packs/software-delivery/src/constants/backlog-patterns.ts +0 -31
- package/packs/software-delivery/src/constants/client-ids.ts +0 -19
- package/packs/software-delivery/src/constants/config-contract.ts +0 -7
- package/packs/software-delivery/src/constants/docs-layout-presets.ts +0 -50
- package/packs/software-delivery/src/constants/duration-constants.ts +0 -20
- package/packs/software-delivery/src/constants/gate-constants.ts +0 -32
- package/packs/software-delivery/src/constants/index.ts +0 -29
- package/packs/software-delivery/src/constants/lock-constants.ts +0 -35
- package/packs/software-delivery/src/constants/object-guards.ts +0 -12
- package/packs/software-delivery/src/constants/section-headings.ts +0 -107
- package/packs/software-delivery/src/constants/wu-cli-constants.ts +0 -500
- package/packs/software-delivery/src/constants/wu-domain-constants.ts +0 -466
- package/packs/software-delivery/src/constants/wu-git-constants.ts +0 -7
- package/packs/software-delivery/src/constants/wu-id-format.ts +0 -327
- package/packs/software-delivery/src/constants/wu-paths-constants.ts +0 -384
- package/packs/software-delivery/src/constants/wu-statuses.ts +0 -287
- package/packs/software-delivery/src/constants/wu-type-helpers.ts +0 -67
- package/packs/software-delivery/src/constants/wu-ui-constants.ts +0 -267
- package/packs/software-delivery/src/constants/wu-validation-constants.ts +0 -73
- package/packs/software-delivery/src/domain/index.ts +0 -5
- package/packs/software-delivery/src/domain/orchestration.constants.ts +0 -166
- package/packs/software-delivery/src/domain/orchestration.schemas.ts +0 -238
- package/packs/software-delivery/src/domain/orchestration.types.ts +0 -176
- package/packs/software-delivery/src/methodology/incremental-test.ts +0 -122
- package/packs/software-delivery/src/methodology/index.ts +0 -6
- package/packs/software-delivery/src/methodology/manual-test-validator.ts +0 -292
- package/packs/software-delivery/src/policy/coverage-gate.ts +0 -270
- package/packs/software-delivery/src/policy/gates-agent-mode.ts +0 -223
- package/packs/software-delivery/src/policy/gates-config-internal.ts +0 -121
- package/packs/software-delivery/src/policy/gates-config.ts +0 -300
- package/packs/software-delivery/src/policy/gates-coverage.ts +0 -356
- package/packs/software-delivery/src/policy/gates-presets.ts +0 -134
- package/packs/software-delivery/src/policy/gates-schemas.ts +0 -173
- package/packs/software-delivery/src/policy/index.ts +0 -22
- package/packs/software-delivery/src/policy/package-manager-resolver.ts +0 -319
- package/packs/software-delivery/src/policy/resolve-policy.ts +0 -601
- package/packs/software-delivery/src/ports/config.ports.ts +0 -90
- package/packs/software-delivery/src/ports/dashboard-renderer.port.ts +0 -125
- package/packs/software-delivery/src/ports/index.ts +0 -10
- package/packs/software-delivery/src/ports/sync-validator.ports.ts +0 -59
- package/packs/software-delivery/src/ports/wu-helpers.ports.ts +0 -168
- package/packs/software-delivery/src/ports/wu-state.ports.ts +0 -241
- package/packs/software-delivery/src/primitives/index.ts +0 -5
- package/packs/software-delivery/src/runtime/index.ts +0 -6
- package/packs/software-delivery/src/runtime/work-classifier.ts +0 -561
- package/packs/software-delivery/src/sandbox/index.ts +0 -10
- package/packs/software-delivery/src/sandbox/sandbox-allowlist.ts +0 -118
- package/packs/software-delivery/src/sandbox/sandbox-backend-linux.ts +0 -88
- package/packs/software-delivery/src/sandbox/sandbox-backend-macos.ts +0 -154
- package/packs/software-delivery/src/sandbox/sandbox-backend-windows.ts +0 -47
- package/packs/software-delivery/src/sandbox/sandbox-profile.ts +0 -153
- package/packs/software-delivery/src/schemas/index.ts +0 -5
- package/packs/software-delivery/src/state/date-utils.ts +0 -158
- package/packs/software-delivery/src/state/index.ts +0 -15
- package/packs/software-delivery/src/state/state-machine.ts +0 -119
- package/packs/software-delivery/src/state/wu-doc-types.ts +0 -51
- package/packs/software-delivery/src/state/wu-paths.ts +0 -381
- package/packs/software-delivery/src/state/wu-schema.ts +0 -1139
- package/packs/software-delivery/src/state/wu-state-schema.ts +0 -255
- package/packs/software-delivery/src/state/wu-yaml.ts +0 -338
- package/packs/software-delivery/tool-impl/agent-tools.ts +0 -263
- package/packs/software-delivery/tool-impl/delegation-tools.ts +0 -66
- package/packs/software-delivery/tool-impl/flow-metrics-tools.ts +0 -219
- package/packs/software-delivery/tool-impl/git-runner.ts +0 -113
- package/packs/software-delivery/tool-impl/git-tools.ts +0 -316
- package/packs/software-delivery/tool-impl/index.ts +0 -15
- package/packs/software-delivery/tool-impl/initiative-orchestration-tools.ts +0 -720
- package/packs/software-delivery/tool-impl/lane-lock.ts +0 -246
- package/packs/software-delivery/tool-impl/memory-tools.ts +0 -470
- package/packs/software-delivery/tool-impl/pending-runtime-tools.ts +0 -21
- package/packs/software-delivery/tool-impl/runtime-cli-adapter.ts +0 -329
- package/packs/software-delivery/tool-impl/runtime-native-tools.ts +0 -687
- package/packs/software-delivery/tool-impl/worker-loader.ts +0 -52
- package/packs/software-delivery/tool-impl/worktree-tools.ts +0 -46
- package/packs/software-delivery/tool-impl/wu-lifecycle-tools.ts +0 -807
- package/packs/software-delivery/tools/delegation-tools.ts +0 -23
- package/packs/software-delivery/tools/git-tools.ts +0 -55
- package/packs/software-delivery/tools/index.ts +0 -8
- package/packs/software-delivery/tools/lane-lock-tool.ts +0 -37
- package/packs/software-delivery/tools/types.ts +0 -71
- package/packs/software-delivery/tools/worktree-tools.ts +0 -49
- package/packs/software-delivery/vitest.config.ts +0 -11
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2026 Hellmai Ltd
|
|
2
|
-
// SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
|
|
3
|
-
|
|
4
|
-
interface PendingRuntimeMigrationOutput {
|
|
5
|
-
success: false;
|
|
6
|
-
error: {
|
|
7
|
-
code: 'TOOL_NOT_IMPLEMENTED';
|
|
8
|
-
message: string;
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export async function pendingRuntimeMigrationTool(): Promise<PendingRuntimeMigrationOutput> {
|
|
13
|
-
return {
|
|
14
|
-
success: false,
|
|
15
|
-
error: {
|
|
16
|
-
code: 'TOOL_NOT_IMPLEMENTED',
|
|
17
|
-
message:
|
|
18
|
-
'Tool is declared in the software-delivery manifest but has not been migrated to a runtime handler yet.',
|
|
19
|
-
},
|
|
20
|
-
};
|
|
21
|
-
}
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2026 Hellmai Ltd
|
|
2
|
-
// SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
|
|
3
|
-
|
|
4
|
-
import { resolve as resolvePath } from 'node:path';
|
|
5
|
-
import { pathToFileURL } from 'node:url';
|
|
6
|
-
import { format } from 'node:util';
|
|
7
|
-
import { UTF8_ENCODING } from '../constants.js';
|
|
8
|
-
|
|
9
|
-
export const RUNTIME_CLI_COMMANDS = {
|
|
10
|
-
AGENT_ISSUES_QUERY: 'agent-issues-query',
|
|
11
|
-
AGENT_LOG_ISSUE: 'agent-log-issue',
|
|
12
|
-
AGENT_SESSION: 'agent-session',
|
|
13
|
-
AGENT_SESSION_END: 'agent-session-end',
|
|
14
|
-
BACKLOG_PRUNE: 'backlog-prune',
|
|
15
|
-
CONFIG_GET: 'config-get',
|
|
16
|
-
CONFIG_SET: 'config-set',
|
|
17
|
-
DELEGATION_LIST: 'delegation-list',
|
|
18
|
-
DOCS_SYNC: 'docs-sync',
|
|
19
|
-
FILE_DELETE: 'file-delete',
|
|
20
|
-
FILE_EDIT: 'file-edit',
|
|
21
|
-
FILE_READ: 'file-read',
|
|
22
|
-
FILE_WRITE: 'file-write',
|
|
23
|
-
FLOW_BOTTLENECKS: 'flow-bottlenecks',
|
|
24
|
-
FLOW_REPORT: 'flow-report',
|
|
25
|
-
GATES: 'gates',
|
|
26
|
-
GIT_BRANCH: 'git-branch',
|
|
27
|
-
GIT_DIFF: 'git-diff',
|
|
28
|
-
GIT_LOG: 'git-log',
|
|
29
|
-
INIT: 'init',
|
|
30
|
-
INITIATIVE_ADD_WU: 'initiative-add-wu',
|
|
31
|
-
INITIATIVE_BULK_ASSIGN: 'initiative-bulk-assign-wus',
|
|
32
|
-
INITIATIVE_CREATE: 'initiative-create',
|
|
33
|
-
INITIATIVE_EDIT: 'initiative-edit',
|
|
34
|
-
INITIATIVE_LIST: 'initiative-list',
|
|
35
|
-
INITIATIVE_PLAN: 'initiative-plan',
|
|
36
|
-
INITIATIVE_REMOVE_WU: 'initiative-remove-wu',
|
|
37
|
-
INITIATIVE_STATUS: 'initiative-status',
|
|
38
|
-
INTEGRATE: 'commands/integrate',
|
|
39
|
-
LANE_HEALTH: 'lane-health',
|
|
40
|
-
LANE_SUGGEST: 'lane-suggest',
|
|
41
|
-
LUMENFLOW_DOCTOR: 'doctor',
|
|
42
|
-
LUMENFLOW_UPGRADE: 'lumenflow-upgrade',
|
|
43
|
-
MEM_CHECKPOINT: 'mem-checkpoint',
|
|
44
|
-
MEM_CLEANUP: 'mem-cleanup',
|
|
45
|
-
MEM_CONTEXT: 'mem-context',
|
|
46
|
-
MEM_CREATE: 'mem-create',
|
|
47
|
-
MEM_DELETE: 'mem-delete',
|
|
48
|
-
MEM_EXPORT: 'mem-export',
|
|
49
|
-
MEM_INBOX: 'mem-inbox',
|
|
50
|
-
MEM_CONVERGED: 'mem-converged',
|
|
51
|
-
MEM_INIT: 'mem-init',
|
|
52
|
-
MEM_READY: 'mem-ready',
|
|
53
|
-
MEM_RECOVER: 'mem-recover',
|
|
54
|
-
MEM_SIGNAL: 'mem-signal',
|
|
55
|
-
MEM_START: 'mem-start',
|
|
56
|
-
MEM_SUMMARIZE: 'mem-summarize',
|
|
57
|
-
MEM_TRIAGE: 'mem-triage',
|
|
58
|
-
METRICS: 'metrics-cli',
|
|
59
|
-
METRICS_SNAPSHOT: 'metrics-snapshot',
|
|
60
|
-
ORCHESTRATE_INIT_STATUS: 'orchestrate-init-status',
|
|
61
|
-
ORCHESTRATE_INITIATIVE: 'orchestrate-initiative',
|
|
62
|
-
ORCHESTRATE_MONITOR: 'orchestrate-monitor',
|
|
63
|
-
PLAN_CREATE: 'plan-create',
|
|
64
|
-
PLAN_EDIT: 'plan-edit',
|
|
65
|
-
PLAN_LINK: 'plan-link',
|
|
66
|
-
PLAN_PROMOTE: 'plan-promote',
|
|
67
|
-
RELEASE: 'release',
|
|
68
|
-
SIGNAL_CLEANUP: 'signal-cleanup',
|
|
69
|
-
STATE_BOOTSTRAP: 'state-bootstrap',
|
|
70
|
-
STATE_CLEANUP: 'state-cleanup',
|
|
71
|
-
STATE_DOCTOR: 'state-doctor',
|
|
72
|
-
SYNC_TEMPLATES: 'sync-templates',
|
|
73
|
-
VALIDATE: 'validate',
|
|
74
|
-
VALIDATE_AGENT_SKILLS: 'validate-agent-skills',
|
|
75
|
-
VALIDATE_AGENT_SYNC: 'validate-agent-sync',
|
|
76
|
-
VALIDATE_BACKLOG_SYNC: 'validate-backlog-sync',
|
|
77
|
-
VALIDATE_SKILLS_SPEC: 'validate-skills-spec',
|
|
78
|
-
WU_BLOCK: 'wu-block',
|
|
79
|
-
WU_BRIEF: 'wu-brief',
|
|
80
|
-
WU_CLAIM: 'wu-claim',
|
|
81
|
-
WU_CLEANUP: 'wu-cleanup',
|
|
82
|
-
WU_CREATE: 'wu-create',
|
|
83
|
-
WU_DELEGATE: 'wu-delegate',
|
|
84
|
-
WU_DELETE: 'wu-delete',
|
|
85
|
-
WU_DEPS: 'wu-deps',
|
|
86
|
-
WU_DONE: 'wu-done',
|
|
87
|
-
WU_EDIT: 'wu-edit',
|
|
88
|
-
WU_INFER_LANE: 'wu-infer-lane',
|
|
89
|
-
WU_PREFLIGHT: 'wu-preflight',
|
|
90
|
-
WU_PREP: 'wu-prep',
|
|
91
|
-
WU_PROTO: 'wu-proto',
|
|
92
|
-
WU_PRUNE: 'wu-prune',
|
|
93
|
-
WU_RECOVER: 'wu-recover',
|
|
94
|
-
WU_RELEASE: 'wu-release',
|
|
95
|
-
WU_REPAIR: 'wu-repair',
|
|
96
|
-
WU_SANDBOX: 'wu-sandbox',
|
|
97
|
-
WU_STATUS: 'wu-status',
|
|
98
|
-
WU_UNBLOCK: 'wu-unblock',
|
|
99
|
-
WU_UNLOCK_LANE: 'wu-unlock-lane',
|
|
100
|
-
WU_VALIDATE: 'wu-validate',
|
|
101
|
-
WORKSPACE_INIT: 'workspace-init',
|
|
102
|
-
} as const;
|
|
103
|
-
|
|
104
|
-
export type RuntimeCliCommand = (typeof RUNTIME_CLI_COMMANDS)[keyof typeof RUNTIME_CLI_COMMANDS];
|
|
105
|
-
|
|
106
|
-
export interface RuntimeCliModule {
|
|
107
|
-
main: () => Promise<void>;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
type RuntimeCliModuleLoader = (command: RuntimeCliCommand) => Promise<RuntimeCliModule>;
|
|
111
|
-
|
|
112
|
-
type WriteCallback = ((error?: Error | null) => void) | undefined;
|
|
113
|
-
type WriteEncodingOrCallback = BufferEncoding | WriteCallback;
|
|
114
|
-
type WriteFn = (
|
|
115
|
-
chunk: string | Uint8Array,
|
|
116
|
-
encodingOrCallback?: WriteEncodingOrCallback,
|
|
117
|
-
callback?: (error?: Error | null) => void,
|
|
118
|
-
) => boolean;
|
|
119
|
-
|
|
120
|
-
const EXIT_STATUS_DEFAULT_OK = 0;
|
|
121
|
-
const EXIT_STATUS_DEFAULT_ERROR = 1;
|
|
122
|
-
const OUTPUT_LINE_SUFFIX = '\n';
|
|
123
|
-
const CLI_SOURCE_ROOT = 'packages/@lumenflow/cli/src';
|
|
124
|
-
const CLI_MODULE_FILE_EXTENSION = '.js';
|
|
125
|
-
|
|
126
|
-
type ConsoleCaptureMethodName = 'debug' | 'error' | 'info' | 'log' | 'warn';
|
|
127
|
-
type ConsoleCaptureMethod = (...args: unknown[]) => void;
|
|
128
|
-
const STDOUT_CONSOLE_METHODS: readonly ConsoleCaptureMethodName[] = ['debug', 'info', 'log'];
|
|
129
|
-
const STDERR_CONSOLE_METHODS: readonly ConsoleCaptureMethodName[] = ['error', 'warn'];
|
|
130
|
-
|
|
131
|
-
function resolveCliModuleRelativePath(command: RuntimeCliCommand): string {
|
|
132
|
-
return `${command}${CLI_MODULE_FILE_EXTENSION}`;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
function resolveCliModuleUrl(command: RuntimeCliCommand): string {
|
|
136
|
-
const absolutePath = resolvePath(
|
|
137
|
-
process.cwd(),
|
|
138
|
-
CLI_SOURCE_ROOT,
|
|
139
|
-
resolveCliModuleRelativePath(command),
|
|
140
|
-
);
|
|
141
|
-
return pathToFileURL(absolutePath).href;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function toErrorMessage(error: unknown): string {
|
|
145
|
-
if (error instanceof Error) {
|
|
146
|
-
return error.message;
|
|
147
|
-
}
|
|
148
|
-
return String(error);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function normalizeExitCode(code: number | string | undefined): number {
|
|
152
|
-
if (typeof code === 'number' && Number.isFinite(code)) {
|
|
153
|
-
return Math.trunc(code);
|
|
154
|
-
}
|
|
155
|
-
if (typeof code === 'string') {
|
|
156
|
-
const parsed = Number.parseInt(code, 10);
|
|
157
|
-
if (Number.isFinite(parsed)) {
|
|
158
|
-
return parsed;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return EXIT_STATUS_DEFAULT_OK;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
function appendCapturedChunk(
|
|
165
|
-
target: string[],
|
|
166
|
-
chunk: string | Uint8Array,
|
|
167
|
-
encoding: BufferEncoding,
|
|
168
|
-
): void {
|
|
169
|
-
if (typeof chunk === 'string') {
|
|
170
|
-
target.push(chunk);
|
|
171
|
-
return;
|
|
172
|
-
}
|
|
173
|
-
target.push(Buffer.from(chunk).toString(encoding));
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
class RuntimeCliExitSignal extends Error {
|
|
177
|
-
readonly exitCode: number;
|
|
178
|
-
|
|
179
|
-
constructor(exitCode: number) {
|
|
180
|
-
super(`CLI requested process exit (${exitCode})`);
|
|
181
|
-
this.exitCode = exitCode;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function patchStreamWrite(stream: NodeJS.WriteStream, target: string[]): () => void {
|
|
186
|
-
const original = stream.write as unknown as WriteFn;
|
|
187
|
-
const patched: WriteFn = (chunk, encodingOrCallback, callback) => {
|
|
188
|
-
const encoding = typeof encodingOrCallback === 'string' ? encodingOrCallback : UTF8_ENCODING;
|
|
189
|
-
const resolvedCallback: WriteCallback =
|
|
190
|
-
typeof encodingOrCallback === 'function' ? encodingOrCallback : callback;
|
|
191
|
-
|
|
192
|
-
appendCapturedChunk(target, chunk, encoding);
|
|
193
|
-
|
|
194
|
-
if (resolvedCallback) {
|
|
195
|
-
resolvedCallback(null);
|
|
196
|
-
}
|
|
197
|
-
return true;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
stream.write = patched as unknown as typeof stream.write;
|
|
201
|
-
return () => {
|
|
202
|
-
stream.write = original as unknown as typeof stream.write;
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
function patchConsoleMethod(methodName: ConsoleCaptureMethodName, target: string[]): () => void {
|
|
207
|
-
const globalConsole = console as unknown as Record<
|
|
208
|
-
ConsoleCaptureMethodName,
|
|
209
|
-
ConsoleCaptureMethod
|
|
210
|
-
>;
|
|
211
|
-
const original = globalConsole[methodName];
|
|
212
|
-
const patched: ConsoleCaptureMethod = (...args) => {
|
|
213
|
-
target.push(`${format(...args)}${OUTPUT_LINE_SUFFIX}`);
|
|
214
|
-
};
|
|
215
|
-
globalConsole[methodName] = patched;
|
|
216
|
-
return () => {
|
|
217
|
-
globalConsole[methodName] = original;
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function patchConsoleOutput(stdoutChunks: string[], stderrChunks: string[]): () => void {
|
|
222
|
-
const restoreMethods: Array<() => void> = [];
|
|
223
|
-
for (const methodName of STDOUT_CONSOLE_METHODS) {
|
|
224
|
-
restoreMethods.push(patchConsoleMethod(methodName, stdoutChunks));
|
|
225
|
-
}
|
|
226
|
-
for (const methodName of STDERR_CONSOLE_METHODS) {
|
|
227
|
-
restoreMethods.push(patchConsoleMethod(methodName, stderrChunks));
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
return () => {
|
|
231
|
-
for (let index = restoreMethods.length - 1; index >= 0; index -= 1) {
|
|
232
|
-
restoreMethods[index]?.();
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
async function defaultLoadRuntimeCliModule(command: RuntimeCliCommand): Promise<RuntimeCliModule> {
|
|
238
|
-
const moduleUrl = resolveCliModuleUrl(command);
|
|
239
|
-
const loaded = (await import(moduleUrl)) as RuntimeCliModule;
|
|
240
|
-
if (!loaded || typeof loaded.main !== 'function') {
|
|
241
|
-
throw new Error(`Runtime CLI command "${command}" does not export main()`);
|
|
242
|
-
}
|
|
243
|
-
return loaded;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export interface RuntimeCliExecutionResult {
|
|
247
|
-
ok: boolean;
|
|
248
|
-
status: number;
|
|
249
|
-
stdout: string;
|
|
250
|
-
stderr: string;
|
|
251
|
-
executionError?: string;
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
export interface RuntimeCliAdapter {
|
|
255
|
-
run(command: RuntimeCliCommand, args: string[]): Promise<RuntimeCliExecutionResult>;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
export interface RuntimeCliAdapterOptions {
|
|
259
|
-
loadModule?: RuntimeCliModuleLoader;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
let executionQueue: Promise<void> = Promise.resolve();
|
|
263
|
-
|
|
264
|
-
async function runExclusive<T>(operation: () => Promise<T>): Promise<T> {
|
|
265
|
-
const scheduled = executionQueue.then(operation, operation);
|
|
266
|
-
executionQueue = scheduled.then(
|
|
267
|
-
() => undefined,
|
|
268
|
-
() => undefined,
|
|
269
|
-
);
|
|
270
|
-
return scheduled;
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
export function createRuntimeCliAdapter(options: RuntimeCliAdapterOptions = {}): RuntimeCliAdapter {
|
|
274
|
-
const loadModule = options.loadModule ?? defaultLoadRuntimeCliModule;
|
|
275
|
-
|
|
276
|
-
return {
|
|
277
|
-
async run(command: RuntimeCliCommand, args: string[]): Promise<RuntimeCliExecutionResult> {
|
|
278
|
-
return runExclusive(async () => {
|
|
279
|
-
const stdoutChunks: string[] = [];
|
|
280
|
-
const stderrChunks: string[] = [];
|
|
281
|
-
const originalArgv = [...process.argv];
|
|
282
|
-
const originalExit = process.exit;
|
|
283
|
-
const restoreStdout = patchStreamWrite(process.stdout, stdoutChunks);
|
|
284
|
-
const restoreStderr = patchStreamWrite(process.stderr, stderrChunks);
|
|
285
|
-
const restoreConsole = patchConsoleOutput(stdoutChunks, stderrChunks);
|
|
286
|
-
|
|
287
|
-
process.argv = [process.execPath, command, ...args];
|
|
288
|
-
process.exit = ((code?: number | string | null | undefined) => {
|
|
289
|
-
throw new RuntimeCliExitSignal(normalizeExitCode(code ?? undefined));
|
|
290
|
-
}) as typeof process.exit;
|
|
291
|
-
|
|
292
|
-
let status = EXIT_STATUS_DEFAULT_OK;
|
|
293
|
-
let executionError: string | undefined;
|
|
294
|
-
|
|
295
|
-
try {
|
|
296
|
-
const module = await loadModule(command);
|
|
297
|
-
await module.main();
|
|
298
|
-
} catch (error) {
|
|
299
|
-
if (error instanceof RuntimeCliExitSignal) {
|
|
300
|
-
status = error.exitCode;
|
|
301
|
-
} else {
|
|
302
|
-
status = EXIT_STATUS_DEFAULT_ERROR;
|
|
303
|
-
executionError = toErrorMessage(error);
|
|
304
|
-
stderrChunks.push(`${executionError}\n`);
|
|
305
|
-
}
|
|
306
|
-
} finally {
|
|
307
|
-
process.argv = originalArgv;
|
|
308
|
-
process.exit = originalExit;
|
|
309
|
-
restoreConsole();
|
|
310
|
-
restoreStdout();
|
|
311
|
-
restoreStderr();
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
const stdout = stdoutChunks.join('');
|
|
315
|
-
const stderr = stderrChunks.join('');
|
|
316
|
-
|
|
317
|
-
return {
|
|
318
|
-
ok: status === EXIT_STATUS_DEFAULT_OK && executionError === undefined,
|
|
319
|
-
status,
|
|
320
|
-
stdout,
|
|
321
|
-
stderr,
|
|
322
|
-
executionError,
|
|
323
|
-
};
|
|
324
|
-
});
|
|
325
|
-
},
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export const runtimeCliAdapter = createRuntimeCliAdapter();
|