@lumenflow/cli 3.19.0 → 3.21.0

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 (36) hide show
  1. package/dist/gates-runners.js +5 -4
  2. package/dist/gates-runners.js.map +1 -1
  3. package/dist/gates-utils.js +71 -0
  4. package/dist/gates-utils.js.map +1 -1
  5. package/dist/init-templates.js +30 -22
  6. package/dist/init-templates.js.map +1 -1
  7. package/dist/wu-prune.js +2 -2
  8. package/dist/wu-prune.js.map +1 -1
  9. package/dist/wu-verify.js +22 -17
  10. package/dist/wu-verify.js.map +1 -1
  11. package/package.json +8 -8
  12. package/packs/agent-runtime/.turbo/turbo-build.log +1 -1
  13. package/packs/agent-runtime/package.json +1 -1
  14. package/packs/sidekick/.turbo/turbo-build.log +1 -1
  15. package/packs/sidekick/README.md +118 -113
  16. package/packs/sidekick/manifest-schema.ts +15 -228
  17. package/packs/sidekick/manifest.ts +107 -7
  18. package/packs/sidekick/manifest.yaml +199 -1
  19. package/packs/sidekick/package.json +4 -1
  20. package/packs/sidekick/policy-factory.ts +38 -0
  21. package/packs/sidekick/tool-impl/channel-tools.ts +99 -0
  22. package/packs/sidekick/tool-impl/memory-tools.ts +86 -1
  23. package/packs/sidekick/tool-impl/routine-tools.ts +156 -2
  24. package/packs/sidekick/tool-impl/storage.ts +6 -5
  25. package/packs/sidekick/tool-impl/task-tools.ts +186 -4
  26. package/packs/software-delivery/.turbo/turbo-build.log +1 -1
  27. package/packs/software-delivery/package.json +1 -1
  28. package/templates/core/.lumenflow/constraints.md.template +68 -3
  29. package/templates/core/LUMENFLOW.md.template +26 -26
  30. package/templates/core/_frameworks/lumenflow/wu-sizing-guide.md.template +3 -5
  31. package/templates/core/ai/onboarding/agent-safety-card.md.template +14 -4
  32. package/templates/core/ai/onboarding/first-wu-mistakes.md.template +96 -0
  33. package/templates/core/ai/onboarding/quick-ref-commands.md.template +50 -39
  34. package/templates/core/ai/onboarding/rapid-prototyping.md +2 -1
  35. package/templates/core/ai/onboarding/starting-prompt.md.template +5 -4
  36. package/templates/core/ai/onboarding/troubleshooting-wu-done.md.template +69 -1
@@ -2,23 +2,18 @@
2
2
  // SPDX-License-Identifier: AGPL-3.0-only
3
3
 
4
4
  import {
5
- TOOL_PERMISSIONS,
6
- TOOL_SCOPE_ACCESS,
7
- TOOL_SCOPE_TYPES,
8
- type PathScope,
9
- type ToolPermission,
10
- } from './tools/types.js';
5
+ DomainPackManifestSchema,
6
+ POLICY_TRIGGERS,
7
+ type DomainPackManifest,
8
+ type DomainPackTool,
9
+ } from '@lumenflow/kernel';
10
+ import type { PathScope, ToolPermission } from './tools/types.js';
11
11
 
12
12
  interface Parser<T> {
13
13
  parse(input: unknown): T;
14
14
  }
15
15
 
16
- export const MANIFEST_POLICY_TRIGGERS = {
17
- ON_TOOL_REQUEST: 'on_tool_request',
18
- ON_CLAIM: 'on_claim',
19
- ON_COMPLETION: 'on_completion',
20
- ON_EVIDENCE_ADDED: 'on_evidence_added',
21
- } as const;
16
+ export const MANIFEST_POLICY_TRIGGERS = POLICY_TRIGGERS;
22
17
 
23
18
  export type ManifestPolicyTrigger =
24
19
  (typeof MANIFEST_POLICY_TRIGGERS)[keyof typeof MANIFEST_POLICY_TRIGGERS];
