@principles/pd-cli 1.148.0 → 1.149.1

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 (33) hide show
  1. package/dist/commands/errors-list.d.ts.map +1 -1
  2. package/dist/commands/errors-list.js +9 -10
  3. package/dist/commands/errors-list.js.map +1 -1
  4. package/dist/commands/pain-record.d.ts +6 -0
  5. package/dist/commands/pain-record.d.ts.map +1 -1
  6. package/dist/commands/pain-record.js +78 -29
  7. package/dist/commands/pain-record.js.map +1 -1
  8. package/dist/commands/runtime-init.d.ts +3 -1
  9. package/dist/commands/runtime-init.d.ts.map +1 -1
  10. package/dist/commands/runtime-init.js +7 -47
  11. package/dist/commands/runtime-init.js.map +1 -1
  12. package/dist/commands/runtime-internalization-run-once.d.ts.map +1 -1
  13. package/dist/commands/runtime-internalization-run-once.js +29 -2
  14. package/dist/commands/runtime-internalization-run-once.js.map +1 -1
  15. package/dist/index.js +13 -4
  16. package/dist/index.js.map +1 -1
  17. package/dist/services/rulehost-pipeline-runner.d.ts.map +1 -1
  18. package/dist/services/rulehost-pipeline-runner.js +18 -3
  19. package/dist/services/rulehost-pipeline-runner.js.map +1 -1
  20. package/package.json +1 -1
  21. package/src/commands/errors-list.ts +14 -13
  22. package/src/commands/pain-record.ts +82 -29
  23. package/src/commands/runtime-init.ts +7 -45
  24. package/src/commands/runtime-internalization-run-once.ts +30 -3
  25. package/src/index.ts +13 -4
  26. package/src/services/rulehost-pipeline-runner.ts +18 -2
  27. package/tests/commands/errors-list.test.ts +5 -4
  28. package/tests/commands/pain-record-session-parser.test.ts +25 -1
  29. package/tests/commands/pain-record.test.ts +68 -9
  30. package/tests/commands/runtime-activation.test.ts +1 -1
  31. package/tests/commands/runtime-init-empty-workspace.test.ts +5 -13
  32. package/tests/commands/runtime-init.test.ts +6 -32
  33. package/tests/commands/runtime-internalization-run-once.test.ts +8 -1
@@ -73,10 +73,6 @@ const EXPECTED_TRAJECTORY_TABLES = [
73
73
  'exports_audit', 'evolution_tasks', 'evolution_events',
74
74
  ];
75
75
 
