@lumenflow/cli 3.6.6 → 3.6.8

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 (67) hide show
  1. package/dist/init.js +78 -7
  2. package/dist/init.js.map +1 -1
  3. package/dist/initiative-create.js +74 -23
  4. package/dist/initiative-create.js.map +1 -1
  5. package/dist/lane-lock.js +62 -1
  6. package/dist/lane-lock.js.map +1 -1
  7. package/dist/lane-setup.js +102 -28
  8. package/dist/lane-setup.js.map +1 -1
  9. package/dist/lane-status.js +42 -0
  10. package/dist/lane-status.js.map +1 -1
  11. package/dist/lane-validate.js +62 -1
  12. package/dist/lane-validate.js.map +1 -1
  13. package/dist/plan-link.js +25 -2
  14. package/dist/plan-link.js.map +1 -1
  15. package/dist/public-manifest.js +7 -0
  16. package/dist/public-manifest.js.map +1 -1
  17. package/dist/release.js +17 -0
  18. package/dist/release.js.map +1 -1
  19. package/dist/state-doctor-fix.js +12 -11
  20. package/dist/state-doctor-fix.js.map +1 -1
  21. package/dist/state-emit.js +198 -0
  22. package/dist/state-emit.js.map +1 -0
  23. package/dist/wu-claim-state.js +58 -15
  24. package/dist/wu-claim-state.js.map +1 -1
  25. package/dist/wu-claim-worktree.js +3 -3
  26. package/dist/wu-claim-worktree.js.map +1 -1
  27. package/dist/wu-claim.js +19 -1
  28. package/dist/wu-claim.js.map +1 -1
  29. package/dist/wu-create-content.js +2 -4
  30. package/dist/wu-create-content.js.map +1 -1
  31. package/dist/wu-create-validation.js +14 -1
  32. package/dist/wu-create-validation.js.map +1 -1
  33. package/dist/wu-create.js +2 -6
  34. package/dist/wu-create.js.map +1 -1
  35. package/dist/wu-done.js +95 -4
  36. package/dist/wu-done.js.map +1 -1
  37. package/dist/wu-edit-operations.js +36 -5
  38. package/dist/wu-edit-operations.js.map +1 -1
  39. package/dist/wu-recover.js +115 -12
  40. package/dist/wu-recover.js.map +1 -1
  41. package/package.json +9 -8
  42. package/packs/sidekick/.turbo/turbo-build.log +4 -0
  43. package/packs/sidekick/README.md +194 -0
  44. package/packs/sidekick/constants.ts +10 -0
  45. package/packs/sidekick/index.ts +8 -0
  46. package/packs/sidekick/manifest-schema.ts +262 -0
  47. package/packs/sidekick/manifest.ts +333 -0
  48. package/packs/sidekick/manifest.yaml +406 -0
  49. package/packs/sidekick/pack-registration.ts +110 -0
  50. package/packs/sidekick/package.json +55 -0
  51. package/packs/sidekick/tool-impl/channel-tools.ts +226 -0
  52. package/packs/sidekick/tool-impl/index.ts +22 -0
  53. package/packs/sidekick/tool-impl/memory-tools.ts +188 -0
  54. package/packs/sidekick/tool-impl/routine-tools.ts +194 -0
  55. package/packs/sidekick/tool-impl/shared.ts +124 -0
  56. package/packs/sidekick/tool-impl/storage.ts +315 -0
  57. package/packs/sidekick/tool-impl/system-tools.ts +155 -0
  58. package/packs/sidekick/tool-impl/task-tools.ts +278 -0
  59. package/packs/sidekick/tools/channel-tools.ts +53 -0
  60. package/packs/sidekick/tools/index.ts +9 -0
  61. package/packs/sidekick/tools/memory-tools.ts +53 -0
  62. package/packs/sidekick/tools/routine-tools.ts +53 -0
  63. package/packs/sidekick/tools/system-tools.ts +47 -0
  64. package/packs/sidekick/tools/task-tools.ts +61 -0
  65. package/packs/sidekick/tools/types.ts +57 -0
  66. package/packs/sidekick/tsconfig.json +20 -0
  67. package/templates/core/ai/onboarding/starting-prompt.md.template +33 -2
