@lumenflow/cli 5.5.0 → 5.7.14

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.
Files changed (229) hide show
  1. package/README.md +41 -40
  2. package/dist/db-journal-recover.js +400 -0
  3. package/dist/db-journal-recover.js.map +1 -0
  4. package/dist/docs-sync.js +8 -3
  5. package/dist/docs-sync.js.map +1 -1
  6. package/dist/doctor.js +11 -0
  7. package/dist/doctor.js.map +1 -1
  8. package/dist/gate-defaults.js +37 -0
  9. package/dist/gate-defaults.js.map +1 -1
  10. package/dist/gates/monolithic-file-contention-guard.js +167 -0
  11. package/dist/gates/monolithic-file-contention-guard.js.map +1 -0
  12. package/dist/gates/prod-migration-drift.js +207 -0
  13. package/dist/gates/prod-migration-drift.js.map +1 -0
  14. package/dist/gates/test-over-deletion-guard.js +280 -0
  15. package/dist/gates/test-over-deletion-guard.js.map +1 -0
  16. package/dist/gates-runners.js +44 -3
  17. package/dist/gates-runners.js.map +1 -1
  18. package/dist/gates.js +3 -2
  19. package/dist/gates.js.map +1 -1
  20. package/dist/hooks/config-resolver.js +16 -1
  21. package/dist/hooks/config-resolver.js.map +1 -1
  22. package/dist/hooks/dirty-guard.js +43 -2
  23. package/dist/hooks/dirty-guard.js.map +1 -1
  24. package/dist/hooks/git-status-parser.js +22 -8
  25. package/dist/hooks/git-status-parser.js.map +1 -1
  26. package/dist/init-templates.js +241 -0
  27. package/dist/init-templates.js.map +1 -1
  28. package/dist/init.js +122 -16
  29. package/dist/init.js.map +1 -1
  30. package/dist/lumenflow-setup.js +144 -0
  31. package/dist/lumenflow-setup.js.map +1 -0
  32. package/dist/lumenflow-upgrade.js +43 -1
  33. package/dist/lumenflow-upgrade.js.map +1 -1
  34. package/dist/mem-create.js +10 -1
  35. package/dist/mem-create.js.map +1 -1
  36. package/dist/mem-signal.js +21 -4
  37. package/dist/mem-signal.js.map +1 -1
  38. package/dist/orchestrate-initiative.js +28 -3
  39. package/dist/orchestrate-initiative.js.map +1 -1
  40. package/dist/public-manifest.js +17 -7
  41. package/dist/public-manifest.js.map +1 -1
  42. package/dist/release.js +53 -18
  43. package/dist/release.js.map +1 -1
  44. package/dist/wu-done-gates.js +13 -9
  45. package/dist/wu-done-gates.js.map +1 -1
  46. package/dist/wu-done.js +14 -2
  47. package/dist/wu-done.js.map +1 -1
  48. package/dist/wu-edit-operations.js +74 -0
  49. package/dist/wu-edit-operations.js.map +1 -1
  50. package/dist/wu-edit-validators.js +58 -0
  51. package/dist/wu-edit-validators.js.map +1 -1
  52. package/dist/wu-edit.js +106 -4
  53. package/dist/wu-edit.js.map +1 -1
  54. package/dist/wu-prep.js +57 -9
  55. package/dist/wu-prep.js.map +1 -1
  56. package/dist/wu-recover.js +6 -0
  57. package/dist/wu-recover.js.map +1 -1
  58. package/dist/wu-release.js +120 -2
  59. package/dist/wu-release.js.map +1 -1
  60. package/dist/wu-sizing-validation.js +47 -17
  61. package/dist/wu-sizing-validation.js.map +1 -1
  62. package/dist/wu-status.js +33 -0
  63. package/dist/wu-status.js.map +1 -1
  64. package/package.json +13 -12
  65. package/packs/agent-runtime/package.json +1 -1
  66. package/packs/sidekick/package.json +1 -1
  67. package/packs/software-delivery/package.json +1 -1
  68. package/templates/core/AGENTS.md.template +67 -3
  69. package/templates/core/LUMENFLOW.md.template +196 -47
  70. package/dist/distribution-preflight.js +0 -230
  71. package/dist/distribution-preflight.js.map +0 -1
  72. package/packs/agent-runtime/agent-heartbeat.ts +0 -163
  73. package/packs/agent-runtime/auto-session-integration.ts +0 -888
  74. package/packs/agent-runtime/capability-factory.ts +0 -104
  75. package/packs/agent-runtime/constants.ts +0 -21
  76. package/packs/agent-runtime/delegation-registry-schema.ts +0 -220
  77. package/packs/agent-runtime/delegation-registry-store.ts +0 -269
  78. package/packs/agent-runtime/delegation-tree.ts +0 -328
  79. package/packs/agent-runtime/index.ts +0 -20
  80. package/packs/agent-runtime/manifest.ts +0 -348
  81. package/packs/agent-runtime/memory-coordination-contract.ts +0 -86
  82. package/packs/agent-runtime/orchestration.ts +0 -2027
  83. package/packs/agent-runtime/pack-registration.ts +0 -110
  84. package/packs/agent-runtime/policy-factory.ts +0 -165
  85. package/packs/agent-runtime/remote-controls/index.ts +0 -7
  86. package/packs/agent-runtime/remote-controls/operations.ts +0 -405
  87. package/packs/agent-runtime/remote-controls/port.ts +0 -48
  88. package/packs/agent-runtime/remote-controls/state-store.ts +0 -258
  89. package/packs/agent-runtime/remote-controls/types.ts +0 -105
  90. package/packs/agent-runtime/session-schema.ts +0 -467
  91. package/packs/agent-runtime/tool-impl/agent-turn-tools.ts +0 -793
  92. package/packs/agent-runtime/tool-impl/index.ts +0 -6
  93. package/packs/agent-runtime/tool-impl/provider-adapters.ts +0 -1245
  94. package/packs/agent-runtime/tool-impl/remote-controls.mock.ts +0 -256
  95. package/packs/agent-runtime/tool-impl/remote-controls.ts +0 -273
  96. package/packs/agent-runtime/tools/index.ts +0 -4
  97. package/packs/agent-runtime/tools/types.ts +0 -47
  98. package/packs/agent-runtime/turn-lifecycle-events.ts +0 -590
  99. package/packs/agent-runtime/types.ts +0 -128
  100. package/packs/agent-runtime/vitest.config.ts +0 -11
  101. package/packs/sidekick/channel-ingress.ts +0 -137
  102. package/packs/sidekick/constants.ts +0 -10
  103. package/packs/sidekick/index.ts +0 -8
  104. package/packs/sidekick/manifest-schema.ts +0 -49
  105. package/packs/sidekick/manifest.ts +0 -512
  106. package/packs/sidekick/pack-registration.ts +0 -110
  107. package/packs/sidekick/policy-factory.ts +0 -38
  108. package/packs/sidekick/sidekick-events.ts +0 -694
  109. package/packs/sidekick/src/adapters/cloud-queue.ts +0 -101
  110. package/packs/sidekick/src/adapters/control-plane-bridge.adapter.ts +0 -386
  111. package/packs/sidekick/src/adapters/filesystem-bridge.adapter.ts +0 -228
  112. package/packs/sidekick/src/domain/channel.types.ts +0 -64
  113. package/packs/sidekick/src/ports/channel-bridge.port.ts +0 -92
  114. package/packs/sidekick/src/routines/commit.ts +0 -74
  115. package/packs/sidekick/tool-impl/channel-tools.ts +0 -577
  116. package/packs/sidekick/tool-impl/channel-transports.ts +0 -75
  117. package/packs/sidekick/tool-impl/index.ts +0 -29
  118. package/packs/sidekick/tool-impl/memory-tools.ts +0 -290
  119. package/packs/sidekick/tool-impl/routine-commit.ts +0 -102
  120. package/packs/sidekick/tool-impl/routine-tools.ts +0 -440
  121. package/packs/sidekick/tool-impl/runtime-context.ts +0 -28
  122. package/packs/sidekick/tool-impl/shared.ts +0 -125
  123. package/packs/sidekick/tool-impl/storage.ts +0 -325
  124. package/packs/sidekick/tool-impl/system-tools.ts +0 -160
  125. package/packs/sidekick/tool-impl/task-tools.ts +0 -506
  126. package/packs/sidekick/tools/channel-tools.ts +0 -53
  127. package/packs/sidekick/tools/index.ts +0 -9
  128. package/packs/sidekick/tools/memory-tools.ts +0 -53
  129. package/packs/sidekick/tools/routine-tools.ts +0 -53
  130. package/packs/sidekick/tools/system-tools.ts +0 -47
  131. package/packs/sidekick/tools/task-tools.ts +0 -61
  132. package/packs/sidekick/tools/types.ts +0 -57
  133. package/packs/sidekick/vitest.config.ts +0 -11
  134. package/packs/software-delivery/constants.ts +0 -10
  135. package/packs/software-delivery/extensions.ts +0 -140
  136. package/packs/software-delivery/gate-policies.ts +0 -134
  137. package/packs/software-delivery/index.ts +0 -8
  138. package/packs/software-delivery/manifest-schema.ts +0 -268
  139. package/packs/software-delivery/manifest.ts +0 -657
  140. package/packs/software-delivery/pack-registration.ts +0 -113
  141. package/packs/software-delivery/src/commands/index.ts +0 -5
  142. package/packs/software-delivery/src/config/delivery-review-contract.ts +0 -256
  143. package/packs/software-delivery/src/config/env-accessors.ts +0 -66
  144. package/packs/software-delivery/src/config/index.ts +0 -8
  145. package/packs/software-delivery/src/config/normalize-config-keys.ts +0 -9
  146. package/packs/software-delivery/src/config/schemas/lumenflow-config-schema-types.ts +0 -460
  147. package/packs/software-delivery/src/config/workspace-reader.ts +0 -375
  148. package/packs/software-delivery/src/constants/backlog-patterns.ts +0 -31
  149. package/packs/software-delivery/src/constants/client-ids.ts +0 -19
  150. package/packs/software-delivery/src/constants/config-contract.ts +0 -7
  151. package/packs/software-delivery/src/constants/docs-layout-presets.ts +0 -50
  152. package/packs/software-delivery/src/constants/duration-constants.ts +0 -20
  153. package/packs/software-delivery/src/constants/gate-constants.ts +0 -32
  154. package/packs/software-delivery/src/constants/index.ts +0 -29
  155. package/packs/software-delivery/src/constants/lock-constants.ts +0 -35
  156. package/packs/software-delivery/src/constants/object-guards.ts +0 -12
  157. package/packs/software-delivery/src/constants/section-headings.ts +0 -107
  158. package/packs/software-delivery/src/constants/wu-cli-constants.ts +0 -500
  159. package/packs/software-delivery/src/constants/wu-domain-constants.ts +0 -466
  160. package/packs/software-delivery/src/constants/wu-git-constants.ts +0 -7
  161. package/packs/software-delivery/src/constants/wu-id-format.ts +0 -327
  162. package/packs/software-delivery/src/constants/wu-paths-constants.ts +0 -384
  163. package/packs/software-delivery/src/constants/wu-statuses.ts +0 -287
  164. package/packs/software-delivery/src/constants/wu-type-helpers.ts +0 -67
  165. package/packs/software-delivery/src/constants/wu-ui-constants.ts +0 -267
  166. package/packs/software-delivery/src/constants/wu-validation-constants.ts +0 -73
  167. package/packs/software-delivery/src/domain/index.ts +0 -5
  168. package/packs/software-delivery/src/domain/orchestration.constants.ts +0 -166
  169. package/packs/software-delivery/src/domain/orchestration.schemas.ts +0 -238
  170. package/packs/software-delivery/src/domain/orchestration.types.ts +0 -176
  171. package/packs/software-delivery/src/methodology/incremental-test.ts +0 -122
  172. package/packs/software-delivery/src/methodology/index.ts +0 -6
  173. package/packs/software-delivery/src/methodology/manual-test-validator.ts +0 -292
  174. package/packs/software-delivery/src/policy/coverage-gate.ts +0 -270
  175. package/packs/software-delivery/src/policy/gates-agent-mode.ts +0 -223
  176. package/packs/software-delivery/src/policy/gates-config-internal.ts +0 -121
  177. package/packs/software-delivery/src/policy/gates-config.ts +0 -300
  178. package/packs/software-delivery/src/policy/gates-coverage.ts +0 -356
  179. package/packs/software-delivery/src/policy/gates-presets.ts +0 -134
  180. package/packs/software-delivery/src/policy/gates-schemas.ts +0 -173
  181. package/packs/software-delivery/src/policy/index.ts +0 -22
  182. package/packs/software-delivery/src/policy/package-manager-resolver.ts +0 -319
  183. package/packs/software-delivery/src/policy/resolve-policy.ts +0 -601
  184. package/packs/software-delivery/src/ports/config.ports.ts +0 -90
  185. package/packs/software-delivery/src/ports/dashboard-renderer.port.ts +0 -125
  186. package/packs/software-delivery/src/ports/index.ts +0 -10
  187. package/packs/software-delivery/src/ports/sync-validator.ports.ts +0 -59
  188. package/packs/software-delivery/src/ports/wu-helpers.ports.ts +0 -168
  189. package/packs/software-delivery/src/ports/wu-state.ports.ts +0 -241
  190. package/packs/software-delivery/src/primitives/index.ts +0 -5
  191. package/packs/software-delivery/src/runtime/index.ts +0 -6
  192. package/packs/software-delivery/src/runtime/work-classifier.ts +0 -561
  193. package/packs/software-delivery/src/sandbox/index.ts +0 -10
  194. package/packs/software-delivery/src/sandbox/sandbox-allowlist.ts +0 -118
  195. package/packs/software-delivery/src/sandbox/sandbox-backend-linux.ts +0 -88
  196. package/packs/software-delivery/src/sandbox/sandbox-backend-macos.ts +0 -154
  197. package/packs/software-delivery/src/sandbox/sandbox-backend-windows.ts +0 -47
  198. package/packs/software-delivery/src/sandbox/sandbox-profile.ts +0 -153
  199. package/packs/software-delivery/src/schemas/index.ts +0 -5
  200. package/packs/software-delivery/src/state/date-utils.ts +0 -158
  201. package/packs/software-delivery/src/state/index.ts +0 -15
  202. package/packs/software-delivery/src/state/state-machine.ts +0 -119
  203. package/packs/software-delivery/src/state/wu-doc-types.ts +0 -51
  204. package/packs/software-delivery/src/state/wu-paths.ts +0 -381
  205. package/packs/software-delivery/src/state/wu-schema.ts +0 -1139
  206. package/packs/software-delivery/src/state/wu-state-schema.ts +0 -255
  207. package/packs/software-delivery/src/state/wu-yaml.ts +0 -338
  208. package/packs/software-delivery/tool-impl/agent-tools.ts +0 -263
  209. package/packs/software-delivery/tool-impl/delegation-tools.ts +0 -66
  210. package/packs/software-delivery/tool-impl/flow-metrics-tools.ts +0 -219
  211. package/packs/software-delivery/tool-impl/git-runner.ts +0 -113
  212. package/packs/software-delivery/tool-impl/git-tools.ts +0 -316
  213. package/packs/software-delivery/tool-impl/index.ts +0 -15
  214. package/packs/software-delivery/tool-impl/initiative-orchestration-tools.ts +0 -720
  215. package/packs/software-delivery/tool-impl/lane-lock.ts +0 -246
  216. package/packs/software-delivery/tool-impl/memory-tools.ts +0 -470
  217. package/packs/software-delivery/tool-impl/pending-runtime-tools.ts +0 -21
  218. package/packs/software-delivery/tool-impl/runtime-cli-adapter.ts +0 -329
  219. package/packs/software-delivery/tool-impl/runtime-native-tools.ts +0 -687
  220. package/packs/software-delivery/tool-impl/worker-loader.ts +0 -52
  221. package/packs/software-delivery/tool-impl/worktree-tools.ts +0 -46
  222. package/packs/software-delivery/tool-impl/wu-lifecycle-tools.ts +0 -807
  223. package/packs/software-delivery/tools/delegation-tools.ts +0 -23
  224. package/packs/software-delivery/tools/git-tools.ts +0 -55
  225. package/packs/software-delivery/tools/index.ts +0 -8
  226. package/packs/software-delivery/tools/lane-lock-tool.ts +0 -37
  227. package/packs/software-delivery/tools/types.ts +0 -71
  228. package/packs/software-delivery/tools/worktree-tools.ts +0 -49
  229. package/packs/software-delivery/vitest.config.ts +0 -11
