@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.
Files changed (213) hide show
  1. package/README.md +42 -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/gate-defaults.js +37 -0
  7. package/dist/gate-defaults.js.map +1 -1
  8. package/dist/gates/monolithic-file-contention-guard.js +167 -0
  9. package/dist/gates/monolithic-file-contention-guard.js.map +1 -0
  10. package/dist/gates/prod-migration-drift.js +207 -0
  11. package/dist/gates/prod-migration-drift.js.map +1 -0
  12. package/dist/gates/test-over-deletion-guard.js +255 -0
  13. package/dist/gates/test-over-deletion-guard.js.map +1 -0
  14. package/dist/gates-runners.js +44 -3
  15. package/dist/gates-runners.js.map +1 -1
  16. package/dist/gates.js +3 -2
  17. package/dist/gates.js.map +1 -1
  18. package/dist/lumenflow-setup.js +144 -0
  19. package/dist/lumenflow-setup.js.map +1 -0
  20. package/dist/lumenflow-upgrade.js +2 -1
  21. package/dist/lumenflow-upgrade.js.map +1 -1
  22. package/dist/mem-create.js +10 -1
  23. package/dist/mem-create.js.map +1 -1
  24. package/dist/mem-signal.js +21 -4
  25. package/dist/mem-signal.js.map +1 -1
  26. package/dist/orchestrate-initiative.js +28 -3
  27. package/dist/orchestrate-initiative.js.map +1 -1
  28. package/dist/public-manifest.js +17 -0
  29. package/dist/public-manifest.js.map +1 -1
  30. package/dist/release.js +53 -18
  31. package/dist/release.js.map +1 -1
  32. package/dist/wu-done-gates.js +13 -9
  33. package/dist/wu-done-gates.js.map +1 -1
  34. package/dist/wu-edit-operations.js +74 -0
  35. package/dist/wu-edit-operations.js.map +1 -1
  36. package/dist/wu-edit-validators.js +58 -0
  37. package/dist/wu-edit-validators.js.map +1 -1
  38. package/dist/wu-edit.js +106 -4
  39. package/dist/wu-edit.js.map +1 -1
  40. package/dist/wu-prep.js +41 -7
  41. package/dist/wu-prep.js.map +1 -1
  42. package/dist/wu-recover.js +6 -0
  43. package/dist/wu-recover.js.map +1 -1
  44. package/dist/wu-release.js +120 -2
  45. package/dist/wu-release.js.map +1 -1
  46. package/dist/wu-sizing-validation.js +47 -17
  47. package/dist/wu-sizing-validation.js.map +1 -1
  48. package/dist/wu-status.js +33 -0
  49. package/dist/wu-status.js.map +1 -1
  50. package/package.json +13 -11
  51. package/packs/agent-runtime/package.json +1 -1
  52. package/packs/sidekick/package.json +1 -1
  53. package/packs/software-delivery/package.json +1 -1
  54. package/templates/core/AGENTS.md.template +67 -3
  55. package/templates/core/LUMENFLOW.md.template +197 -47
  56. package/packs/agent-runtime/agent-heartbeat.ts +0 -163
  57. package/packs/agent-runtime/auto-session-integration.ts +0 -888
  58. package/packs/agent-runtime/capability-factory.ts +0 -104
  59. package/packs/agent-runtime/constants.ts +0 -21
  60. package/packs/agent-runtime/delegation-registry-schema.ts +0 -220
  61. package/packs/agent-runtime/delegation-registry-store.ts +0 -269
  62. package/packs/agent-runtime/delegation-tree.ts +0 -328
  63. package/packs/agent-runtime/index.ts +0 -20
  64. package/packs/agent-runtime/manifest.ts +0 -348
  65. package/packs/agent-runtime/memory-coordination-contract.ts +0 -86
  66. package/packs/agent-runtime/orchestration.ts +0 -2027
  67. package/packs/agent-runtime/pack-registration.ts +0 -110
  68. package/packs/agent-runtime/policy-factory.ts +0 -165
  69. package/packs/agent-runtime/remote-controls/index.ts +0 -7
  70. package/packs/agent-runtime/remote-controls/operations.ts +0 -405
  71. package/packs/agent-runtime/remote-controls/port.ts +0 -48
  72. package/packs/agent-runtime/remote-controls/state-store.ts +0 -258
  73. package/packs/agent-runtime/remote-controls/types.ts +0 -105
  74. package/packs/agent-runtime/session-schema.ts +0 -467
  75. package/packs/agent-runtime/tool-impl/agent-turn-tools.ts +0 -793
  76. package/packs/agent-runtime/tool-impl/index.ts +0 -6
  77. package/packs/agent-runtime/tool-impl/provider-adapters.ts +0 -1245
  78. package/packs/agent-runtime/tool-impl/remote-controls.mock.ts +0 -256
  79. package/packs/agent-runtime/tool-impl/remote-controls.ts +0 -273
  80. package/packs/agent-runtime/tools/index.ts +0 -4
  81. package/packs/agent-runtime/tools/types.ts +0 -47
  82. package/packs/agent-runtime/turn-lifecycle-events.ts +0 -590
  83. package/packs/agent-runtime/types.ts +0 -128
  84. package/packs/agent-runtime/vitest.config.ts +0 -11
  85. package/packs/sidekick/channel-ingress.ts +0 -137
  86. package/packs/sidekick/constants.ts +0 -10
  87. package/packs/sidekick/index.ts +0 -8
  88. package/packs/sidekick/manifest-schema.ts +0 -49
  89. package/packs/sidekick/manifest.ts +0 -512
  90. package/packs/sidekick/pack-registration.ts +0 -110
  91. package/packs/sidekick/policy-factory.ts +0 -38
  92. package/packs/sidekick/sidekick-events.ts +0 -694
  93. package/packs/sidekick/src/adapters/cloud-queue.ts +0 -101
  94. package/packs/sidekick/src/adapters/control-plane-bridge.adapter.ts +0 -386
  95. package/packs/sidekick/src/adapters/filesystem-bridge.adapter.ts +0 -228
  96. package/packs/sidekick/src/domain/channel.types.ts +0 -64
  97. package/packs/sidekick/src/ports/channel-bridge.port.ts +0 -92
  98. package/packs/sidekick/src/routines/commit.ts +0 -74
  99. package/packs/sidekick/tool-impl/channel-tools.ts +0 -577
  100. package/packs/sidekick/tool-impl/channel-transports.ts +0 -75
  101. package/packs/sidekick/tool-impl/index.ts +0 -29
  102. package/packs/sidekick/tool-impl/memory-tools.ts +0 -290
  103. package/packs/sidekick/tool-impl/routine-commit.ts +0 -102
  104. package/packs/sidekick/tool-impl/routine-tools.ts +0 -440
  105. package/packs/sidekick/tool-impl/runtime-context.ts +0 -28
  106. package/packs/sidekick/tool-impl/shared.ts +0 -125
  107. package/packs/sidekick/tool-impl/storage.ts +0 -325
  108. package/packs/sidekick/tool-impl/system-tools.ts +0 -160
  109. package/packs/sidekick/tool-impl/task-tools.ts +0 -506
  110. package/packs/sidekick/tools/channel-tools.ts +0 -53
  111. package/packs/sidekick/tools/index.ts +0 -9
  112. package/packs/sidekick/tools/memory-tools.ts +0 -53
  113. package/packs/sidekick/tools/routine-tools.ts +0 -53
  114. package/packs/sidekick/tools/system-tools.ts +0 -47
  115. package/packs/sidekick/tools/task-tools.ts +0 -61
  116. package/packs/sidekick/tools/types.ts +0 -57
  117. package/packs/sidekick/vitest.config.ts +0 -11
  118. package/packs/software-delivery/constants.ts +0 -10
  119. package/packs/software-delivery/extensions.ts +0 -140
  120. package/packs/software-delivery/gate-policies.ts +0 -134
  121. package/packs/software-delivery/index.ts +0 -8
  122. package/packs/software-delivery/manifest-schema.ts +0 -268
  123. package/packs/software-delivery/manifest.ts +0 -657
  124. package/packs/software-delivery/pack-registration.ts +0 -113
  125. package/packs/software-delivery/src/commands/index.ts +0 -5
  126. package/packs/software-delivery/src/config/delivery-review-contract.ts +0 -256
  127. package/packs/software-delivery/src/config/env-accessors.ts +0 -66
  128. package/packs/software-delivery/src/config/index.ts +0 -8
  129. package/packs/software-delivery/src/config/normalize-config-keys.ts +0 -9
  130. package/packs/software-delivery/src/config/schemas/lumenflow-config-schema-types.ts +0 -460
  131. package/packs/software-delivery/src/config/workspace-reader.ts +0 -375
  132. package/packs/software-delivery/src/constants/backlog-patterns.ts +0 -31
  133. package/packs/software-delivery/src/constants/client-ids.ts +0 -19
  134. package/packs/software-delivery/src/constants/config-contract.ts +0 -7
  135. package/packs/software-delivery/src/constants/docs-layout-presets.ts +0 -50
  136. package/packs/software-delivery/src/constants/duration-constants.ts +0 -20
  137. package/packs/software-delivery/src/constants/gate-constants.ts +0 -32
  138. package/packs/software-delivery/src/constants/index.ts +0 -29
  139. package/packs/software-delivery/src/constants/lock-constants.ts +0 -35
  140. package/packs/software-delivery/src/constants/object-guards.ts +0 -12
  141. package/packs/software-delivery/src/constants/section-headings.ts +0 -107
  142. package/packs/software-delivery/src/constants/wu-cli-constants.ts +0 -500
  143. package/packs/software-delivery/src/constants/wu-domain-constants.ts +0 -466
  144. package/packs/software-delivery/src/constants/wu-git-constants.ts +0 -7
  145. package/packs/software-delivery/src/constants/wu-id-format.ts +0 -327
  146. package/packs/software-delivery/src/constants/wu-paths-constants.ts +0 -384
  147. package/packs/software-delivery/src/constants/wu-statuses.ts +0 -287
  148. package/packs/software-delivery/src/constants/wu-type-helpers.ts +0 -67
  149. package/packs/software-delivery/src/constants/wu-ui-constants.ts +0 -267
  150. package/packs/software-delivery/src/constants/wu-validation-constants.ts +0 -73
  151. package/packs/software-delivery/src/domain/index.ts +0 -5
  152. package/packs/software-delivery/src/domain/orchestration.constants.ts +0 -166
  153. package/packs/software-delivery/src/domain/orchestration.schemas.ts +0 -238
  154. package/packs/software-delivery/src/domain/orchestration.types.ts +0 -176
  155. package/packs/software-delivery/src/methodology/incremental-test.ts +0 -122
  156. package/packs/software-delivery/src/methodology/index.ts +0 -6
  157. package/packs/software-delivery/src/methodology/manual-test-validator.ts +0 -292
  158. package/packs/software-delivery/src/policy/coverage-gate.ts +0 -270
  159. package/packs/software-delivery/src/policy/gates-agent-mode.ts +0 -223
  160. package/packs/software-delivery/src/policy/gates-config-internal.ts +0 -121
  161. package/packs/software-delivery/src/policy/gates-config.ts +0 -300
  162. package/packs/software-delivery/src/policy/gates-coverage.ts +0 -356
  163. package/packs/software-delivery/src/policy/gates-presets.ts +0 -134
  164. package/packs/software-delivery/src/policy/gates-schemas.ts +0 -173
  165. package/packs/software-delivery/src/policy/index.ts +0 -22
  166. package/packs/software-delivery/src/policy/package-manager-resolver.ts +0 -319
  167. package/packs/software-delivery/src/policy/resolve-policy.ts +0 -601
  168. package/packs/software-delivery/src/ports/config.ports.ts +0 -90
  169. package/packs/software-delivery/src/ports/dashboard-renderer.port.ts +0 -125
  170. package/packs/software-delivery/src/ports/index.ts +0 -10
  171. package/packs/software-delivery/src/ports/sync-validator.ports.ts +0 -59
  172. package/packs/software-delivery/src/ports/wu-helpers.ports.ts +0 -168
  173. package/packs/software-delivery/src/ports/wu-state.ports.ts +0 -241
  174. package/packs/software-delivery/src/primitives/index.ts +0 -5
  175. package/packs/software-delivery/src/runtime/index.ts +0 -6
  176. package/packs/software-delivery/src/runtime/work-classifier.ts +0 -561
  177. package/packs/software-delivery/src/sandbox/index.ts +0 -10
  178. package/packs/software-delivery/src/sandbox/sandbox-allowlist.ts +0 -118
  179. package/packs/software-delivery/src/sandbox/sandbox-backend-linux.ts +0 -88
  180. package/packs/software-delivery/src/sandbox/sandbox-backend-macos.ts +0 -154
  181. package/packs/software-delivery/src/sandbox/sandbox-backend-windows.ts +0 -47
  182. package/packs/software-delivery/src/sandbox/sandbox-profile.ts +0 -153
  183. package/packs/software-delivery/src/schemas/index.ts +0 -5
  184. package/packs/software-delivery/src/state/date-utils.ts +0 -158
  185. package/packs/software-delivery/src/state/index.ts +0 -15
  186. package/packs/software-delivery/src/state/state-machine.ts +0 -119
  187. package/packs/software-delivery/src/state/wu-doc-types.ts +0 -51
  188. package/packs/software-delivery/src/state/wu-paths.ts +0 -381
  189. package/packs/software-delivery/src/state/wu-schema.ts +0 -1139
  190. package/packs/software-delivery/src/state/wu-state-schema.ts +0 -255
  191. package/packs/software-delivery/src/state/wu-yaml.ts +0 -338
  192. package/packs/software-delivery/tool-impl/agent-tools.ts +0 -263
  193. package/packs/software-delivery/tool-impl/delegation-tools.ts +0 -66
  194. package/packs/software-delivery/tool-impl/flow-metrics-tools.ts +0 -219
  195. package/packs/software-delivery/tool-impl/git-runner.ts +0 -113
  196. package/packs/software-delivery/tool-impl/git-tools.ts +0 -316
  197. package/packs/software-delivery/tool-impl/index.ts +0 -15
  198. package/packs/software-delivery/tool-impl/initiative-orchestration-tools.ts +0 -720
  199. package/packs/software-delivery/tool-impl/lane-lock.ts +0 -246
  200. package/packs/software-delivery/tool-impl/memory-tools.ts +0 -470
  201. package/packs/software-delivery/tool-impl/pending-runtime-tools.ts +0 -21
  202. package/packs/software-delivery/tool-impl/runtime-cli-adapter.ts +0 -329
  203. package/packs/software-delivery/tool-impl/runtime-native-tools.ts +0 -687
  204. package/packs/software-delivery/tool-impl/worker-loader.ts +0 -52
  205. package/packs/software-delivery/tool-impl/worktree-tools.ts +0 -46
  206. package/packs/software-delivery/tool-impl/wu-lifecycle-tools.ts +0 -807
  207. package/packs/software-delivery/tools/delegation-tools.ts +0 -23
  208. package/packs/software-delivery/tools/git-tools.ts +0 -55
  209. package/packs/software-delivery/tools/index.ts +0 -8
  210. package/packs/software-delivery/tools/lane-lock-tool.ts +0 -37
  211. package/packs/software-delivery/tools/types.ts +0 -71
  212. package/packs/software-delivery/tools/worktree-tools.ts +0 -49
  213. 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 };