create-principles-disciple 1.97.0 → 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.
Files changed (99) hide show
  1. package/console/dist/server/models/ActivationsConsoleModel.js +29 -3
  2. package/console/dist/server/models/ApprovalsConsoleModel.d.ts +13 -0
  3. package/console/dist/server/models/ApprovalsConsoleModel.js +94 -3
  4. package/console/dist/web/assets/app.js +9 -5
  5. package/console/package.json +3 -3
  6. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +5 -4
  7. package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  8. package/core/dist/runtime-v2/__tests__/dreamer-runner.test.js +15 -2
  9. package/core/dist/runtime-v2/__tests__/dreamer-runner.test.js.map +1 -1
  10. package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js +44 -0
  11. package/core/dist/runtime-v2/__tests__/evaluator-runner-vslice-v2.test.js.map +1 -1
  12. package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.d.ts +2 -0
  13. package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.d.ts.map +1 -0
  14. package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.js +149 -0
  15. package/core/dist/runtime-v2/activation/__tests__/activation-re-dispatch.test.js.map +1 -0
  16. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store.test.js +72 -2
  17. package/core/dist/runtime-v2/activation/__tests__/sqlite-activation-state-store.test.js.map +1 -1
  18. package/core/dist/runtime-v2/activation/activation-dispatcher.d.ts.map +1 -1
  19. package/core/dist/runtime-v2/activation/activation-dispatcher.js +5 -0
  20. package/core/dist/runtime-v2/activation/activation-dispatcher.js.map +1 -1
  21. package/core/dist/runtime-v2/activation/activation-types.d.ts +1 -0
  22. package/core/dist/runtime-v2/activation/activation-types.d.ts.map +1 -1
  23. package/core/dist/runtime-v2/activation/activation-types.js.map +1 -1
  24. package/core/dist/runtime-v2/activation/memory-activation-state-store.d.ts.map +1 -1
  25. package/core/dist/runtime-v2/activation/memory-activation-state-store.js +6 -1
  26. package/core/dist/runtime-v2/activation/memory-activation-state-store.js.map +1 -1
  27. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.d.ts +1 -0
  28. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.d.ts.map +1 -1
  29. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js +64 -10
  30. package/core/dist/runtime-v2/activation/sqlite-activation-state-store.js.map +1 -1
  31. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js +11 -8
  32. package/core/dist/runtime-v2/activation/writers/__tests__/rule-host-writer.test.js.map +1 -1
  33. package/core/dist/runtime-v2/activation/writers/rule-host-writer.d.ts.map +1 -1
  34. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js +8 -1
  35. package/core/dist/runtime-v2/activation/writers/rule-host-writer.js.map +1 -1
  36. package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.d.ts +2 -0
  37. package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.d.ts.map +1 -0
  38. package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.js +134 -0
  39. package/core/dist/runtime-v2/adapter/__tests__/principle-tree-ledger-adapter.test.js.map +1 -0
  40. package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.d.ts +15 -0
  41. package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.d.ts.map +1 -1
  42. package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.js +23 -1
  43. package/core/dist/runtime-v2/adapter/principle-tree-ledger-adapter.js.map +1 -1
  44. package/core/dist/runtime-v2/index.d.ts +1 -1
  45. package/core/dist/runtime-v2/index.d.ts.map +1 -1
  46. package/core/dist/runtime-v2/index.js +1 -1
  47. package/core/dist/runtime-v2/index.js.map +1 -1
  48. package/core/dist/runtime-v2/internalization/__tests__/split-diagnostician-runner-retry.test.js +113 -0
  49. package/core/dist/runtime-v2/internalization/__tests__/split-diagnostician-runner-retry.test.js.map +1 -1
  50. package/core/dist/runtime-v2/internalization/dreamer-runner.d.ts.map +1 -1
  51. package/core/dist/runtime-v2/internalization/dreamer-runner.js +4 -0
  52. package/core/dist/runtime-v2/internalization/dreamer-runner.js.map +1 -1
  53. package/core/dist/runtime-v2/internalization/evaluator-runner.d.ts.map +1 -1
  54. package/core/dist/runtime-v2/internalization/evaluator-runner.js +3 -1
  55. package/core/dist/runtime-v2/internalization/evaluator-runner.js.map +1 -1
  56. package/core/dist/runtime-v2/internalization/split-diagnostician-runner.d.ts.map +1 -1
  57. package/core/dist/runtime-v2/internalization/split-diagnostician-runner.js +27 -0
  58. package/core/dist/runtime-v2/internalization/split-diagnostician-runner.js.map +1 -1
  59. package/core/dist/runtime-v2/internalization-chain-integrity-read-model.d.ts.map +1 -1
  60. package/core/dist/runtime-v2/internalization-chain-integrity-read-model.js +4 -1
  61. package/core/dist/runtime-v2/internalization-chain-integrity-read-model.js.map +1 -1
  62. package/core/dist/runtime-v2/proven-channel-baseline.js +1 -1
  63. package/core/dist/runtime-v2/proven-channel-baseline.js.map +1 -1
  64. package/core/dist/runtime-v2/store/sqlite-connection.d.ts.map +1 -1
  65. package/core/dist/runtime-v2/store/sqlite-connection.js +4 -0
  66. package/core/dist/runtime-v2/store/sqlite-connection.js.map +1 -1
  67. package/core/dist/runtime-v2/types/event-types.d.ts +4 -0
  68. package/core/dist/runtime-v2/types/event-types.d.ts.map +1 -1
  69. package/core/dist/runtime-v2/types/event-types.js +5 -0
  70. package/core/dist/runtime-v2/types/event-types.js.map +1 -1
  71. package/core/package.json +1 -1
  72. package/dist/mvp-config.js +1 -1
  73. package/dist/mvp-config.js.map +1 -1
  74. package/package.json +3 -3
  75. package/pd-cli/dist/commands/diagnose.d.ts.map +1 -1
  76. package/pd-cli/dist/commands/diagnose.js +71 -4
  77. package/pd-cli/dist/commands/diagnose.js.map +1 -1
  78. package/pd-cli/dist/commands/pain-record.d.ts.map +1 -1
  79. package/pd-cli/dist/commands/pain-record.js +21 -0
  80. package/pd-cli/dist/commands/pain-record.js.map +1 -1
  81. package/pd-cli/dist/commands/runtime-activation.d.ts +26 -0
  82. package/pd-cli/dist/commands/runtime-activation.d.ts.map +1 -1
  83. package/pd-cli/dist/commands/runtime-activation.js +307 -3
  84. package/pd-cli/dist/commands/runtime-activation.js.map +1 -1
  85. package/pd-cli/dist/config-reader.js +1 -1
  86. package/pd-cli/dist/config-reader.js.map +1 -1
  87. package/pd-cli/dist/index.js +22 -1
  88. package/pd-cli/dist/index.js.map +1 -1
  89. package/pd-cli/dist/services/pd-config-loader.js +1 -1
  90. package/pd-cli/dist/services/pd-config-loader.js.map +1 -1
  91. package/pd-cli/package.json +1 -1
  92. package/plugin/dist/core/pd-config-loader.js +1 -1
  93. package/plugin/dist/core/rule-host.d.ts +22 -1
  94. package/plugin/dist/core/rule-host.js +107 -18
  95. package/plugin/dist/core/workflow-funnel-loader.js +2 -2
  96. package/plugin/dist/core/workspace-context.d.ts +4 -0
  97. package/plugin/dist/core/workspace-context.js +13 -0
  98. package/plugin/dist/hooks/gate.js +36 -50
  99. package/plugin/package.json +2 -2