@@ -0,0 +1,262 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ import {
5
+ TOOL_PERMISSIONS,
6
+ TOOL_SCOPE_ACCESS,
7
+ TOOL_SCOPE_TYPES,
8
+ type PathScope,
9
+ type ToolPermission,
10
+ } from './tools/types.js';
11
+
12
+ interface Parser<T> {
13
+ parse(input: unknown): T;
14
+ }
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;
22
+
23
+ export type ManifestPolicyTrigger =
24
+ (typeof MANIFEST_POLICY_TRIGGERS)[keyof typeof MANIFEST_POLICY_TRIGGERS];
25
+
26
+ export const MANIFEST_POLICY_DECISIONS = {
27
+ ALLOW: 'allow',
28
+ DENY: 'deny',
29
+ } as const;
30
+
31
+ export type ManifestPolicyDecision =
32
+ (typeof MANIFEST_POLICY_DECISIONS)[keyof typeof MANIFEST_POLICY_DECISIONS];
33
+
34
+ export interface SidekickManifestTool {
35
+ name: string;
36
+ entry: string;
37
+ permission: ToolPermission;
38
+ required_scopes: PathScope[];
39
+ input_schema?: Record<string, unknown>;
40
+ output_schema?: Record<string, unknown>;
41
+ internal_only?: boolean;
42
+ }
43
+
44
+ export interface SidekickManifestPolicy {
45
+ id: string;
46
+ trigger: ManifestPolicyTrigger;
47
+ decision: ManifestPolicyDecision;
48
+ reason?: string;
49
+ }
50
+
51
+ export interface SidekickPackManifest {
52
+ id: string;
53
+ version: string;
54
+ config_key?: string;
55
+ config_schema?: string;
56
+ task_types: string[];
57
+ tools: SidekickManifestTool[];
58
+ 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
+ }
213
+
214
+ export const SidekickManifestSchema: Parser<SidekickPackManifest> = {
215
+ 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
+ };
261
+ },
262
+ };
@@ -0,0 +1,333 @@
1
+ // Copyright (c) 2026 Hellmai Ltd
2
+ // SPDX-License-Identifier: AGPL-3.0-only
3
+
4
+ import { SIDEKICK_PACK_ID, SIDEKICK_PACK_VERSION, SIDEKICK_POLICY_ID_PREFIX } from './constants.js';
5
+ import {
6
+ MANIFEST_POLICY_DECISIONS,
7
+ MANIFEST_POLICY_TRIGGERS,
8
+ SidekickManifestSchema,
9
+ type SidekickManifestTool,
10
+ type SidekickPackManifest,
11
+ } from './manifest-schema.js';
12
+ import {
13
+ TOOL_PERMISSIONS,
14
+ TOOL_SCOPE_ACCESS,
15
+ TOOL_SCOPE_TYPES,
16
+ type PathScope,
17
+ type ToolPermission,
18
+ } from './tools/types.js';
19
+
20
+ // ---------------------------------------------------------------------------
21
+ // Scope constants
22
+ // ---------------------------------------------------------------------------
23
+
24
+ const SIDEKICK_SCOPE_READ: PathScope = {
25
+ type: TOOL_SCOPE_TYPES.PATH,
26
+ pattern: '.sidekick/**',
27
+ access: TOOL_SCOPE_ACCESS.READ,
28
+ };
29
+
30
+ const SIDEKICK_SCOPE_WRITE: PathScope = {
31
+ type: TOOL_SCOPE_TYPES.PATH,
32
+ pattern: '.sidekick/**',
33
+ access: TOOL_SCOPE_ACCESS.WRITE,
34
+ };
35
+
36
+ // ---------------------------------------------------------------------------
37
+ // 16-tool contract (per strategy: 5 groups)
38
+ // ---------------------------------------------------------------------------
39
+
40
+ const TOOL_PERMISSIONS_MAP = {
41
+ // Task tools (4)
42
+ 'task:create': TOOL_PERMISSIONS.WRITE,
43
+ 'task:list': TOOL_PERMISSIONS.READ,
44
+ 'task:complete': TOOL_PERMISSIONS.WRITE,
45
+ 'task:schedule': TOOL_PERMISSIONS.WRITE,
46
+ // Memory tools (3)
47
+ 'memory:store': TOOL_PERMISSIONS.WRITE,
48
+ 'memory:recall': TOOL_PERMISSIONS.READ,
49
+ 'memory:forget': TOOL_PERMISSIONS.WRITE,
50
+ // Channel tools (3)
51
+ 'channel:configure': TOOL_PERMISSIONS.WRITE,
52
+ 'channel:send': TOOL_PERMISSIONS.WRITE,
53
+ 'channel:receive': TOOL_PERMISSIONS.READ,
54
+ // Routine tools (3)
55
+ 'routine:create': TOOL_PERMISSIONS.WRITE,
56
+ 'routine:list': TOOL_PERMISSIONS.READ,
57
+ 'routine:run': TOOL_PERMISSIONS.READ, // plan-only, no execution
58
+ // System tools (3)
59
+ 'sidekick:init': TOOL_PERMISSIONS.WRITE,
60
+ 'sidekick:status': TOOL_PERMISSIONS.READ,
61
+ 'sidekick:export': TOOL_PERMISSIONS.READ, // returns data, no file write
62
+ } as const satisfies Record<string, ToolPermission>;
63
+
64
+ type SidekickToolName = keyof typeof TOOL_PERMISSIONS_MAP;
65
+
66
+ const TASK_TOOLS_ENTRY = 'tool-impl/task-tools.ts';
67
+ const MEMORY_TOOLS_ENTRY = 'tool-impl/memory-tools.ts';
68
+ const CHANNEL_TOOLS_ENTRY = 'tool-impl/channel-tools.ts';
69
+ const ROUTINE_TOOLS_ENTRY = 'tool-impl/routine-tools.ts';
70
+ const SYSTEM_TOOLS_ENTRY = 'tool-impl/system-tools.ts';
71
+
72
+ const TOOL_ENTRIES: Record<SidekickToolName, string> = {
73
+ 'task:create': TASK_TOOLS_ENTRY,
74
+ 'task:list': TASK_TOOLS_ENTRY,
75
+ 'task:complete': TASK_TOOLS_ENTRY,
76
+ 'task:schedule': TASK_TOOLS_ENTRY,
77
+ 'memory:store': MEMORY_TOOLS_ENTRY,
78
+ 'memory:recall': MEMORY_TOOLS_ENTRY,
79
+ 'memory:forget': MEMORY_TOOLS_ENTRY,
80
+ 'channel:configure': CHANNEL_TOOLS_ENTRY,
81
+ 'channel:send': CHANNEL_TOOLS_ENTRY,
82
+ 'channel:receive': CHANNEL_TOOLS_ENTRY,
83
+ 'routine:create': ROUTINE_TOOLS_ENTRY,
84
+ 'routine:list': ROUTINE_TOOLS_ENTRY,
85
+ 'routine:run': ROUTINE_TOOLS_ENTRY,
86
+ 'sidekick:init': SYSTEM_TOOLS_ENTRY,
87
+ 'sidekick:status': SYSTEM_TOOLS_ENTRY,
88
+ 'sidekick:export': SYSTEM_TOOLS_ENTRY,
89
+ };
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // Input schemas (JSON Schema objects)
93
+ // ---------------------------------------------------------------------------
94
+
95
+ const TOOL_INPUT_SCHEMAS: Record<SidekickToolName, Record<string, unknown>> = {
96
+ 'task:create': {
97
+ type: 'object',
98
+ properties: {
99
+ title: { type: 'string', minLength: 1 },
100
+ description: { type: 'string' },
101
+ priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] },
102
+ due_at: { type: 'string' },
103
+ tags: { type: 'array', items: { type: 'string' } },
104
+ dry_run: { type: 'boolean' },
105
+ },
106
+ required: ['title'],
107
+ additionalProperties: false,
108
+ },
109
+ 'task:list': {
110
+ type: 'object',
111
+ properties: {
112
+ status: { type: 'string', enum: ['pending', 'done'] },
113
+ priority: { type: 'string', enum: ['P0', 'P1', 'P2', 'P3'] },
114
+ tags: { type: 'array', items: { type: 'string' } },
115
+ search: { type: 'string' },
116
+ due_before: { type: 'string' },
117
+ limit: { type: 'integer', minimum: 1 },
118
+ },
119
+ additionalProperties: false,
120
+ },
121
+ 'task:complete': {
122
+ type: 'object',
123
+ properties: {
124
+ id: { type: 'string', minLength: 1 },
125
+ note: { type: 'string' },
126
+ dry_run: { type: 'boolean' },
127
+ },
128
+ required: ['id'],
129
+ additionalProperties: false,
130
+ },
131
+ 'task:schedule': {
132
+ type: 'object',
133
+ properties: {
134
+ id: { type: 'string', minLength: 1 },
135
+ due_at: { type: 'string' },
136
+ cron: { type: 'string' },
137
+ dry_run: { type: 'boolean' },
138
+ },
139
+ required: ['id'],
140
+ additionalProperties: false,
141
+ },
142
+ 'memory:store': {
143
+ type: 'object',
144
+ properties: {
145
+ type: { type: 'string', enum: ['fact', 'preference', 'note', 'snippet'] },
146
+ content: { type: 'string', minLength: 1 },
147
+ tags: { type: 'array', items: { type: 'string' } },
148
+ dry_run: { type: 'boolean' },
149
+ },
150
+ required: ['type', 'content'],
151
+ additionalProperties: false,
152
+ },
153
+ 'memory:recall': {
154
+ type: 'object',
155
+ properties: {
156
+ query: { type: 'string' },
157
+ type: { type: 'string', enum: ['fact', 'preference', 'note', 'snippet'] },
158
+ tags: { type: 'array', items: { type: 'string' } },
159
+ limit: { type: 'integer', minimum: 1 },
160
+ },
161
+ additionalProperties: false,
162
+ },
163
+ 'memory:forget': {
164
+ type: 'object',
165
+ properties: {
166
+ id: { type: 'string', minLength: 1 },
167
+ dry_run: { type: 'boolean' },
168
+ },
169
+ required: ['id'],
170
+ additionalProperties: false,
171
+ },
172
+ 'channel:configure': {
173
+ type: 'object',
174
+ properties: {
175
+ name: { type: 'string', minLength: 1 },
176
+ type: { type: 'string', enum: ['terminal'] },
177
+ dry_run: { type: 'boolean' },
178
+ },
179
+ required: ['name'],
180
+ additionalProperties: false,
181
+ },
182
+ 'channel:send': {
183
+ type: 'object',
184
+ properties: {
185
+ channel: { type: 'string' },
186
+ content: { type: 'string', minLength: 1 },
187
+ sender: { type: 'string' },
188
+ dry_run: { type: 'boolean' },
189
+ },
190
+ required: ['content'],
191
+ additionalProperties: false,
192
+ },
193
+ 'channel:receive': {
194
+ type: 'object',
195
+ properties: {
196
+ channel: { type: 'string' },
197
+ limit: { type: 'integer', minimum: 1 },
198
+ since: { type: 'string' },
199
+ },
200
+ additionalProperties: false,
201
+ },
202
+ 'routine:create': {
203
+ type: 'object',
204
+ properties: {
205
+ name: { type: 'string', minLength: 1 },
206
+ steps: {
207
+ type: 'array',
208
+ minItems: 1,
209
+ items: {
210
+ type: 'object',
211
+ properties: {
212
+ tool: { type: 'string', minLength: 1 },
213
+ input: { type: 'object', additionalProperties: true },
214
+ },
215
+ required: ['tool'],
216
+ additionalProperties: false,
217
+ },
218
+ },
219
+ cron: { type: 'string' },
220
+ enabled: { type: 'boolean' },
221
+ dry_run: { type: 'boolean' },
222
+ },
223
+ required: ['name', 'steps'],
224
+ additionalProperties: false,
225
+ },
226
+ 'routine:list': {
227
+ type: 'object',
228
+ properties: {
229
+ enabled_only: { type: 'boolean' },
230
+ limit: { type: 'integer', minimum: 1 },
231
+ },
232
+ additionalProperties: false,
233
+ },
234
+ 'routine:run': {
235
+ type: 'object',
236
+ properties: {
237
+ id: { type: 'string', minLength: 1 },
238
+ },
239
+ required: ['id'],
240
+ additionalProperties: false,
241
+ },
242
+ 'sidekick:init': {
243
+ type: 'object',
244
+ properties: {},
245
+ additionalProperties: false,
246
+ },
247
+ 'sidekick:status': {
248
+ type: 'object',
249
+ properties: {},
250
+ additionalProperties: false,
251
+ },
252
+ 'sidekick:export': {
253
+ type: 'object',
254
+ properties: {
255
+ include_audit: { type: 'boolean' },
256
+ },
257
+ additionalProperties: false,
258
+ },
259
+ };
260
+
261
+ // ---------------------------------------------------------------------------
262
+ // Generic output schema
263
+ // ---------------------------------------------------------------------------
264
+
265
+ const GENERIC_OUTPUT_SCHEMA: Record<string, unknown> = {
266
+ type: 'object',
267
+ properties: {
268
+ success: { type: 'boolean' },
269
+ data: { type: 'object', additionalProperties: true },
270
+ error: { type: 'object', additionalProperties: true },
271
+ },
272
+ additionalProperties: true,
273
+ };
274
+
275
+ // ---------------------------------------------------------------------------
276
+ // Builder helpers
277
+ // ---------------------------------------------------------------------------
278
+
279
+ function resolveRequiredScopes(permission: ToolPermission): PathScope[] {
280
+ if (permission === TOOL_PERMISSIONS.READ) {
281
+ return [SIDEKICK_SCOPE_READ];
282
+ }
283
+ return [SIDEKICK_SCOPE_READ, SIDEKICK_SCOPE_WRITE];
284
+ }
285
+
286
+ function buildTool(name: SidekickToolName): SidekickManifestTool {
287
+ const permission = TOOL_PERMISSIONS_MAP[name];
288
+ return {
289
+ name,
290
+ entry: TOOL_ENTRIES[name],
291
+ permission,
292
+ required_scopes: resolveRequiredScopes(permission),
293
+ input_schema: TOOL_INPUT_SCHEMAS[name],
294
+ output_schema: GENERIC_OUTPUT_SCHEMA,
295
+ };
296
+ }
297
+
298
+ // ---------------------------------------------------------------------------
299
+ // Exported manifest
300
+ // ---------------------------------------------------------------------------
301
+
302
+ export const SIDEKICK_TOOL_NAMES = Object.keys(TOOL_PERMISSIONS_MAP) as SidekickToolName[];
303
+
304
+ const SIDEKICK_MANIFEST_TEMPLATE = {
305
+ id: SIDEKICK_PACK_ID,
306
+ version: SIDEKICK_PACK_VERSION,
307
+ config_key: SIDEKICK_PACK_ID,
308
+ task_types: ['sidekick'],
309
+ tools: SIDEKICK_TOOL_NAMES.map((name) => buildTool(name)),
310
+ policies: [
311
+ {
312
+ id: `${SIDEKICK_POLICY_ID_PREFIX}.default`,
313
+ trigger: MANIFEST_POLICY_TRIGGERS.ON_TOOL_REQUEST,
314
+ decision: MANIFEST_POLICY_DECISIONS.ALLOW,
315
+ reason: 'Default sidekick policy permits declared tools within scoped access.',
316
+ },
317
+ ],
318
+ evidence_types: ['sidekick.audited.tool-call'],
319
+ state_aliases: {},
320
+ lane_templates: [],
321
+ };
322
+
323
+ export const SIDEKICK_MANIFEST: SidekickPackManifest = SidekickManifestSchema.parse(
324
+ SIDEKICK_MANIFEST_TEMPLATE,
325
+ );
326
+
327
+ export function getSidekickManifestToolByName(name: string): SidekickManifestTool | undefined {
328
+ return SIDEKICK_MANIFEST.tools.find((tool) => tool.name === name);
329
+ }
330
+
331
+ export function getSidekickToolCount(): number {
332
+ return SIDEKICK_MANIFEST.tools.length;
333
+ }