76
- const EXPECTED_WORKFLOW_TABLES = [
77
- 'schema_version', 'subagent_workflows', 'subagent_workflow_events',
78
- ];
79
-
80
76
  const EXPECTED_TRAJECTORY_INDEXES = [
81
77
  'idx_assistant_turns_session_id',
82
78
  'idx_assistant_turns_created_at',
@@ -110,11 +106,11 @@ describe('pd runtime init — empty workspace integration', () => {
110
106
  // ── EMPTY-01: initialize empty workspace ───────────────────────────────────
111
107
 
112
108
  describe('EMPTY-01: initialize empty workspace', () => {
113
- it('returns ok=true with 3 initialized databases', () => {
109
+ it('returns ok=true with 2 initialized databases', () => {
114
110
  const output = buildRuntimeInitOutput(tmpDir, true);
115
111
  expect(output.ok).toBe(true);
116
112
  expect(output.mode).toBe('confirm');
117
- expect(output.databases).toHaveLength(3);
113
+ expect(output.databases).toHaveLength(2);
118
114
  for (const db of output.databases) {
119
115
  expect(db.status).toBe('initialized');
120
116
  }
@@ -150,14 +146,10 @@ describe('pd runtime init — empty workspace integration', () => {
150
146
  }
151
147
  });
152
148
 
153
- it('creates subagent_workflows.db with all expected tables', () => {
149
+ it('no longer creates subagent_workflows.db (legacy workflow store retired in PRI-737)', () => {
154
150
  buildRuntimeInitOutput(tmpDir, true);
155
151
  const wfDbPath = path.join(tmpDir, '.state', 'subagent_workflows.db');
156
- expect(fs.existsSync(wfDbPath)).toBe(true);
157
- const tables = getTableNames(wfDbPath);
158
- for (const expected of EXPECTED_WORKFLOW_TABLES) {
159
- expect(tables).toContain(expected);
160
- }
152
+ expect(fs.existsSync(wfDbPath)).toBe(false);
161
153
  });
162
154
 
163
155
  it('pain_events table has canonical_pain_id and runtime_task_id columns', () => {
@@ -229,7 +221,7 @@ describe('pd runtime init — empty workspace integration', () => {
229
221
  // Second initialization (should be idempotent)
230
222
  const output2 = buildRuntimeInitOutput(tmpDir, true);
231
223
  expect(output2.ok).toBe(true);
232
- expect(output2.databases).toHaveLength(3);
224
+ expect(output2.databases).toHaveLength(2);
233
225
  for (const db of output2.databases) {
234
226
  expect(db.status).toBe('initialized');
235
227
  }
@@ -2,8 +2,8 @@
2
2
  * runtime-init tests — pd runtime init command (unit tests with mocked DB layer).
3
3
  *
4
4
  * Covers:
5
- * - INIT-01: --dry-run (default) reports 3 DBs as 'skipped', no real writes
6
- * - INIT-02: --confirm calls all 3 init functions, output shows 'initialized'
5
+ * - INIT-01: --dry-run (default) reports 2 DBs as 'skipped', no real writes
6
+ * - INIT-02: --confirm calls all init functions, output shows 'initialized'
7
7
  * - INIT-03: --json outputs single parseable JSON object (cli-1)
8
8
  * - INIT-04: --dry-run + --confirm mutually exclusive (cli-4)
9
9
  * - INIT-05: --confirm failure sets exitCode=1 with reason + nextAction (cli-6)
@@ -24,7 +24,6 @@ import * as fs from 'node:fs';
24
24
  const mockState = vi.hoisted(() => {
25
25
  return {
26
26
  initTrajectorySchema: vi.fn(),
27
- initWorkflowSchema: vi.fn(),
28
27
  sqliteConnectionCtor: vi.fn(),
29
28
  sqliteConnectionGetDb: vi.fn(),
30
29
  sqliteConnectionGetWarnings: vi.fn(),
@@ -37,7 +36,6 @@ const mockState = vi.hoisted(() => {
37
36
 
38
37
  vi.mock('principles-disciple', () => ({
39
38
  initTrajectorySchema: mockState.initTrajectorySchema,
40
- initWorkflowSchema: mockState.initWorkflowSchema,
41
39
  }));
42
40
 
43
41
  vi.mock('@principles/core/runtime-v2', async () => {
@@ -87,12 +85,6 @@ function setupDefaultConfirmMocks(): void {
87
85
  warnings: [],
88
86
  });
89
87
 
90
- // initWorkflowSchema mock
91
- mockState.initWorkflowSchema.mockReturnValue({
92
- tables: ['schema_version', 'subagent_workflows', 'subagent_workflow_events'],
93
- warnings: [],
94
- });
95
-
96
88
  // SchemaConformanceReadModel mock
97
89
  mockState.schemaConformanceCtor.mockImplementation(function () {
98
90
  return {
@@ -113,19 +105,18 @@ describe('pd runtime init', () => {
113
105
  // ── INIT-01: dry-run (default) ─────────────────────────────────────────────
114
106
 
115
107
  describe('INIT-01: dry-run (default)', () => {
116
- it('reports 3 DBs as skipped without calling init functions', () => {
108
+ it('reports 2 DBs as skipped without calling init functions', () => {
117
109
  const tmp = mkTmpDir();
118
110
  try {
119
111
  const output = buildRuntimeInitOutput(tmp, false);
120
112
  expect(output.ok).toBe(true);
121
113
  expect(output.mode).toBe('dry-run');
122
- expect(output.databases).toHaveLength(3);
114
+ expect(output.databases).toHaveLength(2);
123
115
  for (const db of output.databases) {
124
116
  expect(db.status).toBe('skipped');
125
117
  }
126
118
  // No init functions should be called in dry-run mode
127
119
  expect(mockState.initTrajectorySchema).not.toHaveBeenCalled();
128
- expect(mockState.initWorkflowSchema).not.toHaveBeenCalled();
129
120
  expect(mockState.sqliteConnectionCtor).not.toHaveBeenCalled();
130
121
  } finally { rmTmpDir(tmp); }
131
122
  });
@@ -136,12 +127,10 @@ describe('pd runtime init', () => {
136
127
  const output = buildRuntimeInitOutput(tmp, false);
137
128
  const stateDb = output.databases.find(d => d.name === 'state.db');
138
129
  const trajDb = output.databases.find(d => d.name === 'trajectory.db');
139
- const wfDb = output.databases.find(d => d.name === 'subagent_workflows.db');
140
130
  expect(stateDb?.tables).toContain('tasks');
141
131
  expect(stateDb?.tables).toContain('runs');
142
132
  expect(trajDb?.tables).toContain('pain_events');
143
133
  expect(trajDb?.tables).toContain('sessions');
144
- expect(wfDb?.tables).toContain('subagent_workflows');
145
134
  } finally { rmTmpDir(tmp); }
146
135
  });
147
136
  });
@@ -149,20 +138,19 @@ describe('pd runtime init', () => {
149
138
  // ── INIT-02: --confirm ─────────────────────────────────────────────────────
150
139
 
151
140
  describe('INIT-02: --confirm', () => {
152
- it('calls all 3 init functions and reports initialized status', () => {
141
+ it('calls all init functions and reports initialized status', () => {
153
142
  const tmp = mkTmpDir();
154
143
  try {
155
144
  const output = buildRuntimeInitOutput(tmp, true);
156
145
  expect(output.ok).toBe(true);
157
146
  expect(output.mode).toBe('confirm');
158
- expect(output.databases).toHaveLength(3);
147
+ expect(output.databases).toHaveLength(2);
159
148
  for (const db of output.databases) {
160
149
  expect(db.status).toBe('initialized');
161
150
  }
162
151
  expect(mockState.sqliteConnectionCtor).toHaveBeenCalledTimes(1);
163
152
  expect(mockState.sqliteConnectionGetDb).toHaveBeenCalledTimes(1);
164
153
  expect(mockState.initTrajectorySchema).toHaveBeenCalledWith(tmp);
165
- expect(mockState.initWorkflowSchema).toHaveBeenCalledWith(tmp);
166
154
  } finally { rmTmpDir(tmp); }
167
155
  });
168
156
 
@@ -256,7 +244,6 @@ describe('pd runtime init', () => {
256
244
  it('does not call any init functions on flag conflict', async () => {
257
245
  await handleRuntimeInit({ dryRun: true, confirm: true, json: true });
258
246
  expect(mockState.initTrajectorySchema).not.toHaveBeenCalled();
259
- expect(mockState.initWorkflowSchema).not.toHaveBeenCalled();
260
247
  expect(mockState.sqliteConnectionCtor).not.toHaveBeenCalled();
261
248
  });
262
249
  });
@@ -305,19 +292,6 @@ describe('pd runtime init', () => {
305
292
  } finally { rmTmpDir(tmp); }
306
293
  });
307
294
 
308
- it('sets exitCode=1 and includes reason when subagent_workflows.db fails', () => {
309
- const tmp = mkTmpDir();
310
- try {
311
- mockState.initWorkflowSchema.mockImplementation(() => {
312
- throw new Error('locked');
313
- });
314
- const output = buildRuntimeInitOutput(tmp, true);
315
- expect(output.ok).toBe(false);
316
- expect(output.reason).toContain('subagent_workflows.db');
317
- expect(output.reason).toContain('locked');
318
- } finally { rmTmpDir(tmp); }
319
- });
320
-
321
295
  it('handler sets process.exitCode=1 on failure with --json', async () => {
322
296
  const tmp = mkTmpDir();
323
297
  try {
@@ -86,6 +86,7 @@ vi.mock('@principles/core/runtime-v2', () => ({
86
86
  ArtificerRunner: vi.fn().mockImplementation(function () {
87
87
  return { run: mockRun };
88
88
  }),
89
+ buildArtificerHostSemanticContext: (registry) => ({ hostKinds: [], tools: registry.hostMappings() }),
89
90
  EvaluatorRunner: vi.fn().mockImplementation(function () {
90
91
  return { run: mockRun };
91
92
  }),
@@ -197,6 +198,10 @@ const { mockCreateEvaluatorRuntimeContext, mockCreateRolloutGovernanceDeps, mock
197
198
  const mockCreateEvaluatorRuntimeContext = vi.fn().mockReturnValue({
198
199
  ok: true,
199
200
  gateDeps: { evaluateInSandbox: vi.fn() },
201
+ // PRI-741: the context resolution also carries the single registry
202
+ // snapshot the parity projection derives from.
203
+ registry: { resolve: vi.fn(), hostMappings: vi.fn().mockReturnValue([{ rawToolName: 'write', canonicalKind: 'write' }]) },
204
+ hostKinds: ['openclaw'],
200
205
  });
201
206
  const mockCreateRolloutGovernanceDeps = vi.fn().mockReturnValue({
202
207
  dispatchActivation: vi.fn(),
@@ -204,7 +209,9 @@ const { mockCreateEvaluatorRuntimeContext, mockCreateRolloutGovernanceDeps, mock
204
209
  });
205
210
  const mockResolveWorkspaceHostToolSemantics = vi.fn().mockReturnValue({
206
211
  ok: true,
207
- registry: { resolve: vi.fn() },
212
+ // PRI-741: the projection reads the host layer via hostMappings() — the
213
+ // mock registry carries it like a real buildToolSemanticRegistry product.
214
+ registry: { resolve: vi.fn(), hostMappings: vi.fn().mockReturnValue([{ rawToolName: 'write', canonicalKind: 'write' }]) },
208
215
  hostKinds: ['openclaw'],
209
216
  });
210
217
  return { mockCreateEvaluatorRuntimeContext, mockCreateRolloutGovernanceDeps, mockResolveWorkspaceHostToolSemantics };