@@ -8,11 +8,9 @@
8
8
  * 1. Early Return: Skip if not write/bash/agent tool or no workspace
9
9
  * 2. Rule Host: Dynamic principle-based evaluation (sole gate)
10
10
  */
11
- import { normalizePath } from '../utils/io.js';
12
11
  import { WorkspaceContext } from '../core/workspace-context.js';
13
12
  import { recordGateBlockAndReturn } from './gate-block-helper.js';
14
- import { RuleHost } from '../core/rule-host.js';
15
- import { validateCorrectionProposal, validateProposedPathBounds, computeFeatureFlagsFromConfig, UNAVAILABLE_RULE_CONTEXT } from '@principles/core/runtime-v2';
13
+ import { buildRuleHostAction, validateCorrectionProposal, validateProposedPathBounds, computeFeatureFlagsFromConfig, UNAVAILABLE_RULE_CONTEXT } from '@principles/core/runtime-v2';
16
14
  import { AGENT_TOOLS, BASH_TOOLS_SET, WRITE_TOOLS } from '../constants/tools.js';
17
15
  import { getSession, hasRecentThinking } from '../core/session-tracker.js';
18
16
  import { getEvolutionEngine } from '../core/evolution-engine.js';
@@ -30,41 +28,27 @@ export function handleBeforeToolCall(event, ctx) {
30
28
  return;
31
29
  }
