create-principles-disciple 1.97.1 → 1.98.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.
- package/console/dist/server/models/ActivationsConsoleModel.js +29 -3
- package/console/dist/server/models/ApprovalsConsoleModel.d.ts +13 -0
- package/console/dist/server/models/ApprovalsConsoleModel.js +94 -3
- package/console/dist/web/assets/app.js +9 -5
- package/console/package.json +1 -1
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +5 -4
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/dreamer-runner.test.js +15 -2
- package/core/dist/runtime-v2/__tests__/dreamer-runner.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js +44 -0
- package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.d.ts +2 -0
- package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.js +149 -0
- package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.js.map +1 -0
- package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store.test.js +72 -2
- package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/activation-dispatcher.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/activation-dispatcher.js +5 -0
- package/core/dist/runtime-v2/activation/activation-dispatcher.js.map +1 -1
- package/core/dist/runtime-v2/activation/activation-types.d.ts +1 -0
- package/core/dist/runtime-v2/activation/activation-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/activation-types.js.map +1 -1
- package/core/dist/runtime-v2/activation/memory-activation-state-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/memory-activation-state-store.js +6 -1
- package/core/dist/runtime-v2/activation/memory-activation-state-store.js.map +1 -1
- package/core/dist/runtime-v2/activation/sqlite-activation-state-store.d.ts +1 -0
- package/core/dist/runtime-v2/activation/sqlite-activation-state-store.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js +64 -10
- package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js.map +1 -1
- package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js +11 -8
- package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js.map +1 -1
- package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts.map +1 -1
- package/core/dist/runtime-v2/activation/writers/rule-host-writer.js +8 -1
- package/core/dist/runtime-v2/activation/writers/rule-host-writer.js.map +1 -1
- package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.d.ts +2 -0
- package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.js +134 -0
- package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.js.map +1 -0
- package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.d.ts +15 -0
- package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
- package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.js +23 -1
- package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.js.map +1 -1
- package/core/dist/runtime-v2/index.d.ts +1 -1
- package/core/dist/runtime-v2/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/index.js +1 -1
- package/core/dist/runtime-v2/index.js.map +1 -1
- package/core/dist/runtime-v2/internalization/__tests__/split-diagnostician-runner-retry.test.js +113 -0
- package/core/dist/runtime-v2/internalization/__tests__/split-diagnostician-runner-retry.test.js.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/dreamer-runner.js +4 -0
- package/core/dist/runtime-v2/internalization/dreamer-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/evaluator-runner.js +3 -1
- package/core/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization/split-diagnostician-runner.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization/split-diagnostician-runner.js +27 -0
- package/core/dist/runtime-v2/internalization/split-diagnostician-runner.js.map +1 -1
- package/core/dist/runtime-v2/internalization-chain-integrity-read-model.d.ts.map +1 -1
- package/core/dist/runtime-v2/internalization-chain-integrity-read-model.js +4 -1
- package/core/dist/runtime-v2/internalization-chain-integrity-read-model.js.map +1 -1
- package/core/dist/runtime-v2/proven-channel-baseline.js +1 -1
- package/core/dist/runtime-v2/proven-channel-baseline.js.map +1 -1
- package/core/dist/runtime-v2/store/sqlite-connection.d.ts.map +1 -1
- package/core/dist/runtime-v2/store/sqlite-connection.js +4 -0
- package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
- package/core/dist/runtime-v2/types/event-types.d.ts +4 -0
- package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/types/event-types.js +5 -0
- package/core/dist/runtime-v2/types/event-types.js.map +1 -1
- package/dist/mvp-config.js +1 -1
- package/dist/mvp-config.js.map +1 -1
- package/package.json +2 -2
- package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
- package/pd-cli/dist/commands/diagnose.js +71 -4
- package/pd-cli/dist/commands/diagnose.js.map +1 -1
- package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
- package/pd-cli/dist/commands/pain-record.js +21 -0
- package/pd-cli/dist/commands/pain-record.js.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.d.ts +26 -0
- package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
- package/pd-cli/dist/commands/runtime-activation.js +307 -3
- package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
- package/pd-cli/dist/config-reader.js +1 -1
- package/pd-cli/dist/config-reader.js.map +1 -1
- package/pd-cli/dist/index.js +22 -1
- package/pd-cli/dist/index.js.map +1 -1
- package/pd-cli/dist/services/pd-config-loader.js +1 -1
- package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
- package/plugin/dist/core/pd-config-loader.js +1 -1
- package/plugin/dist/core/rule-host.d.ts +22 -1
- package/plugin/dist/core/rule-host.js +107 -18
- package/plugin/dist/core/workflow-funnel-loader.js +2 -2
- package/plugin/dist/core/workspace-context.d.ts +4 -0
- package/plugin/dist/core/workspace-context.js +13 -0
- package/plugin/dist/hooks/gate.js +36 -50
- package/plugin/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { SqliteConnection, SqliteActivationStateStore, SqlitePIArtifactStore, } from '@principles/core/runtime-v2';
|
|
1
|
+
import { SqliteConnection, SqliteActivationStateStore, SqlitePIArtifactStore, extractPrincipleId, } from '@principles/core/runtime-v2';
|
|
2
2
|
import * as fs from 'node:fs';
|
|
3
3
|
import * as path from 'node:path';
|
|
4
4
|
function isMissingTableError(err) {
|
|
@@ -6,6 +6,26 @@ function isMissingTableError(err) {
|
|
|
6
6
|
return false;
|
|
7
7
|
return err.message.includes('no such table');
|
|
8
8
|
}
|
|
9
|
+
/**
|
|
10
|
+
* Bug-O L2 fix: adapt PIArtifactRecord (DB row) to PIArtifactSnapshot (activation
|
|
11
|
+
* contract type). The two interfaces have identical fields but different names —
|
|
12
|
+
* we use explicit field copy instead of `as` to comply with rc-2-no-as-bypass
|
|
13
|
+
* and to surface future field drift as a compile error.
|
|
14
|
+
*/
|
|
15
|
+
function toSnapshot(record) {
|
|
16
|
+
return {
|
|
17
|
+
artifactId: record.artifactId,
|
|
18
|
+
artifactKind: record.artifactKind,
|
|
19
|
+
sourceTaskId: record.sourceTaskId,
|
|
20
|
+
sourcePrincipleId: record.sourcePrincipleId,
|
|
21
|
+
sourceRuleId: record.sourceRuleId,
|
|
22
|
+
lineageArtifactIds: record.lineageArtifactIds,
|
|
23
|
+
validationStatus: record.validationStatus,
|
|
24
|
+
contentJson: record.contentJson,
|
|
25
|
+
createdAt: record.createdAt,
|
|
26
|
+
updatedAt: record.updatedAt,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
9
29
|
export class ActivationsConsoleModel {
|
|
10
30
|
workspaceDir;
|
|
11
31
|
constructor(workspaceDir) {
|
|
@@ -30,13 +50,19 @@ export class ActivationsConsoleModel {
|
|
|
30
50
|
}
|
|
31
51
|
throw err;
|
|
32
52
|
}
|
|
33
|
-
// Build artifactId →
|
|
53
|
+
// Build artifactId → principleId map. Bug-O L2 fix: use extractPrincipleId
|
|
54
|
+
// (4-step fallback: column → parsed.principleId → parsed.sourcePrincipleId
|
|
55
|
+
// → parsed.principleDraft.title) instead of only reading the column.
|
|
56
|
+
// Without this, dreamer artifacts whose sourcePrincipleId was stripped
|
|
57
|
+
// (non-core-principle case) would show 'unlinked' even when contentJson
|
|
58
|
+
// carries a resolvable principleId.
|
|
34
59
|
const artifactPrincipleMap = new Map();
|
|
35
60
|
for (const activation of allActivations) {
|
|
36
61
|
if (!artifactPrincipleMap.has(activation.artifactId)) {
|
|
37
62
|
try {
|
|
38
63
|
const artifact = await artifactStore.getArtifactById(activation.artifactId);
|
|
39
|
-
|
|
64
|
+
const principleId = artifact ? extractPrincipleId(toSnapshot(artifact)) : null;
|
|
65
|
+
artifactPrincipleMap.set(activation.artifactId, principleId);
|
|
40
66
|
}
|
|
41
67
|
catch (err) {
|
|
42
68
|
if (isMissingTableError(err)) {
|
|
@@ -38,6 +38,19 @@ export declare class ApprovalsConsoleModel {
|
|
|
38
38
|
isMvpProven: boolean;
|
|
39
39
|
}) | null>;
|
|
40
40
|
approve(approvalId: string, decidedBy: string, note?: string): Promise<ApproveWithActivationResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Bug-O L3b fix: upgrade the ledger principle linked to `artifactId` from
|
|
43
|
+
* 'candidate' to 'active'. Called by {@link approve} after a successful
|
|
44
|
+
* activation. Non-fatal on failure — the activation is already committed;
|
|
45
|
+
* ledger failure is surfaced as a warning string (rc-9).
|
|
46
|
+
*
|
|
47
|
+
* The principleId is resolved via {@link extractPrincipleId}'s 4-step
|
|
48
|
+
* fallback (column → parsed.principleId → parsed.sourcePrincipleId →
|
|
49
|
+
* parsed.principleDraft.title) so dreamer artifacts whose
|
|
50
|
+
* sourcePrincipleId column was stripped by stripFabricatedCorePrincipleIds
|
|
51
|
+
* can still be linked via contentJson.
|
|
52
|
+
*/
|
|
53
|
+
private upgradeLedgerPrinciple;
|
|
41
54
|
/**
|
|
42
55
|
* Edit a pending approval's artifact to a new version (P1 #2 fix).
|
|
43
56
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import { SqliteConnection, SqliteApprovalQueueStore, SqliteActivationStateStore, SqlitePIArtifactStore, ActivationDispatcher, PromptWriter, DeferArchiveWriter, RuleHostWriter, createProductionGateDeps, ApprovalCompletionService, ApprovalQueue, mapConfidenceToLabel, isArtifactRevisionOf, MVP_CHANNELS, } from '@principles/core/runtime-v2';
|
|
3
|
+
import { SqliteConnection, SqliteApprovalQueueStore, SqliteActivationStateStore, SqlitePIArtifactStore, ActivationDispatcher, PromptWriter, DeferArchiveWriter, RuleHostWriter, createProductionGateDeps, ApprovalCompletionService, ApprovalQueue, mapConfidenceToLabel, isArtifactRevisionOf, extractPrincipleId, PrincipleTreeLedgerAdapter, MVP_CHANNELS, } from '@principles/core/runtime-v2';
|
|
4
4
|
import { loadPdConfig, computeFlagsFromLoadResult } from '../config/pd-config-store.js';
|
|
5
5
|
const MVP_PROVEN_CHANNELS = new Set(MVP_CHANNELS);
|
|
6
6
|
const EMPTY_STATS = { pending: 0, approved: 0, rejected: 0, cancelled: 0 };
|
|
@@ -12,6 +12,26 @@ function isMissingTableError(err) {
|
|
|
12
12
|
function isActivationSuccess(activation) {
|
|
13
13
|
return activation.decision === 'activated' || activation.decision === 'already_activated';
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Bug-O L3b fix: adapt a PIArtifactRecord (DB row) to a PIArtifactSnapshot
|
|
17
|
+
* (activation contract type). The two interfaces have identical fields but
|
|
18
|
+
* different names — explicit field copy surfaces future field drift as a
|
|
19
|
+
* compile error and complies with rc-2-no-as-bypass.
|
|
20
|
+
*/
|
|
21
|
+
function toArtifactSnapshot(record) {
|
|
22
|
+
return {
|
|
23
|
+
artifactId: record.artifactId,
|
|
24
|
+
artifactKind: record.artifactKind,
|
|
25
|
+
sourceTaskId: record.sourceTaskId,
|
|
26
|
+
sourcePrincipleId: record.sourcePrincipleId,
|
|
27
|
+
sourceRuleId: record.sourceRuleId,
|
|
28
|
+
lineageArtifactIds: record.lineageArtifactIds,
|
|
29
|
+
validationStatus: record.validationStatus,
|
|
30
|
+
contentJson: record.contentJson,
|
|
31
|
+
createdAt: record.createdAt,
|
|
32
|
+
updatedAt: record.updatedAt,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
15
35
|
function stateDbExists(workspaceDir) {
|
|
16
36
|
return fs.existsSync(path.join(workspaceDir, '.pd', 'state.db'));
|
|
17
37
|
}
|
|
@@ -133,7 +153,75 @@ export class ApprovalsConsoleModel {
|
|
|
133
153
|
warning: 'activation_skipped_feature_flag_disabled: approval is recorded but activation was not dispatched. Enable story_a_approval_completion flag or manually run "pd runtime activation dispatch" to activate.',
|
|
134
154
|
};
|
|
135
155
|
}
|
|
136
|
-
|
|
156
|
+
// Bug-O L3b fix: after a successful activation, upgrade the corresponding
|
|
157
|
+
// ledger principle from 'candidate' to 'active'. The activation is already
|
|
158
|
+
// committed to SQLite; a ledger failure here is non-fatal and surfaced as
|
|
159
|
+
// a warning (rc-9-no-silent-fallback) — the owner is informed that the
|
|
160
|
+
// ledger state may be out of sync and can be repaired separately.
|
|
161
|
+
//
|
|
162
|
+
// CodeRabbit review fix: use approvalResult.record.artifactId (post-approve
|
|
163
|
+
// source of truth) instead of the pre-read `existing.artifactId`. If
|
|
164
|
+
// editApproval() changed the artifact pointer between read and write, the
|
|
165
|
+
// pre-read value would bind the ledger upgrade to the wrong artifact while
|
|
166
|
+
// the returned record points to the new one.
|
|
167
|
+
let ledgerWarning;
|
|
168
|
+
if (isActivationSuccess(activation)) {
|
|
169
|
+
ledgerWarning = await this.upgradeLedgerPrinciple(approvalResult.record.artifactId);
|
|
170
|
+
}
|
|
171
|
+
return { ok: true, record: approvalResult.record, activation, warning: ledgerWarning };
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Bug-O L3b fix: upgrade the ledger principle linked to `artifactId` from
|
|
175
|
+
* 'candidate' to 'active'. Called by {@link approve} after a successful
|
|
176
|
+
* activation. Non-fatal on failure — the activation is already committed;
|
|
177
|
+
* ledger failure is surfaced as a warning string (rc-9).
|
|
178
|
+
*
|
|
179
|
+
* The principleId is resolved via {@link extractPrincipleId}'s 4-step
|
|
180
|
+
* fallback (column → parsed.principleId → parsed.sourcePrincipleId →
|
|
181
|
+
* parsed.principleDraft.title) so dreamer artifacts whose
|
|
182
|
+
* sourcePrincipleId column was stripped by stripFabricatedCorePrincipleIds
|
|
183
|
+
* can still be linked via contentJson.
|
|
184
|
+
*/
|
|
185
|
+
async upgradeLedgerPrinciple(artifactId) {
|
|
186
|
+
const stateDir = path.join(this.workspaceDir, '.state');
|
|
187
|
+
const { connection } = this.createReadContext();
|
|
188
|
+
try {
|
|
189
|
+
const piArtifactStore = new SqlitePIArtifactStore(connection);
|
|
190
|
+
const artifact = await piArtifactStore.getArtifactById(artifactId);
|
|
191
|
+
if (!artifact) {
|
|
192
|
+
// rc-9: surface the reason instead of silently returning.
|
|
193
|
+
return `ledger_activate_skipped: artifact ${artifactId} not found in artifact store`;
|
|
194
|
+
}
|
|
195
|
+
const principleId = extractPrincipleId(toArtifactSnapshot(artifact));
|
|
196
|
+
if (!principleId) {
|
|
197
|
+
// No principleId resolvable from any source — this is a legitimate
|
|
198
|
+
// skip (e.g. rule-only artifact), not an error. Surface it so the
|
|
199
|
+
// owner can verify whether the link was supposed to exist.
|
|
200
|
+
return `ledger_activate_skipped: artifact ${artifactId} has no resolvable principleId`;
|
|
201
|
+
}
|
|
202
|
+
const ledger = new PrincipleTreeLedgerAdapter({ stateDir });
|
|
203
|
+
const result = ledger.activatePrinciple(principleId);
|
|
204
|
+
if (!result.ok) {
|
|
205
|
+
// Reason is already prefixed with `ledger_activate_failed:`.
|
|
206
|
+
return result.reason;
|
|
207
|
+
}
|
|
208
|
+
return undefined;
|
|
209
|
+
}
|
|
210
|
+
catch (err) {
|
|
211
|
+
// CodeRabbit review fix: read-side failures (getArtifactById, missing
|
|
212
|
+
// table, connection errors) must NOT propagate upward and fail the
|
|
213
|
+
// approval flow after activation is already committed. The activation
|
|
214
|
+
// succeeded; ledger upgrade is a non-fatal post-step. Surface the error
|
|
215
|
+
// as a warning so the owner can repair the ledger separately (rc-9).
|
|
216
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
217
|
+
return `ledger_activate_failed: ${message}`;
|
|
218
|
+
}
|
|
219
|
+
finally {
|
|
220
|
+
try {
|
|
221
|
+
connection.close();
|
|
222
|
+
}
|
|
223
|
+
catch { /* best-effort */ }
|
|
224
|
+
}
|
|
137
225
|
}
|
|
138
226
|
/**
|
|
139
227
|
* Edit a pending approval's artifact to a new version (P1 #2 fix).
|
|
@@ -254,7 +342,10 @@ export class ApprovalsConsoleModel {
|
|
|
254
342
|
const dispatcher = new ActivationDispatcher(artifactReadModel, activationStateStore, {
|
|
255
343
|
writers: [
|
|
256
344
|
new PromptWriter(),
|
|
257
|
-
new RuleHostWriter({
|
|
345
|
+
new RuleHostWriter({
|
|
346
|
+
gateDeps: createProductionGateDeps(),
|
|
347
|
+
featureFlagProbe: (flagId) => pdFlags.flags[flagId]?.enabled === true,
|
|
348
|
+
}),
|
|
258
349
|
new DeferArchiveWriter(),
|
|
259
350
|
],
|
|
260
351
|
approvalQueueStore,
|