@@ -26,237 +21,29 @@ export type ManifestPolicyTrigger =
26
21
  export const MANIFEST_POLICY_DECISIONS = {
27
22
  ALLOW: 'allow',
28
23
  DENY: 'deny',
24
+ APPROVAL_REQUIRED: 'approval_required',
29
25
  } as const;
30
26
 
31
27
  export type ManifestPolicyDecision =
32
28
  (typeof MANIFEST_POLICY_DECISIONS)[keyof typeof MANIFEST_POLICY_DECISIONS];
33
29
 
34
- export interface SidekickManifestTool {
35
- name: string;
36
- entry: string;
30
+ export interface SidekickManifestTool extends Omit<
31
+ DomainPackTool,
32
+ 'permission' | 'required_scopes'
33
+ > {
37
34
  permission: ToolPermission;
38
35
  required_scopes: PathScope[];
39
- input_schema?: Record<string, unknown>;
40
- output_schema?: Record<string, unknown>;
41
- internal_only?: boolean;
42
36
  }
43
37
 
44
- export interface SidekickManifestPolicy {
45
- id: string;
46
- trigger: ManifestPolicyTrigger;
47
- decision: ManifestPolicyDecision;
48
- reason?: string;
49
- }
38
+ export type SidekickManifestPolicy = DomainPackManifest['policies'][number];
50
39
 
51
- export interface SidekickPackManifest {
52
- id: string;
53
- version: string;
54
- config_key?: string;
55
- config_schema?: string;
56
- task_types: string[];
40
+ export interface SidekickPackManifest extends Omit<DomainPackManifest, 'tools' | 'policies'> {
57
41
  tools: SidekickManifestTool[];
58
42
  policies: SidekickManifestPolicy[];
59
- evidence_types: string[];
60
- state_aliases: Record<string, string>;
61
- lane_templates: Array<{ id: string }>;
62
- }
63
-
64
- function asRecord(input: unknown, label: string): Record<string, unknown> {
65
- if (!input || typeof input !== 'object' || Array.isArray(input)) {
66
- throw new Error(`${label} must be an object.`);
67
- }
68
- return input as Record<string, unknown>;
69
- }
70
-
71
- function parseNonEmptyString(value: unknown, label: string): string {
72
- if (typeof value !== 'string' || value.trim().length === 0) {
73
- throw new Error(`${label} must be a non-empty string.`);
74
- }
75
- return value;
76
- }
77
-
78
- function parseStringArray(value: unknown, label: string): string[] {
79
- if (!Array.isArray(value)) {
80
- throw new Error(`${label} must be an array.`);
81
- }
82
- return value.map((entry, index) => parseNonEmptyString(entry, `${label}[${index}]`));
83
- }
84
-
85
- function parseJsonSchemaObject(value: unknown, label: string): Record<string, unknown> {
86
- return asRecord(value, label);
87
- }
88
-
89
- function isSemver(value: string): boolean {
90
- let core = value;
91
- const prereleaseIndex = core.indexOf('-');
92
- if (prereleaseIndex >= 0) {
93
- core = core.slice(0, prereleaseIndex);
94
- }
95
- const metadataIndex = core.indexOf('+');
96
- if (metadataIndex >= 0) {
97
- core = core.slice(0, metadataIndex);
98
- }
99
-
100
- const parts = core.split('.');
101
- if (parts.length !== 3) {
102
- return false;
103
- }
104
-
105
- return parts.every(
106
- (part) => part.length > 0 && [...part].every((char) => char >= '0' && char <= '9'),
107
- );
108
- }
109
-
110
- const ALLOWED_POLICY_TRIGGERS = new Set<string>(Object.values(MANIFEST_POLICY_TRIGGERS));
111
- const ALLOWED_POLICY_DECISIONS = new Set<string>(Object.values(MANIFEST_POLICY_DECISIONS));
112
- const ALLOWED_TOOL_PERMISSIONS = new Set<string>(Object.values(TOOL_PERMISSIONS));
113
-
114
- function parsePathScope(input: unknown, label: string): PathScope {
115
- const scope = asRecord(input, label);
116
- const type = parseNonEmptyString(scope.type, `${label}.type`);
117
- const pattern = parseNonEmptyString(scope.pattern, `${label}.pattern`);
118
- const access = parseNonEmptyString(scope.access, `${label}.access`);
119
-
120
- if (type !== TOOL_SCOPE_TYPES.PATH) {
121
- throw new Error(`${label}.type must be "${TOOL_SCOPE_TYPES.PATH}".`);
122
- }
123
- if (access !== TOOL_SCOPE_ACCESS.READ && access !== TOOL_SCOPE_ACCESS.WRITE) {
124
- throw new Error(
125
- `${label}.access must be "${TOOL_SCOPE_ACCESS.READ}" or "${TOOL_SCOPE_ACCESS.WRITE}".`,
126
- );
127
- }
128
-
129
- return {
130
- type: TOOL_SCOPE_TYPES.PATH,
131
- pattern,
132
- access,
133
- };
134
- }
135
-
136
- function parseRequiredScopes(value: unknown, label: string): PathScope[] {
137
- if (!Array.isArray(value) || value.length === 0) {
138
- throw new Error(`${label} must be a non-empty array.`);
139
- }
140
- return value.map((entry, index) => parsePathScope(entry, `${label}[${index}]`));
141
- }
142
-
143
- function parsePolicy(input: unknown, index: number): SidekickManifestPolicy {
144
- const policy = asRecord(input, `policies[${index}]`);
145
- const trigger = parseNonEmptyString(policy.trigger, `policies[${index}].trigger`);
146
- const decision = parseNonEmptyString(policy.decision, `policies[${index}].decision`);
147
-
148
- if (!ALLOWED_POLICY_TRIGGERS.has(trigger)) {
149
- throw new Error(`policies[${index}].trigger is invalid.`);
150
- }
151
- if (!ALLOWED_POLICY_DECISIONS.has(decision)) {
152
- throw new Error(`policies[${index}].decision is invalid.`);
153
- }
154
-
155
- return {
156
- id: parseNonEmptyString(policy.id, `policies[${index}].id`),
157
- trigger: trigger as ManifestPolicyTrigger,
158
- decision: decision as ManifestPolicyDecision,
159
- reason:
160
- policy.reason === undefined
161
- ? undefined
162
- : parseNonEmptyString(policy.reason, `policies[${index}].reason`),
163
- };
164
- }
165
-
166
- function parseTool(input: unknown, index: number): SidekickManifestTool {
167
- const tool = asRecord(input, `tools[${index}]`);
168
- const permission =
169
- tool.permission === undefined
170
- ? TOOL_PERMISSIONS.READ
171
- : parseNonEmptyString(tool.permission, `tools[${index}].permission`);
172
-
173
- if (!ALLOWED_TOOL_PERMISSIONS.has(permission)) {
174
- throw new Error(`tools[${index}].permission is invalid.`);
175
- }
176
-
177
- return {
178
- name: parseNonEmptyString(tool.name, `tools[${index}].name`),
179
- entry: parseNonEmptyString(tool.entry, `tools[${index}].entry`),
180
- permission: permission as ToolPermission,
181
- required_scopes: parseRequiredScopes(tool.required_scopes, `tools[${index}].required_scopes`),
182
- input_schema:
183
- tool.input_schema === undefined
184
- ? undefined
185
- : parseJsonSchemaObject(tool.input_schema, `tools[${index}].input_schema`),
186
- output_schema:
187
- tool.output_schema === undefined
188
- ? undefined
189
- : parseJsonSchemaObject(tool.output_schema, `tools[${index}].output_schema`),
190
- internal_only:
191
- tool.internal_only === undefined
192
- ? undefined
193
- : (() => {
194
- if (typeof tool.internal_only !== 'boolean') {
195
- throw new Error(`tools[${index}].internal_only must be boolean.`);
196
- }
197
- return tool.internal_only;
198
- })(),
199
- };
200
- }
201
-
202
- function parseStateAliases(input: unknown): Record<string, string> {
203
- const aliases = asRecord(input ?? {}, 'state_aliases');
204
- const parsed: Record<string, string> = {};
205
- for (const [key, value] of Object.entries(aliases)) {
206
- parsed[parseNonEmptyString(key, 'state_aliases key')] = parseNonEmptyString(
207
- value,
208
- `state_aliases.${key}`,
209
- );
210
- }
211
- return parsed;
212
43
  }
213
44
 
214
45
  export const SidekickManifestSchema: Parser<SidekickPackManifest> = {
215
46
  parse(input: unknown): SidekickPackManifest {
216
- const manifest = asRecord(input, 'manifest');
217
- const version = parseNonEmptyString(manifest.version, 'version');
218
- if (!isSemver(version)) {
219
- throw new Error('version must be semver.');
220
- }
221
-
222
- const taskTypes = parseStringArray(manifest.task_types, 'task_types');
223
- if (taskTypes.length === 0) {
224
- throw new Error('task_types must include at least one item.');
225
- }
226
-
227
- const toolsValue = manifest.tools ?? [];
228
- if (!Array.isArray(toolsValue)) {
229
- throw new Error('tools must be an array.');
230
- }
231
- const policiesValue = manifest.policies ?? [];
232
- if (!Array.isArray(policiesValue)) {
233
- throw new Error('policies must be an array.');
234
- }
235
- const laneTemplatesValue = manifest.lane_templates ?? [];
236
- if (!Array.isArray(laneTemplatesValue)) {
237
- throw new Error('lane_templates must be an array.');
238
- }
239
-
240
- return {
241
- id: parseNonEmptyString(manifest.id, 'id'),
242
- version,
243
- config_key:
244
- manifest.config_key === undefined
245
- ? undefined
246
- : parseNonEmptyString(manifest.config_key, 'config_key'),
247
- config_schema:
248
- manifest.config_schema === undefined
249
- ? undefined
250
- : parseNonEmptyString(manifest.config_schema, 'config_schema'),
251
- task_types: taskTypes,
252
- tools: toolsValue.map((tool, index) => parseTool(tool, index)),
253
- policies: policiesValue.map((policy, index) => parsePolicy(policy, index)),
254
- evidence_types: parseStringArray(manifest.evidence_types ?? [], 'evidence_types'),
255
- state_aliases: parseStateAliases(manifest.state_aliases),
256
- lane_templates: laneTemplatesValue.map((laneTemplate, index) => {
257
- const entry = asRecord(laneTemplate, `lane_templates[${index}]`);
258
- return { id: parseNonEmptyString(entry.id, `lane_templates[${index}].id`) };
259
- }),
260
- };
47
+ return DomainPackManifestSchema.parse(input) as SidekickPackManifest;
261
48
  },
262
49
  };
@@ -34,26 +34,33 @@ const SIDEKICK_SCOPE_WRITE: PathScope = {
34
34
  };
35
35
 
36
36
  // ---------------------------------------------------------------------------
37
- // 16-tool contract (per strategy: 5 groups)
37
+ // Sidekick tool contract
38
38
  // ---------------------------------------------------------------------------
39
39
 
40
40
  const TOOL_PERMISSIONS_MAP = {
41
- // Task tools (4)
41
+ // Task tools (6)
42
42
  'task:create': TOOL_PERMISSIONS.WRITE,
43
43
  'task:list': TOOL_PERMISSIONS.READ,
44
+ 'task:update': TOOL_PERMISSIONS.WRITE,
45
+ 'task:cancel': TOOL_PERMISSIONS.ADMIN,
44
46
  'task:complete': TOOL_PERMISSIONS.WRITE,
45
47
  'task:schedule': TOOL_PERMISSIONS.WRITE,
46
- // Memory tools (3)
48
+ // Memory tools (4)
47
49
  'memory:store': TOOL_PERMISSIONS.WRITE,
48
50
  'memory:recall': TOOL_PERMISSIONS.READ,
49
- 'memory:forget': TOOL_PERMISSIONS.WRITE,
50
- // Channel tools (3)
51
+ 'memory:update': TOOL_PERMISSIONS.WRITE,
52
+ 'memory:forget': TOOL_PERMISSIONS.ADMIN,
53
+ // Channel tools (5)
51
54
  'channel:configure': TOOL_PERMISSIONS.WRITE,
55
+ 'channel:list': TOOL_PERMISSIONS.READ,
56
+ 'channel:delete': TOOL_PERMISSIONS.ADMIN,
52
57
  'channel:send': TOOL_PERMISSIONS.WRITE,
53
58
  'channel:receive': TOOL_PERMISSIONS.READ,
54
- // Routine tools (3)
59
+ // Routine tools (5)
55
60
  'routine:create': TOOL_PERMISSIONS.WRITE,
56
61
  'routine:list': TOOL_PERMISSIONS.READ,
62
+ 'routine:update': TOOL_PERMISSIONS.WRITE,
63
+ 'routine:delete': TOOL_PERMISSIONS.ADMIN,
57
64
  'routine:run': TOOL_PERMISSIONS.READ, // plan-only, no execution
58
65
  // System tools (3)
59
66
  'sidekick:init': TOOL_PERMISSIONS.WRITE,
@@ -68,20 +75,28 @@ const MEMORY_TOOLS_ENTRY = 'tool-impl/memory-tools.ts';
68
75
  const CHANNEL_TOOLS_ENTRY = 'tool-impl/channel-tools.ts';
69
76
  const ROUTINE_TOOLS_ENTRY = 'tool-impl/routine-tools.ts';
70
77
  const SYSTEM_TOOLS_ENTRY = 'tool-impl/system-tools.ts';
78
+ const POLICY_FACTORY_ENTRY = 'policy-factory.ts#createSidekickPolicyFactory';
71
79
 
72
80
  const TOOL_ENTRIES: Record<SidekickToolName, string> = {
73
81
  'task:create': TASK_TOOLS_ENTRY,
74
82
  'task:list': TASK_TOOLS_ENTRY,
83
+ 'task:update': TASK_TOOLS_ENTRY,
84
+ 'task:cancel': TASK_TOOLS_ENTRY,
75
85
  'task:complete': TASK_TOOLS_ENTRY,
76
86
  'task:schedule': TASK_TOOLS_ENTRY,
77
87
  'memory:store': MEMORY_TOOLS_ENTRY,
78
88
  'memory:recall': MEMORY_TOOLS_ENTRY,
89
+ 'memory:update': MEMORY_TOOLS_ENTRY,
79
90
  'memory:forget': MEMORY_TOOLS_ENTRY,
80
91
  'channel:configure': CHANNEL_TOOLS_ENTRY,
92
+ 'channel:list': CHANNEL_TOOLS_ENTRY,
93
+ 'channel:delete': CHANNEL_TOOLS_ENTRY,
81
94
  'channel:send': CHANNEL_TOOLS_ENTRY,
82
95
  'channel:receive': CHANNEL_TOOLS_ENTRY,
83
96
  'routine:create': ROUTINE_TOOLS_ENTRY,
84
97
  'routine:list': ROUTINE_TOOLS_ENTRY,
98
+ 'routine:update': ROUTINE_TOOLS_ENTRY,
99
+ 'routine:delete': ROUTINE_TOOLS_ENTRY,
85
100
  'routine:run': ROUTINE_TOOLS_ENTRY,
86
101
  'sidekick:init': SYSTEM_TOOLS_ENTRY,
87
102
  'sidekick:status': SYSTEM_TOOLS_ENTRY,
@@ -109,7 +124,7 @@ const TOOL_INPUT_SCHEMAS: Record<SidekickToolName, Record<string, unknown>> = {
109
124
  'task:list': {
110
125
  type: 'object',
111
126
  properties: {
112
- status: { type: 'string', enum: ['pending', 'done'] },
127
+ status: { type: 'string', enum: ['pending', 'done', 'canceled'] },
113
128
  priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] },
114
129
  tags: { type: 'array', items: { type: 'string' } },
115
130
  search: { type: 'string' },
@@ -118,6 +133,30 @@ const TOOL_INPUT_SCHEMAS: Record<SidekickToolName, Record<string, unknown>> = {
118
133
  },
119
134
  additionalProperties: false,
120
135
  },
136
+ 'task:update': {
137
+ type: 'object',
138
+ properties: {
139
+ id: { type: 'string', minLength: 1 },
140
+ title: { type: 'string', minLength: 1 },
141
+ description: { type: 'string' },
142
+ priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] },
143
+ tags: { type: 'array', items: { type: 'string' } },
144
+ due_at: { type: 'string' },
145
+ cron: { type: 'string' },
146
+ dry_run: { type: 'boolean' },
147
+ },
148
+ required: ['id'],
149
+ additionalProperties: false,
150
+ },
151
+ 'task:cancel': {
152
+ type: 'object',
153
+ properties: {
154
+ id: { type: 'string', minLength: 1 },
155
+ dry_run: { type: 'boolean' },
156
+ },
157
+ required: ['id'],
158
+ additionalProperties: false,
159
+ },
121
160
  'task:complete': {
122
161
  type: 'object',
123
162
  properties: {
@@ -169,6 +208,18 @@ const TOOL_INPUT_SCHEMAS: Record<SidekickToolName, Record<string, unknown>> = {
169
208
  required: ['id'],
170
209
  additionalProperties: false,
171
210
  },
211
+ 'memory:update': {
212
+ type: 'object',
213
+ properties: {
214
+ id: { type: 'string', minLength: 1 },
215
+ type: { type: 'string', enum: ['fact', 'preference', 'note', 'snippet'] },
216
+ content: { type: 'string', minLength: 1 },
217
+ tags: { type: 'array', items: { type: 'string' } },
218
+ dry_run: { type: 'boolean' },
219
+ },
220
+ required: ['id'],
221
+ additionalProperties: false,
222
+ },
172
223
  'channel:configure': {
173
224
  type: 'object',
174
225
  properties: {
@@ -179,6 +230,20 @@ const TOOL_INPUT_SCHEMAS: Record<SidekickToolName, Record<string, unknown>> = {
179
230
  required: ['name'],
180
231
  additionalProperties: false,
181
232
  },
233
+ 'channel:list': {
234
+ type: 'object',
235
+ properties: {},
236
+ additionalProperties: false,
237
+ },
238
+ 'channel:delete': {
239
+ type: 'object',
240
+ properties: {
241
+ id: { type: 'string', minLength: 1 },
242
+ dry_run: { type: 'boolean' },
243
+ },
244
+ required: ['id'],
245
+ additionalProperties: false,
246
+ },
182
247
  'channel:send': {
183
248
  type: 'object',
184
249
  properties: {
@@ -236,6 +301,40 @@ const TOOL_INPUT_SCHEMAS: Record<SidekickToolName, Record<string, unknown>> = {
236
301
  },
237
302
  additionalProperties: false,
238
303
  },
304
+ 'routine:update': {
305
+ type: 'object',
306
+ properties: {
307
+ id: { type: 'string', minLength: 1 },
308
+ name: { type: 'string', minLength: 1 },
309
+ steps: {
310
+ type: 'array',
311
+ minItems: 1,
312
+ items: {
313
+ type: 'object',
314
+ properties: {
315
+ tool: { type: 'string', minLength: 1 },
316
+ input: { type: 'object', additionalProperties: true },
317
+ },
318
+ required: ['tool'],
319
+ additionalProperties: false,
320
+ },
321
+ },
322
+ cron: { type: 'string' },
323
+ enabled: { type: 'boolean' },
324
+ dry_run: { type: 'boolean' },
325
+ },
326
+ required: ['id'],
327
+ additionalProperties: false,
328
+ },
329
+ 'routine:delete': {
330
+ type: 'object',
331
+ properties: {
332
+ id: { type: 'string', minLength: 1 },
333
+ dry_run: { type: 'boolean' },
334
+ },
335
+ required: ['id'],
336
+ additionalProperties: false,
337
+ },
239
338
  'routine:run': {
240
339
  type: 'object',
241
340
  properties: {
@@ -310,6 +409,7 @@ const SIDEKICK_MANIFEST_TEMPLATE = {
310
409
  id: SIDEKICK_PACK_ID,
311
410
  version: SIDEKICK_PACK_VERSION,
312
411
  config_key: SIDEKICK_PACK_ID,
412
+ policy_factory: POLICY_FACTORY_ENTRY,
313
413
  task_types: ['sidekick'],
314
414
  tools: SIDEKICK_TOOL_NAMES.map((name) => buildTool(name)),
315
415
  policies: [