32
30
  const wctx = WorkspaceContext.fromHookContext(ctx);
33
- // 2. Resolve the target file path
34
- let filePath = event.params?.file_path || event.params?.path || event.params?.file || event.params?.target;
35
- // Heuristic for bash mutation detection
36
- if (isBash && !filePath) {
37
- const command = String(event.params?.command || event.params?.args || '');
38
- const mutationMatch = /(?:>|>>|sed\s+-i|rm|mv|mkdir|touch|cp)\s+(?:-[a-zA-Z]+\s+)*([^\s;&|<>]+)/.exec(command);
39
- if (mutationMatch) {
40
- filePath = mutationMatch[1];
41
- }
42
- else {
43
- // Bash command without a clear file target — let it through to Rule Host
44
- filePath = command;
45
- }
46
- }
47
- // Write tools without a file path must still go through RuleHost evaluation.
48
- // Use a synthetic path so RuleHost can evaluate and potentially block.
49
- if (!filePath && isWriteTool) {
50
- filePath = `<tool:${event.toolName}>`;
51
- }
52
- if (typeof filePath !== 'string')
31
+ // 2. Use the same action builder as Golden Trace replay. This is the single
32
+ // path extraction + normalization contract for production and evaluation.
33
+ const action = buildRuleHostAction(event.toolName, event.params ?? {}, ctx.workspaceDir, {
34
+ isBashTool: isBash,
35
+ isWriteTool,
36
+ });
37
+ const relPath = action.normalizedPath;
38
+ // buildRuleHostAction returns null when no path can be extracted (e.g. bash
39
+ // command with no file target and no clear mutation operator). Mirror the
40
+ // legacy guard: no path → no gate evaluation, let the tool through.
41
+ if (relPath === null)
53
42
  return;
54
- const relPath = normalizePath(filePath, ctx.workspaceDir);
55
43
  // 3. Rule Host Evaluation — sole gate