@@ -1,110 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- import { createHash } from 'node:crypto';
5
- import { readdir, readFile } from 'node:fs/promises';
6
- import path from 'node:path';
7
- import { fileURLToPath } from 'node:url';
8
- import { AGENT_RUNTIME_MANIFEST } from './manifest.js';
9
- import { AGENT_RUNTIME_MANIFEST_FILE_NAME, SHA256_ALGORITHM, UTF8_ENCODING } from './constants.js';
10
- import type { AgentRuntimePackManifest } from './manifest.js';
11
-
12
- const NULL_BYTE_BUFFER = Buffer.from([0]);
13
- const DEFAULT_EXCLUSIONS = ['node_modules/', '.git/', 'dist/', '.DS_Store'] as const;
14
-
15
- function getDefaultPackRoot(): string {
16
- return path.dirname(fileURLToPath(import.meta.url));
17
- }
18
-
19
- function normalizeRelativePath(root: string, absolutePath: string): string {
20
- return path.relative(root, absolutePath).split(path.sep).join('/');
21
- }
22
-
23
- function shouldExclude(relativePath: string, exclusions: readonly string[]): boolean {
24
- return exclusions.some((excluded) => {
25
- if (excluded.endsWith('/')) {
26
- return relativePath.startsWith(excluded);
27
- }
28
- return relativePath === excluded || relativePath.endsWith(`/${excluded}`);
29
- });
30
- }
31
-
32
- async function collectFilesRecursive(root: string, directory: string): Promise<string[]> {
33
- const entries = await readdir(directory, { withFileTypes: true });
34
- const sortedEntries = [...entries].sort((left, right) => left.name.localeCompare(right.name));
35
- const files: string[] = [];
36
-
37
- for (const entry of sortedEntries) {
38
- const absolutePath = path.join(directory, entry.name);
39
- const relativePath = normalizeRelativePath(root, absolutePath);
40
- if (entry.isDirectory()) {
41
- files.push(...(await collectFilesRecursive(root, absolutePath)));
42
- continue;
43
- }
44
- files.push(relativePath);
45
- }
46
-
47
- return files;
48
- }
49
-
50
- async function listPackFiles(packRoot: string, exclusions: readonly string[]): Promise<string[]> {
51
- const absoluteRoot = path.resolve(packRoot);
52
- const allFiles = await collectFilesRecursive(absoluteRoot, absoluteRoot);
53
- return allFiles.filter((relativePath) => !shouldExclude(relativePath, exclusions)).sort();
54
- }
55
-
56
- export async function computeAgentRuntimePackIntegrity(
57
- packRoot = getDefaultPackRoot(),
58
- exclusions: readonly string[] = DEFAULT_EXCLUSIONS,
59
- ): Promise<`sha256:${string}`> {
60
- const absoluteRoot = path.resolve(packRoot);
61
- const files = await listPackFiles(absoluteRoot, exclusions);
62
- const digestChunks: Buffer[] = [];
63
-
64
- for (const relativePath of files) {
65
- const fileContents = await readFile(path.join(absoluteRoot, relativePath));
66
- const fileHash = createHash(SHA256_ALGORITHM).update(fileContents).digest('hex');
67
- digestChunks.push(Buffer.from(relativePath, UTF8_ENCODING));
68
- digestChunks.push(NULL_BYTE_BUFFER);
69
- digestChunks.push(Buffer.from(fileHash, UTF8_ENCODING));
70
- digestChunks.push(NULL_BYTE_BUFFER);
71
- }
72
-
73
- const combinedDigest = createHash(SHA256_ALGORITHM)
74
- .update(digestChunks.length === 0 ? Buffer.alloc(0) : Buffer.concat(digestChunks))
75
- .digest('hex');
76
-
77
- return `sha256:${combinedDigest}`;
78
- }
79
-
80
- export async function loadAgentRuntimeManifest(
81
- packRoot = getDefaultPackRoot(),
82
- ): Promise<AgentRuntimePackManifest> {
83
- const manifestPath = path.join(path.resolve(packRoot), AGENT_RUNTIME_MANIFEST_FILE_NAME);
84
- await readFile(manifestPath, UTF8_ENCODING);
85
- return structuredClone(AGENT_RUNTIME_MANIFEST);
86
- }
87
-
88
- export interface RegisteredAgentRuntimePack {
89
- manifest: AgentRuntimePackManifest;
90
- packRoot: string;
91
- manifestPath: string;
92
- integrity: `sha256:${string}`;
93
- }
94
-
95
- export async function registerAgentRuntimePack(options?: {
96
- packRoot?: string;
97
- exclusions?: readonly string[];
98
- }): Promise<RegisteredAgentRuntimePack> {
99
- const packRoot = path.resolve(options?.packRoot ?? getDefaultPackRoot());
100
- const exclusions = options?.exclusions ?? DEFAULT_EXCLUSIONS;
101
- const manifest = await loadAgentRuntimeManifest(packRoot);
102
- const integrity = await computeAgentRuntimePackIntegrity(packRoot, exclusions);
103
-
104
- return {
105
- manifest,
106
- packRoot,
107
- manifestPath: path.join(packRoot, AGENT_RUNTIME_MANIFEST_FILE_NAME),
108
- integrity,
109
- };
110
- }
@@ -1,165 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- import { POLICY_TRIGGERS, type PackPolicyFactory, type PolicyRule } from '@lumenflow/kernel';
5
- import {
6
- AGENT_RUNTIME_AGENT_INTENT_METADATA_KEY,
7
- AGENT_RUNTIME_POLICY_ID_PREFIX,
8
- } from './constants.js';
9
- import type { AgentRuntimeIntentConfig, AgentRuntimePackConfig } from './types.js';
10
-
11
- interface NormalizedIntentRule {
12
- allowTools: Set<string>;
13
- approvalRequiredTools: Set<string>;
14
- }
15
-
16
- type NormalizedIntentRuleMap = Map<string, NormalizedIntentRule>;
17
-
18
- export const createAgentRuntimePolicyFactory: PackPolicyFactory = async (input) => {
19
- const intentRules = normalizeIntentRules(input.packConfig);
20
- if (intentRules.size === 0) {
21
- return [];
22
- }
23
-
24
- const rules: PolicyRule[] = [
25
- {
26
- id: `${AGENT_RUNTIME_POLICY_ID_PREFIX}.intent-approval`,
27
- trigger: POLICY_TRIGGERS.ON_TOOL_REQUEST,
28
- decision: 'approval_required',
29
- reason: 'The classified agent intent requires approval before this tool may run.',
30
- when: (context) => matchesApprovalRequiredIntent(context, intentRules),
31
- },
32
- {
33
- id: `${AGENT_RUNTIME_POLICY_ID_PREFIX}.intent-deny`,
34
- trigger: POLICY_TRIGGERS.ON_TOOL_REQUEST,
35
- decision: 'deny',
36
- reason: 'The classified agent intent does not permit this tool.',
37
- when: (context) => matchesDeniedIntent(context, intentRules),
38
- },
39
- ];
40
-
41
- return rules;
42
- };
43
-
44
- function normalizeIntentRules(packConfig: unknown): NormalizedIntentRuleMap {
45
- const config = asRecord(packConfig);
46
- const intents = asRecord(config?.intents);
47
- if (!intents) {
48
- return new Map();
49
- }
50
-
51
- const normalized = new Map<string, NormalizedIntentRule>();
52
- for (const [intentId, candidate] of Object.entries(intents)) {
53
- const parsed = normalizeIntentConfig(intentId, candidate);
54
- normalized.set(intentId, parsed);
55
- }
56
- return normalized;
57
- }
58
-
59
- function normalizeIntentConfig(intentId: string, value: unknown): NormalizedIntentRule {
60
- const config = asRecord(value);
61
- if (!config) {
62
- throw new Error(`agent_runtime.intents.${intentId} must be an object.`);
63
- }
64
-
65
- const allowTools = normalizeToolList(
66
- config.allow_tools,
67
- `agent_runtime.intents.${intentId}.allow_tools`,
68
- );
69
- const approvalRequiredTools = normalizeToolList(
70
- config.approval_required_tools,
71
- `agent_runtime.intents.${intentId}.approval_required_tools`,
72
- true,
73
- );
74
-
75
- return {
76
- allowTools: new Set([...allowTools, ...approvalRequiredTools]),
77
- approvalRequiredTools: new Set(approvalRequiredTools),
78
- };
79
- }
80
-
81
- function normalizeToolList(value: unknown, fieldName: string, optional = false): string[] {
82
- if (value === undefined && optional) {
83
- return [];
84
- }
85
- if (
86
- !Array.isArray(value) ||
87
- value.some((entry) => typeof entry !== 'string' || entry.trim().length === 0)
88
- ) {
89
- throw new Error(`${fieldName} must be an array of non-empty strings.`);
90
- }
91
-
92
- return value.map((entry) => entry.trim());
93
- }
94
-
95
- function matchesApprovalRequiredIntent(
96
- context: Parameters<NonNullable<PolicyRule['when']>>[0],
97
- intentRules: NormalizedIntentRuleMap,
98
- ): boolean {
99
- const toolName = readCandidateToolName(context);
100
- if (!toolName) {
101
- return false;
102
- }
103
-
104
- const intentRule = resolveIntentRule(context, intentRules);
105
- return intentRule?.approvalRequiredTools.has(toolName) ?? false;
106
- }
107
-
108
- function matchesDeniedIntent(
109
- context: Parameters<NonNullable<PolicyRule['when']>>[0],
110
- intentRules: NormalizedIntentRuleMap,
111
- ): boolean {
112
- const toolName = readCandidateToolName(context);
113
- if (!toolName) {
114
- return false;
115
- }
116
-
117
- const intentRule = resolveIntentRule(context, intentRules);
118
- if (!intentRule) {
119
- return false;
120
- }
121
-
122
- return !intentRule.allowTools.has(toolName);
123
- }
124
-
125
- function resolveIntentRule(
126
- context: Parameters<NonNullable<PolicyRule['when']>>[0],
127
- intentRules: NormalizedIntentRuleMap,
128
- ): NormalizedIntentRule | null {
129
- const intent = readAgentIntent(context);
130
- if (!intent) {
131
- return null;
132
- }
133
-
134
- return (
135
- intentRules.get(intent) ?? {
136
- allowTools: new Set<string>(),
137
- approvalRequiredTools: new Set<string>(),
138
- }
139
- );
140
- }
141
-
142
- function readAgentIntent(context: Parameters<NonNullable<PolicyRule['when']>>[0]): string | null {
143
- const executionMetadata = asRecord(context.execution_metadata);
144
- const candidate = executionMetadata?.[AGENT_RUNTIME_AGENT_INTENT_METADATA_KEY];
145
- return typeof candidate === 'string' && candidate.trim().length > 0 ? candidate.trim() : null;
146
- }
147
-
148
- function readCandidateToolName(
149
- context: Parameters<NonNullable<PolicyRule['when']>>[0],
150
- ): string | null {
151
- if (typeof context.tool_name !== 'string' || context.tool_name.trim().length === 0) {
152
- return null;
153
- }
154
-
155
- const toolName = context.tool_name.trim();
156
- return toolName === 'agent:execute-turn' ? null : toolName;
157
- }
158
-
159
- function asRecord(value: unknown): Record<string, unknown> | null {
160
- return typeof value === 'object' && value !== null && !Array.isArray(value)
161
- ? (value as Record<string, unknown>)
162
- : null;
163
- }
164
-
165
- export type { AgentRuntimeIntentConfig, AgentRuntimePackConfig };
@@ -1,7 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
-
4
- export * from './port.js';
5
- export * from './types.js';
6
- export * from './state-store.js';
7
- export * from './operations.js';
@@ -1,405 +0,0 @@
1
- // Copyright (c) 2026 Hellmai Ltd
2
- // SPDX-License-Identifier: LicenseRef-LumenFlow-Proprietary
3
- //
4
- // WU-2733 (INIT-060 Phase 3, ADR-013 §1 + §6):
5
- // Real kernel-side implementations for the six remote-control
6
- // operations. Each operation:
7
- // 1. Loads/mutates RemoteControlSessionState via the sidecar store
8
- // (so state survives process restarts).
9
- // 2. Emits the ADR-013-governed event via the supplied sink
10
- // (turn_aborted / autonomy_changed / tool_called).
11
- // 3. Returns a result that adheres to RemoteControlPort.
12
- //
13
- // No auto-wu:recover. recovery_action is always a hint; ADR-013 §1
14
- // safety lock is preserved.
15
-
16
- import { randomUUID } from 'node:crypto';
17
- import {
18
- buildToolCalledEvent,
19
- buildTurnAbortedEvent,
20
- buildAutonomyChangedEvent,
21
- emitAgentRuntimeEvent,
22
- type AgentRuntimeCleanupStatus,
23
- type AgentRuntimeEventSink,
24
- } from '../turn-lifecycle-events.js';
25
- import {
26
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES,
27
- type AbortTurnInvocationResult,
28
- type AgentRuntimeRemoteControlToolName,
29
- type RemoteControlInvocationResult,
30
- } from './types.js';
31
- import type { AbortTurnInvocationInput, RemoteControlInvocationInput } from './port.js';
32
- import {
33
- AGENT_RUNTIME_AUTONOMY_LEVELS,
34
- AGENT_RUNTIME_AUTONOMY_LEVEL_VALUES,
35
- type AgentRuntimeAutonomyLevel,
36
- type RemoteControlStateStore,
37
- } from './state-store.js';
38
-
39
- /**
40
- * Observed turn index emitted in remote-control tool_called events.
41
- * The real kernel runtime increments a per-turn counter; remote-control
42
- * invocations happen OUTSIDE an active turn (that is precisely their
43
- * purpose), so we emit 0 to signal "not tied to a turn index". This
44
- * mirrors the mock adapter's constant for wire parity.
45
- */
46
- const REMOTE_CONTROL_TURN_INDEX = 0;
47
-
48
- export interface RemoteControlOperationContext {
49
- store: RemoteControlStateStore;
50
- eventSink?: AgentRuntimeEventSink;
51
- now: () => string;
52
- }
53
-
54
- function resolveSessionId(input: string | undefined): string | null {
55
- if (input !== undefined && input.trim().length > 0) {
56
- return input;
57
- }
58
- return null;
59
- }
60
-
61
- function emitToolCalled(
62
- ctx: RemoteControlOperationContext,
63
- toolName: AgentRuntimeRemoteControlToolName,
64
- sessionId: string,
65
- ): void {
66
- emitAgentRuntimeEvent(
67
- ctx.eventSink,
68
- buildToolCalledEvent({
69
- session_id: sessionId,
70
- turn_index: REMOTE_CONTROL_TURN_INDEX,
71
- tool_name: toolName,
72
- tool_call_id: randomUUID(),
73
- // WU-2829: remote-control invocations are governed by the
74
- // conductor's approval flow BEFORE the kernel-side operation
75
- // runs. By the time this emission fires, the operation has
76
- // already been authorised — approved is always true at this
77
- // call site.
78
- approved: true,
79
- }),
80
- );
81
- }
82
-
83
- function requireSessionId(
84
- toolName: AgentRuntimeRemoteControlToolName,
85
- input: string | undefined,
86
- ): string {
87
- const resolved = resolveSessionId(input);
88
- if (!resolved) {
89
- throw new Error(`Remote-control tool "${toolName}" requires a non-empty session_id input.`);
90
- }
91
- return resolved;
92
- }
93
-
94
- // ---------------------------------------------------------------------------
95
- // pause_turn
96
- // ---------------------------------------------------------------------------
97
-
98
- /**
99
- * Soft-pause marker honoured at the next checkpoint. The running turn
100
- * (if any) observes the marker via a state load and suspends gracefully.
101
- * Re-pausing an already-paused session is idempotent — we refresh the
102
- * reason+timestamp without toggling.
103
- */
104
- export async function pauseTurn(
105
- input: RemoteControlInvocationInput & { reason?: string | null },
106
- ctx: RemoteControlOperationContext,
107
- ): Promise<RemoteControlInvocationResult> {
108
- const sessionId = requireSessionId(
109
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.PAUSE_TURN,
110
- input.session_id,
111
- );
112
- const now = ctx.now();
113
- const state = await ctx.store.loadOrDefault(sessionId, now);
114
- const reason = typeof input.reason === 'string' ? input.reason : null;
115
- await ctx.store.save({
116
- ...state,
117
- pause: {
118
- paused: true,
119
- paused_at: now,
120
- resumed_at: null,
121
- reason,
122
- },
123
- updated_at: now,
124
- });
125
- emitToolCalled(ctx, AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.PAUSE_TURN, sessionId);
126
- return {
127
- status: 'ok',
128
- tool_name: AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.PAUSE_TURN,
129
- session_id: sessionId,
130
- };
131
- }
132
-
133
- // ---------------------------------------------------------------------------
134
- // resume_workflow
135
- // ---------------------------------------------------------------------------
136
-
137
- /**
138
- * Clears the pause marker so the next checkpoint observer advances the
139
- * workflow. Does NOT re-enter the agent loop — the pauser/scheduler
140
- * resumes the session on its next poll. Emits tool_called for audit.
141
- */
142
- export async function resumeWorkflow(
143
- input: RemoteControlInvocationInput,
144
- ctx: RemoteControlOperationContext,
145
- ): Promise<RemoteControlInvocationResult> {
146
- const sessionId = requireSessionId(
147
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.RESUME_WORKFLOW,
148
- input.session_id,
149
- );
150
- const now = ctx.now();
151
- const state = await ctx.store.loadOrDefault(sessionId, now);
152
- await ctx.store.save({
153
- ...state,
154
- pause: {
155
- paused: false,
156
- paused_at: state.pause.paused_at,
157
- resumed_at: now,
158
- reason: state.pause.reason,
159
- },
160
- updated_at: now,
161
- });
162
- emitToolCalled(ctx, AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.RESUME_WORKFLOW, sessionId);
163
- return {
164
- status: 'ok',
165
- tool_name: AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.RESUME_WORKFLOW,
166
- session_id: sessionId,
167
- };
168
- }
169
-
170
- // ---------------------------------------------------------------------------
171
- // abort_turn (ADR-013 §1)
172
- // ---------------------------------------------------------------------------
173
-
174
- /**
175
- * Hard-aborts the current turn and records the cleanup_status +
176
- * recovery_action per ADR-013 §1:
177
- * - 'clean' — no prior mutations; recovery_action = null
178
- * - 'partial' — inflight approvals existed; recovery_action
179
- * is a prose hint
180
- * - 'needs_recovery' — abort interrupted a mid-flight approval with
181
- * the abort ordered while paused; operator must
182
- * run `wu:recover`
183
- *
184
- * NEVER auto-triggers wu:recover. The returned recovery_action is a
185
- * hint cloud renders in the conductor UI (§1 safety lock).
186
- */
187
- export async function abortTurn(
188
- input: AbortTurnInvocationInput,
189
- ctx: RemoteControlOperationContext,
190
- ): Promise<AbortTurnInvocationResult> {
191
- const sessionId = requireSessionId(
192
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.ABORT_TURN,
193
- input.session_id,
194
- );
195
- const now = ctx.now();
196
- const state = await ctx.store.loadOrDefault(sessionId, now);
197
- const { cleanup_status, recovery_action } = classifyAbort(state);
198
- const reason =
199
- typeof input.reason === 'string' && input.reason.trim().length > 0
200
- ? input.reason
201
- : 'operator-requested';
202
- await ctx.store.save({
203
- ...state,
204
- abort: {
205
- aborted: true,
206
- aborted_at: now,
207
- cleanup_status,
208
- recovery_action,
209
- reason,
210
- },
211
- pause: state.pause,
212
- updated_at: now,
213
- });
214
-
215
- // ADR-013 §1: emit turn_aborted carrying the cleanup contract.
216
- emitAgentRuntimeEvent(
217
- ctx.eventSink,
218
- buildTurnAbortedEvent({
219
- session_id: sessionId,
220
- turn_index: REMOTE_CONTROL_TURN_INDEX,
221
- cleanup_status,
222
- recovery_action,
223
- reason,
224
- }),
225
- );
226
- // ADR-013 §6: emit tool_called for audit of the governance surface.
227
- emitToolCalled(ctx, AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.ABORT_TURN, sessionId);
228
-
229
- return {
230
- status: 'ok',
231
- tool_name: AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.ABORT_TURN,
232
- session_id: sessionId,
233
- cleanup_status,
234
- recovery_action,
235
- };
236
- }
237
-
238
- interface AbortClassification {
239
- cleanup_status: AgentRuntimeCleanupStatus;
240
- recovery_action: string | null;
241
- }
242
-
243
- /**
244
- * Decide cleanup_status per ADR-013 §1 abort table.
245
- *
246
- * - Fresh/unused session state → 'clean'; no mutations occurred.
247
- * - Paused session with ≥1 inflight approval → 'needs_recovery'; state
248
- * may be inconsistent because an approval was mid-flight when pause
249
- * landed and the operator ordered an abort on top.
250
- * - Either "paused" OR "inflight approvals" alone → 'partial'; the
251
- * session is self-consistent but has uncommitted work.
252
- */
253
- function classifyAbort(state: {
254
- pause: { paused: boolean };
255
- inflight_approvals: readonly unknown[];
256
- }): AbortClassification {
257
- const hasInflight = state.inflight_approvals.length > 0;
258
- const isPaused = state.pause.paused;
259
-
260
- if (!hasInflight && !isPaused) {
261
- return { cleanup_status: 'clean', recovery_action: null };
262
- }
263
- if (hasInflight && isPaused) {
264
- return {
265
- cleanup_status: 'needs_recovery',
266
- recovery_action:
267
- 'Run `pnpm wu:recover --session ${session}` to reconcile the paused session with pending approval state.',
268
- };
269
- }
270
- if (hasInflight) {
271
- return {
272
- cleanup_status: 'partial',
273
- recovery_action:
274
- 'Review inflight approvals in the conductor UI; re-run `wu:prep` after the approval is cleared.',
275
- };
276
- }
277
- return {
278
- cleanup_status: 'partial',
279
- recovery_action:
280
- 'Session was paused when the abort landed; review the paused continuation before resuming.',
281
- };
282
- }
283
-
284
- // ---------------------------------------------------------------------------
285
- // elevate_autonomy / lower_autonomy
286
- // ---------------------------------------------------------------------------
287
-
288
- function autonomyIndex(level: AgentRuntimeAutonomyLevel): number {
289
- return AGENT_RUNTIME_AUTONOMY_LEVEL_VALUES.indexOf(level);
290
- }
291
-
292
- function nextAutonomyLevel(
293
- current: AgentRuntimeAutonomyLevel,
294
- direction: 'elevate' | 'lower',
295
- ): AgentRuntimeAutonomyLevel {
296
- const index = autonomyIndex(current);
297
- const delta = direction === 'elevate' ? 1 : -1;
298
- const candidate = index + delta;
299
- if (candidate < 0 || candidate >= AGENT_RUNTIME_AUTONOMY_LEVEL_VALUES.length) {
300
- return current;
301
- }
302
- return AGENT_RUNTIME_AUTONOMY_LEVEL_VALUES[candidate] ?? current;
303
- }
304
-
305
- async function transitionAutonomy(
306
- toolName: AgentRuntimeRemoteControlToolName,
307
- direction: 'elevate' | 'lower',
308
- input: RemoteControlInvocationInput & { reason?: string | null },
309
- ctx: RemoteControlOperationContext,
310
- ): Promise<RemoteControlInvocationResult> {
311
- const sessionId = requireSessionId(toolName, input.session_id);
312
- const now = ctx.now();
313
- const state = await ctx.store.loadOrDefault(sessionId, now);
314
- const previousLevel = state.autonomy_level;
315
- const newLevel = nextAutonomyLevel(previousLevel, direction);
316
- await ctx.store.save({
317
- ...state,
318
- autonomy_level: newLevel,
319
- updated_at: now,
320
- });
321
-
322
- // §6 governance — record BOTH autonomy_changed AND tool_called.
323
- emitAgentRuntimeEvent(
324
- ctx.eventSink,
325
- buildAutonomyChangedEvent({
326
- session_id: sessionId,
327
- previous_level: previousLevel,
328
- new_level: newLevel,
329
- direction,
330
- reason: typeof input.reason === 'string' ? input.reason : null,
331
- }),
332
- );
333
- emitToolCalled(ctx, toolName, sessionId);
334
-
335
- return {
336
- status: 'ok',
337
- tool_name: toolName,
338
- session_id: sessionId,
339
- };
340
- }
341
-
342
- export async function elevateAutonomy(
343
- input: RemoteControlInvocationInput & { reason?: string | null },
344
- ctx: RemoteControlOperationContext,
345
- ): Promise<RemoteControlInvocationResult> {
346
- return transitionAutonomy(
347
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.ELEVATE_AUTONOMY,
348
- 'elevate',
349
- input,
350
- ctx,
351
- );
352
- }
353
-
354
- export async function lowerAutonomy(
355
- input: RemoteControlInvocationInput & { reason?: string | null },
356
- ctx: RemoteControlOperationContext,
357
- ): Promise<RemoteControlInvocationResult> {
358
- return transitionAutonomy(
359
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.LOWER_AUTONOMY,
360
- 'lower',
361
- input,
362
- ctx,
363
- );
364
- }
365
-
366
- // ---------------------------------------------------------------------------
367
- // approve_inflight
368
- // ---------------------------------------------------------------------------
369
-
370
- /**
371
- * Resolves the oldest pending in-flight approval for a session. The
372
- * approval queue lives inside RemoteControlSessionState; workflow-level
373
- * approval gating remains the orchestration module's responsibility —
374
- * this tool only clears the queue entry so the workflow observer sees
375
- * the approval as satisfied.
376
- *
377
- * If there are no pending approvals, we still emit tool_called and
378
- * return `status: 'ok'` — the operator's click is auditable even when
379
- * it was a no-op race against an auto-resolved approval.
380
- */
381
- export async function approveInflight(
382
- input: RemoteControlInvocationInput,
383
- ctx: RemoteControlOperationContext,
384
- ): Promise<RemoteControlInvocationResult> {
385
- const sessionId = requireSessionId(
386
- AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.APPROVE_INFLIGHT,
387
- input.session_id,
388
- );
389
- const now = ctx.now();
390
- const state = await ctx.store.loadOrDefault(sessionId, now);
391
- const [, ...remaining] = state.inflight_approvals;
392
- await ctx.store.save({
393
- ...state,
394
- inflight_approvals: remaining,
395
- updated_at: now,
396
- });
397
- emitToolCalled(ctx, AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.APPROVE_INFLIGHT, sessionId);
398
- return {
399
- status: 'ok',
400
- tool_name: AGENT_RUNTIME_REMOTE_CONTROL_TOOL_NAMES.APPROVE_INFLIGHT,
401
- session_id: sessionId,
402
- };
403
- }
404
-
405
- export { AGENT_RUNTIME_AUTONOMY_LEVELS };