56
44
  try {
57
- const ruleHost = new RuleHost(wctx.stateDir, logger, { workspaceDir: ctx.workspaceDir });
45
+ const ruleHost = wctx.getRuleHost(logger);
58
46
  // PRI-483 Phase 4: assemble RuleContextV2 when `rulecode_context_v2` flag is ON.
59
47
  // flag OFF → undefined (v1 zero-change, no trajectory access).
60
48
  // flag ON → RuleContextV2 (available or unavailable). Never throws (ERR-024).
61
49
  const ruleContext = _buildRuleContextIfEnabled(wctx, relPath, ctx.sessionId, logger);
62
50
  const hostInput = {
63
- action: {
64
- toolName: event.toolName,
65
- normalizedPath: relPath,
66
- paramsSummary: _extractParamsSummary(event.params ?? {}),
67
- },
51
+ action,
68
52
  workspace: {
69
53
  isRiskPath: false, // Rule Host determines risk dynamically
70
54
  // DEPRECATED (PRI-286): planStatus/hasPlanFile are legacy compatibility fields.
@@ -88,7 +72,27 @@ export function handleBeforeToolCall(event, ctx) {
88
72
  },
89
73
  context: ruleContext,
90
74
  };
91
- const hostResult = ruleHost.evaluate(hostInput);
75
+ const report = typeof ruleHost.evaluateDetailed === 'function'
76
+ ? ruleHost.evaluateDetailed(hostInput)
77
+ : { liveDecision: ruleHost.evaluate(hostInput), shadowDecisions: [] };
78
+ const hostResult = report.liveDecision;
79
+ for (const shadowDecision of report.shadowDecisions) {
80
+ try {
81
+ const eventLog = EventLogService.get(wctx.stateDir, logger);
82
+ eventLog.recordRuleHostEvaluated({
83
+ toolName: event.toolName,
84
+ filePath: relPath,
85
+ matched: shadowDecision.matched,
86
+ decision: shadowDecision.decision,
87
+ ruleId: shadowDecision.ruleId,
88
+ activationId: shadowDecision.activationId,
89
+ activationMode: 'shadow',
90
+ });
91
+ }
92
+ catch (evErr) {
93
+ logger?.warn?.(`[PD_GATE] Failed to record shadow rulehost_evaluated: ${String(evErr)}`);
94
+ }
95
+ }
92
96
  // Always emit rulehost_evaluated
93
97
  try {
94
98
  const eventLog = EventLogService.get(wctx.stateDir, logger);
@@ -98,6 +102,7 @@ export function handleBeforeToolCall(event, ctx) {
98
102
  matched: hostResult?.matched ?? false,
99
103
  decision: hostResult?.decision ?? 'allow',
100
104
  ruleId: hostResult?.ruleId,
105
+ activationMode: 'live',
101
106
  });
102
107
  }
103
108
  catch (evErr) {
@@ -321,25 +326,6 @@ export function handleBeforeToolCall(event, ctx) {
321
326
  // ---------------------------------------------------------------------------
322
327
  // Private helpers
323
328
  // ---------------------------------------------------------------------------
324
- function _extractParamsSummary(params) {
325
- const summary = {};
326
- // NOTE: Do NOT redact here — this feeds into RuleHost.evaluate() which
327
- // may match against paramsSummary.command. Redaction happens at
328
- // EventLog.record() before persistence.
329
- if (params.file_path)
330
- summary.file_path = params.file_path;
331
- if (params.path)
332
- summary.path = params.path;
333
- if (params.command)
334
- summary.command = params.command;
335
- if (params.args)
336
- summary.args = params.args;
337
- if (params.old_string)
338
- summary.old_string = params.old_string;
339
- if (params.new_string)
340
- summary.new_string = params.new_string;
341
- return summary;
342
- }
343
329
  function _getCurrentGfi(sessionId) {
344
330
  if (!sessionId)
345
331
  return 0;
@@ -57,7 +57,7 @@
57
57
  "@types/better-sqlite3": "^7.6.13",
58
58
  "@types/js-yaml": "^4.0.9",
59
59
  "@types/micromatch": "^4.0.10",
60
- "@types/node": "^25.6.2",
60
+ "@types/node": "^26.0.1",
61
61
  "@types/ws": "^8.5.13",
62
62
  "@typescript-eslint/eslint-plugin": "^8.61.0",
63
63
  "@typescript-eslint/parser": "^8.58.0",
@@ -83,7 +83,7 @@
83
83
  "@sinclair/typebox": "^0.34.48",
84
84
  "better-sqlite3": "^12.9.0",
85
85
  "commander": "^12.0.0",
86
- "js-yaml": "^4.1.1",
86
+ "js-yaml": "^5.2.0",
87
87
  "micromatch": "^4.0.8"
88
88
  }
89
89
  }