@principles/core 1.124.0 → 1.126.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 (130) hide show
  1. package/dist/runtime-v2/__tests__/architecture-regression.test.js +5 -1
  2. package/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
  3. package/dist/runtime-v2/__tests__/attack-e2e-pipeline-smoke.test.js +115 -21
  4. package/dist/runtime-v2/__tests__/attack-e2e-pipeline-smoke.test.js.map +1 -1
  5. package/dist/runtime-v2/__tests__/golden-path-diagnostician-e2e.test.js.map +1 -1
  6. package/dist/runtime-v2/__tests__/pain-signal-bridge-retried.test.js +7 -6
  7. package/dist/runtime-v2/__tests__/pain-signal-bridge-retried.test.js.map +1 -1
  8. package/dist/runtime-v2/__tests__/pain-signal-bridge-short-circuit.test.js.map +1 -1
  9. package/dist/runtime-v2/__tests__/pain-signal-bridge-workspace-dir.test.js.map +1 -1
  10. package/dist/runtime-v2/cli/diagnose.d.ts +2 -2
  11. package/dist/runtime-v2/cli/diagnose.d.ts.map +1 -1
  12. package/dist/runtime-v2/config/__tests__/pd-config-contract.test.js +3 -3
  13. package/dist/runtime-v2/config/__tests__/pd-config-contract.test.js.map +1 -1
  14. package/dist/runtime-v2/config/pd-config-defaults.js +2 -2
  15. package/dist/runtime-v2/config/pd-config-defaults.js.map +1 -1
  16. package/dist/runtime-v2/diagnostician-prompt-builder.d.ts +1 -64
  17. package/dist/runtime-v2/diagnostician-prompt-builder.d.ts.map +1 -1
  18. package/dist/runtime-v2/diagnostician-prompt-builder.js +0 -186
  19. package/dist/runtime-v2/diagnostician-prompt-builder.js.map +1 -1
  20. package/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js +17 -30
  21. package/dist/runtime-v2/feature-flags/__tests__/feature-flag-contract.test.js.map +1 -1
  22. package/dist/runtime-v2/feature-flags/feature-flag-contract.d.ts.map +1 -1
  23. package/dist/runtime-v2/feature-flags/feature-flag-contract.js +3 -8
  24. package/dist/runtime-v2/feature-flags/feature-flag-contract.js.map +1 -1
  25. package/dist/runtime-v2/index.d.ts +8 -7
  26. package/dist/runtime-v2/index.d.ts.map +1 -1
  27. package/dist/runtime-v2/index.js +8 -5
  28. package/dist/runtime-v2/index.js.map +1 -1
  29. package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js +108 -105
  30. package/dist/runtime-v2/internalization/__tests__/diag-chain-e2e.test.js.map +1 -1
  31. package/dist/runtime-v2/internalization/__tests__/runnerkind-seam.test.js +3 -3
  32. package/dist/runtime-v2/internalization/__tests__/runnerkind-seam.test.js.map +1 -1
  33. package/dist/runtime-v2/internalization/split-diagnostician-runner.d.ts.map +1 -1
  34. package/dist/runtime-v2/internalization/split-diagnostician-runner.js +121 -52
  35. package/dist/runtime-v2/internalization/split-diagnostician-runner.js.map +1 -1
  36. package/dist/runtime-v2/observer/__tests__/empathy-observer.real-e2e.test.js +28 -21
  37. package/dist/runtime-v2/observer/__tests__/empathy-observer.real-e2e.test.js.map +1 -1
  38. package/dist/runtime-v2/pain-signal-runtime-factory.d.ts +10 -1
  39. package/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
  40. package/dist/runtime-v2/pain-signal-runtime-factory.js +42 -40
  41. package/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
  42. package/dist/runtime-v2/pain-to-principle-service.d.ts +1 -0
  43. package/dist/runtime-v2/pain-to-principle-service.d.ts.map +1 -1
  44. package/dist/runtime-v2/pain-to-principle-service.js.map +1 -1
  45. package/dist/runtime-v2/runner/__tests__/diagnose.test.js.map +1 -1
  46. package/package.json +1 -1
  47. package/dist/runtime-v2/__tests__/diagnostician-core-grounding.test.d.ts +0 -2
  48. package/dist/runtime-v2/__tests__/diagnostician-core-grounding.test.d.ts.map +0 -1
  49. package/dist/runtime-v2/__tests__/diagnostician-core-grounding.test.js +0 -122
  50. package/dist/runtime-v2/__tests__/diagnostician-core-grounding.test.js.map +0 -1
  51. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-builder.integration.test.d.ts +0 -2
  52. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-builder.integration.test.d.ts.map +0 -1
  53. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-builder.integration.test.js +0 -169
  54. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-builder.integration.test.js.map +0 -1
  55. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-builder.test.d.ts +0 -2
  56. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-builder.test.d.ts.map +0 -1
  57. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-builder.test.js +0 -462
  58. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-builder.test.js.map +0 -1
  59. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-language.test.d.ts +0 -13
  60. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-language.test.d.ts.map +0 -1
  61. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-language.test.js +0 -97
  62. package/dist/runtime-v2/diagnostician/__tests__/diagnostician-prompt-language.test.js.map +0 -1
  63. package/dist/runtime-v2/runner/__tests__/diagnostician-runner.integration.test.d.ts +0 -2
  64. package/dist/runtime-v2/runner/__tests__/diagnostician-runner.integration.test.d.ts.map +0 -1
  65. package/dist/runtime-v2/runner/__tests__/diagnostician-runner.integration.test.js +0 -378
  66. package/dist/runtime-v2/runner/__tests__/diagnostician-runner.integration.test.js.map +0 -1
  67. package/dist/runtime-v2/runner/__tests__/diagnostician-runner.test.d.ts +0 -2
  68. package/dist/runtime-v2/runner/__tests__/diagnostician-runner.test.d.ts.map +0 -1
  69. package/dist/runtime-v2/runner/__tests__/diagnostician-runner.test.js +0 -682
  70. package/dist/runtime-v2/runner/__tests__/diagnostician-runner.test.js.map +0 -1
  71. package/dist/runtime-v2/runner/__tests__/diagnostician-telemetry.test.d.ts +0 -2
  72. package/dist/runtime-v2/runner/__tests__/diagnostician-telemetry.test.d.ts.map +0 -1
  73. package/dist/runtime-v2/runner/__tests__/diagnostician-telemetry.test.js +0 -286
  74. package/dist/runtime-v2/runner/__tests__/diagnostician-telemetry.test.js.map +0 -1
  75. package/dist/runtime-v2/runner/__tests__/dual-track-e2e.test.d.ts +0 -2
  76. package/dist/runtime-v2/runner/__tests__/dual-track-e2e.test.d.ts.map +0 -1
  77. package/dist/runtime-v2/runner/__tests__/dual-track-e2e.test.js +0 -320
  78. package/dist/runtime-v2/runner/__tests__/dual-track-e2e.test.js.map +0 -1
  79. package/dist/runtime-v2/runner/__tests__/lease-expiration-recovery.integration.test.d.ts +0 -2
  80. package/dist/runtime-v2/runner/__tests__/lease-expiration-recovery.integration.test.d.ts.map +0 -1
  81. package/dist/runtime-v2/runner/__tests__/lease-expiration-recovery.integration.test.js +0 -261
  82. package/dist/runtime-v2/runner/__tests__/lease-expiration-recovery.integration.test.js.map +0 -1
  83. package/dist/runtime-v2/runner/__tests__/m5-05-e2e.test.d.ts +0 -2
  84. package/dist/runtime-v2/runner/__tests__/m5-05-e2e.test.d.ts.map +0 -1
  85. package/dist/runtime-v2/runner/__tests__/m5-05-e2e.test.js +0 -405
  86. package/dist/runtime-v2/runner/__tests__/m5-05-e2e.test.js.map +0 -1
  87. package/dist/runtime-v2/runner/__tests__/m6-06-e2e.test.d.ts +0 -2
  88. package/dist/runtime-v2/runner/__tests__/m6-06-e2e.test.d.ts.map +0 -1
  89. package/dist/runtime-v2/runner/__tests__/m6-06-e2e.test.js +0 -347
  90. package/dist/runtime-v2/runner/__tests__/m6-06-e2e.test.js.map +0 -1
  91. package/dist/runtime-v2/runner/__tests__/m6-06-legacy.test.d.ts +0 -2
  92. package/dist/runtime-v2/runner/__tests__/m6-06-legacy.test.d.ts.map +0 -1
  93. package/dist/runtime-v2/runner/__tests__/m6-06-legacy.test.js +0 -186
  94. package/dist/runtime-v2/runner/__tests__/m6-06-legacy.test.js.map +0 -1
  95. package/dist/runtime-v2/runner/__tests__/m6-06-real-path.test.d.ts +0 -2
  96. package/dist/runtime-v2/runner/__tests__/m6-06-real-path.test.d.ts.map +0 -1
  97. package/dist/runtime-v2/runner/__tests__/m6-06-real-path.test.js +0 -355
  98. package/dist/runtime-v2/runner/__tests__/m6-06-real-path.test.js.map +0 -1
  99. package/dist/runtime-v2/runner/__tests__/m8-02-e2e.test.d.ts +0 -2
  100. package/dist/runtime-v2/runner/__tests__/m8-02-e2e.test.d.ts.map +0 -1
  101. package/dist/runtime-v2/runner/__tests__/m8-02-e2e.test.js +0 -486
  102. package/dist/runtime-v2/runner/__tests__/m8-02-e2e.test.js.map +0 -1
  103. package/dist/runtime-v2/runner/__tests__/m9-adapter-integration.test.d.ts +0 -2
  104. package/dist/runtime-v2/runner/__tests__/m9-adapter-integration.test.d.ts.map +0 -1
  105. package/dist/runtime-v2/runner/__tests__/m9-adapter-integration.test.js +0 -171
  106. package/dist/runtime-v2/runner/__tests__/m9-adapter-integration.test.js.map +0 -1
  107. package/dist/runtime-v2/runner/__tests__/m9-e2e.test.d.ts +0 -2
  108. package/dist/runtime-v2/runner/__tests__/m9-e2e.test.d.ts.map +0 -1
  109. package/dist/runtime-v2/runner/__tests__/m9-e2e.test.js +0 -175
  110. package/dist/runtime-v2/runner/__tests__/m9-e2e.test.js.map +0 -1
  111. package/dist/runtime-v2/runner/__tests__/max-attempts-exceeded.integration.test.d.ts +0 -2
  112. package/dist/runtime-v2/runner/__tests__/max-attempts-exceeded.integration.test.d.ts.map +0 -1
  113. package/dist/runtime-v2/runner/__tests__/max-attempts-exceeded.integration.test.js +0 -276
  114. package/dist/runtime-v2/runner/__tests__/max-attempts-exceeded.integration.test.js.map +0 -1
  115. package/dist/runtime-v2/runner/__tests__/retry-wait-recovery.integration.test.d.ts +0 -2
  116. package/dist/runtime-v2/runner/__tests__/retry-wait-recovery.integration.test.d.ts.map +0 -1
  117. package/dist/runtime-v2/runner/__tests__/retry-wait-recovery.integration.test.js +0 -272
  118. package/dist/runtime-v2/runner/__tests__/retry-wait-recovery.integration.test.js.map +0 -1
  119. package/dist/runtime-v2/runner/__tests__/start-run-input.test.d.ts +0 -2
  120. package/dist/runtime-v2/runner/__tests__/start-run-input.test.d.ts.map +0 -1
  121. package/dist/runtime-v2/runner/__tests__/start-run-input.test.js +0 -67
  122. package/dist/runtime-v2/runner/__tests__/start-run-input.test.js.map +0 -1
  123. package/dist/runtime-v2/runner/diagnostician-runner-options.d.ts +0 -57
  124. package/dist/runtime-v2/runner/diagnostician-runner-options.d.ts.map +0 -1
  125. package/dist/runtime-v2/runner/diagnostician-runner-options.js +0 -21
  126. package/dist/runtime-v2/runner/diagnostician-runner-options.js.map +0 -1
  127. package/dist/runtime-v2/runner/diagnostician-runner.d.ts +0 -89
  128. package/dist/runtime-v2/runner/diagnostician-runner.d.ts.map +0 -1
  129. package/dist/runtime-v2/runner/diagnostician-runner.js +0 -470
  130. package/dist/runtime-v2/runner/diagnostician-runner.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"start-run-input.test.js","sourceRoot":"","sources":["../../../../src/runtime-v2/runner/__tests__/start-run-input.test.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,0BAA0B,EAAE,MAAM,uCAAuC,CAAC;AACnF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAIhE,8EAA8E;AAC9E,SAAS,kBAAkB,CACzB,OAAoC,EACpC,MAAc,EACd,SAAiB;IAEjB,MAAM,OAAO,GAAG,IAAI,0BAA0B,EAAE,CAAC;IACjD,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAEjD,OAAO;QACL,SAAS,EAAE,EAAE,OAAO,EAAE,MAAM,EA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IAC7D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,GAAG,EAAE;QACtD,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,2EAA2E,EAAE,GAAG,EAAE;QACnF,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,YAAsB,CAAC,CAAC;QACzD,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACpC,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,WAAW,EAAE,CAAC;QACpD,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QACzE,MAAM,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,57 +0,0 @@
1
- /**
2
- * Configuration options for DiagnosticianRunner.
3
- *
4
- * Per CONTEXT.md D-02: pollIntervalMs default 5000, timeout configurable.
5
- * Per CONTEXT.md D-04: owner and runtimeKind required for lease acquisition.
6
- */
7
- import type { OutputLanguage } from '../language-directive.js';
8
- import type { EffectivePdConfig } from '../config/pd-config-types.js';
9
- export interface DiagnosticianRunnerOptions {
10
- /** Polling interval in ms (default: 5000 = 5 seconds). */
11
- readonly pollIntervalMs?: number;
12
- /** Maximum runtime execution time in ms (default: 300000 = 5 minutes). */
13
- readonly timeoutMs?: number;
14
- /** Default maxAttempts for synthetic TaskRecord in lease error path (default: 3). */
15
- readonly defaultMaxAttempts?: number;
16
- /** Lease owner identifier for acquireLease. */
17
- readonly owner: string;
18
- /** RuntimeKind value for lease/run record creation. */
19
- readonly runtimeKind: string;
20
- /**
21
- * Agent ID passed to the runtime adapter (default: 'diagnostician').
22
- * Allows CLI to forward --agent flag through to openclaw agent invocation.
23
- */
24
- readonly agentId?: string;
25
- /**
26
- * Owner's preferred language for principle generation (PRI-336).
27
- * When provided, the diagnostician prompt includes a language directive
28
- * telling the LLM to produce human-readable fields in this language.
29
- * Undefined = no language directive (backward compatible).
30
- */
31
- readonly outputLanguage?: OutputLanguage;
32
- /**
33
- * Effective PD config for feature flag resolution (PRI-371).
34
- * When provided, the runner reads `diagnostician_core_grounding` flag
35
- * to decide whether to inject core axioms into the prompt.
36
- * Undefined = flag off (backward compatible).
37
- */
38
- readonly effectiveConfig?: EffectivePdConfig;
39
- }
40
- /** Resolved options with defaults applied. */
41
- export interface ResolvedDiagnosticianRunnerOptions {
42
- readonly pollIntervalMs: number;
43
- readonly timeoutMs: number;
44
- readonly defaultMaxAttempts: number;
45
- readonly owner: string;
46
- readonly runtimeKind: string;
47
- readonly agentId: string;
48
- /** Owner's preferred language for principle generation (PRI-336). Undefined = no directive. */
49
- readonly outputLanguage?: OutputLanguage;
50
- /** Effective PD config for feature flag resolution (PRI-371). Undefined = flags off. */
51
- readonly effectiveConfig?: EffectivePdConfig;
52
- }
53
- /** Default option values. */
54
- export declare const DEFAULT_RUNNER_OPTIONS: Readonly<Omit<ResolvedDiagnosticianRunnerOptions, 'owner' | 'runtimeKind'>>;
55
- /** Resolve options by applying defaults. */
56
- export declare function resolveRunnerOptions(options: DiagnosticianRunnerOptions): ResolvedDiagnosticianRunnerOptions;
57
- //# sourceMappingURL=diagnostician-runner-options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diagnostician-runner-options.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/runner/diagnostician-runner-options.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,i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G"}
@@ -1,21 +0,0 @@
1
- /** Default option values. */
2
- export const DEFAULT_RUNNER_OPTIONS = {
3
- pollIntervalMs: 5_000,
4
- timeoutMs: 300_000,
5
- defaultMaxAttempts: 3,
6
- agentId: 'main',
7
- };
8
- /** Resolve options by applying defaults. */
9
- export function resolveRunnerOptions(options) {
10
- return {
11
- pollIntervalMs: options.pollIntervalMs ?? DEFAULT_RUNNER_OPTIONS.pollIntervalMs,
12
- timeoutMs: options.timeoutMs ?? DEFAULT_RUNNER_OPTIONS.timeoutMs,
13
- defaultMaxAttempts: options.defaultMaxAttempts ?? DEFAULT_RUNNER_OPTIONS.defaultMaxAttempts,
14
- owner: options.owner,
15
- runtimeKind: options.runtimeKind,
16
- agentId: options.agentId ?? DEFAULT_RUNNER_OPTIONS.agentId,
17
- outputLanguage: options.outputLanguage,
18
- effectiveConfig: options.effectiveConfig,
19
- };
20
- }
21
- //# sourceMappingURL=diagnostician-runner-options.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diagnostician-runner-options.js","sourceRoot":"","sources":["../../../src/runtime-v2/runner/diagnostician-runner-options.ts"],"names":[],"mappings":"AAuDA,6BAA6B;AAC7B,MAAM,CAAC,MAAM,sBAAsB,GAAgF;IACjH,cAAc,EAAE,KAAK;IACrB,SAAS,EAAE,OAAO;IAClB,kBAAkB,EAAE,CAAC;IACrB,OAAO,EAAE,MAAM;CACP,CAAC;AAEX,4CAA4C;AAC5C,MAAM,UAAU,oBAAoB,CAAC,OAAmC;IACtE,OAAO;QACL,cAAc,EAAE,OAAO,CAAC,cAAc,IAAI,sBAAsB,CAAC,cAAc;QAC/E,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,sBAAsB,CAAC,SAAS;QAChE,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,IAAI,sBAAsB,CAAC,kBAAkB;QAC3F,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,WAAW,EAAE,OAAO,CAAC,WAAW;QAChC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,sBAAsB,CAAC,OAAO;QAC1D,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,eAAe,EAAE,OAAO,CAAC,eAAe;KACzC,CAAC;AACJ,CAAC"}
@@ -1,89 +0,0 @@
1
- /**
2
- * DiagnosticianRunner -- explicit runner-driven diagnostician execution.
3
- *
4
- * Replaces heartbeat-prompt-driven execution with a deterministic pipeline:
5
- * lease -> build context -> invoke runtime -> poll -> fetch output -> validate -> succeed/fail
6
- *
7
- * Per D-01: Phase-based step pipeline, each phase is independent method.
8
- * Per D-02: Polling loop with configurable interval and timeout.
9
- * Per D-03: Retry with backoff on transient errors, fail on permanent.
10
- * Per D-04: All store operations through RuntimeStateManager.
11
- *
12
- * Runner does NOT:
13
- * - Import from evolution-worker.ts or prompt.ts
14
- * - Write artifact files (M5 scope)
15
- * - Emit principle candidates (M5 scope)
16
- * - Persist RunnerPhase to TaskStore
17
- */
18
- import type { RuntimeStateManager } from '../store/runtime-state-manager.js';
19
- import type { ContextAssembler } from '../store/context/context-assembler.js';
20
- import type { PDRuntimeAdapter } from '../runtime-protocol.js';
21
- import type { StoreEventEmitter } from '../store/event-emitter.js';
22
- import type { DiagnosticianRunnerOptions } from './diagnostician-runner-options.js';
23
- import type { DiagnosticianValidator } from './diagnostician-validator.js';
24
- import type { RunnerResult } from './runner-result.js';
25
- import type { DiagnosticianCommitter } from '../store/commit/diagnostician-committer.js';
26
- import { RunnerPhase } from './runner-phase.js';
27
- /** Dependencies injected into DiagnosticianRunner. */
28
- export interface DiagnosticianRunnerDeps {
29
- readonly stateManager: RuntimeStateManager;
30
- readonly contextAssembler: ContextAssembler;
31
- readonly runtimeAdapter: PDRuntimeAdapter;
32
- readonly eventEmitter: StoreEventEmitter;
33
- readonly validator: DiagnosticianValidator;
34
- readonly committer: DiagnosticianCommitter;
35
- }
36
- export declare class DiagnosticianRunner {
37
- private phase;
38
- private readonly resolvedOptions;
39
- private readonly stateManager;
40
- private readonly contextAssembler;
41
- private readonly runtimeAdapter;
42
- private readonly eventEmitter;
43
- private readonly validator;
44
- private readonly committer;
45
- /** Whether core grounding was active for the current run (set in invokeRuntime, read in succeedTask). */
46
- private coreGroundingActive;
47
- constructor(deps: DiagnosticianRunnerDeps, options: DiagnosticianRunnerOptions);
48
- /** Get the current internal phase. For testing/observability only. */
49
- get currentPhase(): RunnerPhase;
50
- /**
51
- * Emit a diagnostician telemetry event via the store event emitter.
52
- */
53
- private emitDiagnosticianEvent;
54
- /**
55
- * Execute the full diagnostician lifecycle for a task.
56
- *
57
- * The runner does NOT hold mutable state between run() calls.
58
- * Each invocation is independent.
59
- */
60
- run(taskId: string): Promise<RunnerResult>;
61
- /**
62
- * Handle errors that occur after a successful lease acquisition.
63
- * Uses the real leasedTask (with actual attemptCount/maxAttempts) — never synthetic.
64
- * lease_conflict is NOT handled here because it cannot occur after a successful lease.
65
- */
66
- private handlePostLeaseError;
67
- private buildContext;
68
- /**
69
- * Resolve the store's runId for the latest run of a task.
70
- * acquireLease creates a RunRecord with a deterministic ID (run_{taskId}_{attempt}).
71
- * The adapter's RunHandle.runId is separate -- we need the store's ID for
72
- * updateRunOutput and other store operations.
73
- */
74
- private resolveStoreRunId;
75
- private invokeRuntime;
76
- private pollUntilTerminal;
77
- private fetchAndParseOutput;
78
- private succeedTask;
79
- private handleRuntimeFailure;
80
- private handleValidationError;
81
- private handleLeaseOrPhaseError;
82
- private retryOrFail;
83
- private readonly PERMANENT_ERROR_CATEGORIES;
84
- private isPermanentError;
85
- private classifyError;
86
- private mapRunStatusToErrorCategory;
87
- private sleep;
88
- }
89
- //# sourceMappingURL=diagnostician-runner.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"diagnostician-runner.d.ts","sourceRoot":"","sources":["../../../src/runtime-v2/runner/diagnostician-runner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,KA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AE,OAAO,EAAE,0BAA0B;IAU9E,sEAAsE;IACtE,IAAI,YAAY,IAAI,WAAW,CAE9B;IAED;;OAEG;IACH,OAAO,CAAC,sBAAsB;IAe9B;;;;;OAKG;IACG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;IAqFhD;;;;OAIG;YACW,oBAAoB;YAoBpB,YAAY;IAI1B;;;;;OAKG;YACW,iBAAiB;YASjB,aAAa;YAyBb,iBAAiB;YAyBjB,mBAAmB;YAqCnB,WAAW;YAsHX,oBAAoB;YAgBpB,qBAAqB;YAkBrB,uBAAuB;YAyCvB,WAAW;IA4CzB,OAAO,CAAC,QAAQ,CAAC,0BAA0B,CAEzC;IAEF,OAAO,CAAC,gBAAgB;IAKxB,OAAO,CAAC,aAAa;IAWrB,OAAO,CAAC,2BAA2B;IAUnC,OAAO,CAAC,KAAK;CAGd"}
@@ -1,470 +0,0 @@
1
- import { DiagnosticianOutputV1Schema } from '../diagnostician-output.js';
2
- import { DiagnosticianPromptBuilder } from '../diagnostician-prompt-builder.js';
3
- import { PDRuntimeError } from '../error-categories.js';
4
- import { Value } from '@sinclair/typebox/value';
5
- import { safeStringifyPreview } from '../adapter/output-repair-contract.js';
6
- import { redactSensitiveFields } from '../feedback/redact-sensitive.js';
7
- import { RunnerPhase } from './runner-phase.js';
8
- import { resolveRunnerOptions } from './diagnostician-runner-options.js';
9
- import { computeFeatureFlagsFromConfig, isFeatureEnabled } from '../config/pd-config-feature-flags.js';
10
- import { CORE_PRINCIPLES, isCorePrincipleId } from '../core-principles/core-principle-registry.js';
11
- export class DiagnosticianRunner {
12
- phase = RunnerPhase.Idle;
13
- resolvedOptions;
14
- stateManager;
15
- contextAssembler;
16
- runtimeAdapter;
17
- eventEmitter;
18
- validator;
19
- committer;
20
- /** Whether core grounding was active for the current run (set in invokeRuntime, read in succeedTask). */
21
- coreGroundingActive = false;
22
- constructor(deps, options) {
23
- this.stateManager = deps.stateManager;
24
- this.contextAssembler = deps.contextAssembler;
25
- this.runtimeAdapter = deps.runtimeAdapter;
26
- this.eventEmitter = deps.eventEmitter;
27
- this.validator = deps.validator;
28
- this.committer = deps.committer;
29
- this.resolvedOptions = resolveRunnerOptions(options);
30
- }
31
- /** Get the current internal phase. For testing/observability only. */
32
- get currentPhase() {
33
- return this.phase;
34
- }
35
- /**
36
- * Emit a diagnostician telemetry event via the store event emitter.
37
- */
38
- emitDiagnosticianEvent(eventType, taskId, payload) {
39
- this.eventEmitter.emitTelemetry({
40
- eventType: eventType,
41
- traceId: taskId,
42
- timestamp: new Date().toISOString(),
43
- sessionId: this.resolvedOptions.owner,
44
- agentId: this.resolvedOptions.agentId,
45
- payload,
46
- });
47
- }
48
- /**
49
- * Execute the full diagnostician lifecycle for a task.
50
- *
51
- * The runner does NOT hold mutable state between run() calls.
52
- * Each invocation is independent.
53
- */
54
- async run(taskId) {
55
- this.phase = RunnerPhase.Idle;
56
- this.coreGroundingActive = false;
57
- // 1. Acquire lease — isolated try/catch so lease_conflict never uses synthetic TaskRecord
58
- let leasedTask;
59
- try {
60
- leasedTask = await this.stateManager.acquireLease({
61
- taskId,
62
- owner: this.resolvedOptions.owner,
63
- runtimeKind: this.resolvedOptions.runtimeKind,
64
- });
65
- }
66
- catch (error) {
67
- return await this.handleLeaseOrPhaseError(taskId, error);
68
- }
69
- // Emit: diagnostician_task_leased (only on successful lease)
70
- this.emitDiagnosticianEvent('diagnostician_task_leased', taskId, {
71
- taskKind: leasedTask.taskKind,
72
- attemptCount: leasedTask.attemptCount,
73
- });
74
- // All subsequent errors use the real leasedTask — no synthetic TaskRecord allowed
75
- try {
76
- // Look up the store's runId for this attempt (acquireLease creates it).
77
- // The adapter's RunHandle.runId is separate from the store's runId.
78
- const storeRunId = await this.resolveStoreRunId(taskId);
79
- // 2. Build context
80
- this.phase = RunnerPhase.BuildingContext;
81
- const context = await this.buildContext(taskId);
82
- const contextHash = context.contextHash;
83
- // Emit: diagnostician_context_built
84
- this.emitDiagnosticianEvent('diagnostician_context_built', taskId, {
85
- contextHash,
86
- sourceCount: context.sourceRefs.length,
87
- });
88
- // 3. Invoke runtime (skip CreatingRun -- acquireLease already created it)
89
- this.phase = RunnerPhase.Invoking;
90
- const runHandle = await this.invokeRuntime(context, taskId);
91
- // Emit: diagnostician_run_started
92
- this.emitDiagnosticianEvent('diagnostician_run_started', taskId, {
93
- runtimeKind: this.resolvedOptions.runtimeKind,
94
- });
95
- // 4. Poll until terminal
96
- this.phase = RunnerPhase.Polling;
97
- const finalStatus = await this.pollUntilTerminal(runHandle);
98
- // 5. Handle non-success terminal states
99
- if (finalStatus.status !== 'succeeded') {
100
- return await this.handleRuntimeFailure(taskId, leasedTask, finalStatus);
101
- }
102
- // 6. Fetch output
103
- this.phase = RunnerPhase.FetchingOutput;
104
- const output = await this.fetchAndParseOutput(runHandle.runId);
105
- // 7. Validate (delegate to validator)
106
- this.phase = RunnerPhase.Validating;
107
- const validationResult = await this.validator.validate(output, taskId);
108
- if (!validationResult.valid) {
109
- return await this.handleValidationError({
110
- taskId, task: leasedTask, errors: validationResult.errors, errorCategory: validationResult.errorCategory,
111
- });
112
- }
113
- // TELE-04: output_validation_succeeded — validator returned valid: true
114
- this.emitDiagnosticianEvent('output_validation_succeeded', taskId, {
115
- runtimeKind: this.resolvedOptions.runtimeKind,
116
- outputValid: validationResult.valid,
117
- });
118
- // 8. Succeed task -- store output and mark succeeded using store's runId
119
- return await this.succeedTask({ taskId, runId: storeRunId, output, task: leasedTask, contextHash });
120
- }
121
- catch (error) {
122
- // handleLeaseOrPhaseError is only used for lease errors (before lease).
123
- // Post-lease errors use retryOrFail with the real leasedTask.
124
- return await this.handlePostLeaseError(taskId, leasedTask, error);
125
- }
126
- }
127
- /**
128
- * Handle errors that occur after a successful lease acquisition.
129
- * Uses the real leasedTask (with actual attemptCount/maxAttempts) — never synthetic.
130
- * lease_conflict is NOT handled here because it cannot occur after a successful lease.
131
- */
132
- async handlePostLeaseError(taskId, task, error) {
133
- const classified = this.classifyError(error);
134
- // Emit: diagnostician_run_failed
135
- this.emitDiagnosticianEvent('diagnostician_run_failed', taskId, {
136
- errorCategory: classified.category,
137
- errorMessage: classified.message,
138
- });
139
- // Post-lease errors always go through retryOrFail with the real task record.
140
- // This ensures attemptCount/maxAttempts from the store are respected.
141
- return this.retryOrFail({ taskId, task, errorCategory: classified.category, failureReason: classified.message });
142
- }
143
- // -- Phase methods (each independently testable) --
144
- async buildContext(taskId) {
145
- return this.contextAssembler.assemble(taskId);
146
- }
147
- /**
148
- * Resolve the store's runId for the latest run of a task.
149
- * acquireLease creates a RunRecord with a deterministic ID (run_{taskId}_{attempt}).
150
- * The adapter's RunHandle.runId is separate -- we need the store's ID for
151
- * updateRunOutput and other store operations.
152
- */
153
- async resolveStoreRunId(taskId) {
154
- const runs = await this.stateManager.getRunsByTask(taskId);
155
- const latestRun = runs[runs.length - 1];
156
- if (!latestRun) {
157
- throw new PDRuntimeError('execution_failed', `No run record found for task ${taskId} after lease acquisition`);
158
- }
159
- return latestRun.runId;
160
- }
161
- async invokeRuntime(context, taskId) {
162
- // T-E (PRI-371): Read diagnostician_core_grounding flag from effective config.
163
- // EP-03: Flag off (default) = no change to prompt. Flag on = inject PHASE 3.5.
164
- let coreGrounding = false;
165
- if (this.resolvedOptions.effectiveConfig) {
166
- const featureFlags = computeFeatureFlagsFromConfig(this.resolvedOptions.effectiveConfig);
167
- coreGrounding = isFeatureEnabled(featureFlags, 'diagnostician_core_grounding');
168
- }
169
- this.coreGroundingActive = coreGrounding;
170
- const builder = new DiagnosticianPromptBuilder();
171
- const { message } = builder.buildPrompt(context, { outputLanguage: this.resolvedOptions.outputLanguage, coreGrounding });
172
- const startInput = {
173
- agentSpec: { agentId: this.resolvedOptions.agentId, schemaVersion: 'v1' },
174
- taskRef: { taskId },
175
- inputPayload: message,
176
- contextItems: [],
177
- outputSchemaRef: 'diagnostician-output-v1',
178
- timeoutMs: this.resolvedOptions.timeoutMs,
179
- };
180
- return this.runtimeAdapter.startRun(startInput);
181
- }
182
- async pollUntilTerminal(runHandle) {
183
- const deadline = Date.now() + this.resolvedOptions.timeoutMs;
184
- const terminalStatuses = ['succeeded', 'failed', 'timed_out', 'cancelled'];
185
- while (Date.now() < deadline) {
186
- const status = await this.runtimeAdapter.pollRun(runHandle.runId);
187
- if (terminalStatuses.includes(status.status)) {
188
- return status;
189
- }
190
- await this.sleep(this.resolvedOptions.pollIntervalMs);
191
- }
192
- // Timeout -- cancel the run gracefully, preserving the timeout error
193
- try {
194
- await this.runtimeAdapter.cancelRun(runHandle.runId);
195
- }
196
- catch (cancelErr) {
197
- // Log but do not throw — timeout error is the primary failure to report
198
- this.emitDiagnosticianEvent('diagnostician_cancel_run_failed', 'timeout-task', {
199
- runId: runHandle.runId,
200
- errorMessage: cancelErr instanceof Error ? cancelErr.message : String(cancelErr),
201
- });
202
- }
203
- throw new PDRuntimeError('timeout', `Run ${runHandle.runId} timed out after ${this.resolvedOptions.timeoutMs}ms`);
204
- }
205
- async fetchAndParseOutput(runId) {
206
- const result = await this.runtimeAdapter.fetchOutput(runId);
207
- if (!result || !result.payload) {
208
- throw new PDRuntimeError('output_invalid', `No output available for run ${runId}`);
209
- }
210
- // ERR-001/ERR-005: Do NOT use `as DiagnosticianOutputV1` to bypass validation.
211
- // The adapter may return payload that passed its own schema check, but the runner
212
- // must independently verify the shape before trusting it (defense-in-depth).
213
- // Adapters that already validated (e.g., PiAiRuntimeAdapter, OpenClawCliRuntimeAdapter)
214
- // will pass this check trivially; adapters that don't validate will be caught here.
215
- if (!Value.Check(DiagnosticianOutputV1Schema, result.payload)) {
216
- const schemaErrors = [...Value.Errors(DiagnosticianOutputV1Schema, result.payload)]
217
- .slice(0, 5)
218
- .map(e => ({ path: e.path, message: e.message }));
219
- const redacted = redactSensitiveFields(result.payload);
220
- const boundedPreview = redacted.ok
221
- ? safeStringifyPreview(redacted.value, 300)
222
- : safeStringifyPreview(result.payload, 300);
223
- throw new PDRuntimeError('output_invalid', `Run ${runId} output failed DiagnosticianOutputV1 schema validation at runner boundary`, {
224
- parseFailureReason: 'runner_boundary_schema_check_failed',
225
- boundedRawOutputPreview: boundedPreview,
226
- schemaErrors,
227
- nextAction: 'Adapter returned payload that does not match DiagnosticianOutputV1; check adapter validation logic',
228
- });
229
- }
230
- // Value.Check narrows the type at runtime but not in TS; Value.Cast
231
- // performs a safe conversion after validation passes.
232
- return Value.Cast(DiagnosticianOutputV1Schema, result.payload);
233
- }
234
- async succeedTask(ctx) {
235
- // Lineage strip contract invariant: adapter should have stripped lineage
236
- // fields (taskId, sourcePainId, etc.) from LLM output. If they survive,
237
- // the adapter violated its contract — emit telemetry but don't crash.
238
- const outputRecord = ctx.output;
239
- if (typeof outputRecord === 'object' && outputRecord !== null &&
240
- Object.hasOwn(outputRecord, 'taskId')) {
241
- this.emitDiagnosticianEvent('lineage_strip_contract_violation', ctx.taskId, {
242
- reason: 'output_contained_taskId_after_strip',
243
- expectedAdapter: 'pi-ai-runtime-adapter',
244
- });
245
- }
246
- // Store output before commit so run record reflects output on disk
247
- try {
248
- await this.stateManager.updateRunOutput(ctx.runId, JSON.stringify(ctx.output));
249
- }
250
- catch (updateErr) {
251
- this.emitDiagnosticianEvent('diagnostician_update_output_failed', ctx.taskId, {
252
- runId: ctx.runId,
253
- errorMessage: updateErr instanceof Error ? updateErr.message : String(updateErr),
254
- });
255
- throw updateErr;
256
- }
257
- // Commit artifact + candidates before marking task succeeded
258
- this.phase = RunnerPhase.Committing;
259
- let commitResult;
260
- try {
261
- commitResult = await this.committer.commit({
262
- runId: ctx.runId,
263
- taskId: ctx.taskId,
264
- output: ctx.output,
265
- idempotencyKey: `${ctx.taskId}:${ctx.runId}`,
266
- });
267
- }
268
- catch (commitErr) {
269
- // Emit: diagnostician_artifact_commit_failed (TELE-02)
270
- this.emitDiagnosticianEvent('diagnostician_artifact_commit_failed', ctx.taskId, {
271
- taskId: ctx.taskId,
272
- runId: ctx.runId,
273
- errorCategory: commitErr instanceof PDRuntimeError ? commitErr.category : 'artifact_commit_failed',
274
- errorMessage: commitErr instanceof Error ? commitErr.message : String(commitErr),
275
- });
276
- throw commitErr; // Re-throw so outer try/catch in run() handles it
277
- }
278
- // Emit: principle_candidate_registered per candidate (TELE-03)
279
- const principleRecs = ctx.output.recommendations.filter((r) => r.kind === 'principle');
280
- for (let i = 0; i < principleRecs.length; i++) {
281
- const rec = principleRecs[i]; // eslint-disable-line @typescript-eslint/no-non-null-assertion
282
- this.emitDiagnosticianEvent('principle_candidate_registered', ctx.taskId, {
283
- candidateIndex: i,
284
- commitId: commitResult.commitId,
285
- kind: 'principle',
286
- description: rec.description,
287
- sourceRunId: ctx.runId,
288
- });
289
- }
290
- // Emit: diagnostician_artifact_committed (TELE-01)
291
- this.emitDiagnosticianEvent('diagnostician_artifact_committed', ctx.taskId, {
292
- commitId: commitResult.commitId,
293
- artifactId: commitResult.artifactId,
294
- candidateCount: commitResult.candidateCount,
295
- taskId: ctx.taskId,
296
- runId: ctx.runId,
297
- });
298
- // Use commit URI as resultRef
299
- const resultRef = `commit://${commitResult.commitId}`;
300
- try {
301
- await this.stateManager.markTaskSucceeded(ctx.taskId, resultRef);
302
- }
303
- catch (stateErr) {
304
- // markTaskSucceeded failed after commit succeeded — emit error event so this is observable
305
- this.emitDiagnosticianEvent('diagnostician_mark_succeeded_failed', ctx.taskId, {
306
- taskId: ctx.taskId,
307
- runId: ctx.runId,
308
- commitId: commitResult.commitId,
309
- errorMessage: stateErr instanceof Error ? stateErr.message : String(stateErr),
310
- });
311
- throw stateErr;
312
- }
313
- // Emit: diagnostician_task_succeeded
314
- this.emitDiagnosticianEvent('diagnostician_task_succeeded', ctx.taskId, {
315
- attemptCount: ctx.task.attemptCount,
316
- resultRef,
317
- commitId: commitResult.commitId,
318
- candidateCount: commitResult.candidateCount,
319
- });
320
- // T-E (PRI-371): Emit core grounding telemetry when flag was on.
321
- // EP-01: axiom IDs from ambiguityNotes are untrusted LLM output —
322
- // validate with regex + isCorePrincipleId() before counting.
323
- if (this.coreGroundingActive) {
324
- const ambiguityNotes = ctx.output.ambiguityNotes ?? [];
325
- const allNotes = ambiguityNotes.join(' ');
326
- const axiomIdMatches = allNotes.match(/T-\d{2}/g) ?? [];
327
- const validatedIds = axiomIdMatches.filter(id => isCorePrincipleId(id));
328
- const uniqueIds = new Set(validatedIds);
329
- const linkagePercent = (uniqueIds.size / CORE_PRINCIPLES.length) * 100;
330
- this.emitDiagnosticianEvent('diagnostician_core_grounding_result', ctx.taskId, {
331
- taskId: ctx.taskId,
332
- axiomRefCount: uniqueIds.size,
333
- linkagePercent,
334
- });
335
- }
336
- this.phase = RunnerPhase.Completed;
337
- return {
338
- status: 'succeeded',
339
- taskId: ctx.taskId,
340
- contextHash: ctx.contextHash,
341
- output: ctx.output,
342
- attemptCount: ctx.task.attemptCount,
343
- };
344
- }
345
- async handleRuntimeFailure(taskId, task, runStatus) {
346
- const errorCategory = this.mapRunStatusToErrorCategory(runStatus.status, runStatus.reason);
347
- // Emit: diagnostician_run_failed
348
- this.emitDiagnosticianEvent('diagnostician_run_failed', taskId, {
349
- runStatus: runStatus.status,
350
- errorCategory,
351
- });
352
- return this.retryOrFail({ taskId, task, errorCategory, failureReason: `Runtime execution ended with status: ${runStatus.status}` });
353
- }
354
- async handleValidationError(ctx) {
355
- const category = ctx.errorCategory ?? 'output_invalid';
356
- // Emit: diagnostician_output_invalid
357
- this.emitDiagnosticianEvent('diagnostician_output_invalid', ctx.taskId, {
358
- errorCount: ctx.errors.length,
359
- errorCategory: category,
360
- });
361
- // TELE-04: output_validation_failed — validator returned valid: false
362
- this.emitDiagnosticianEvent('output_validation_failed', ctx.taskId, {
363
- errorCount: ctx.errors.length,
364
- errorCategory: category,
365
- });
366
- return this.retryOrFail({ taskId: ctx.taskId, task: ctx.task, errorCategory: category, failureReason: `Validation failed: ${ctx.errors.join('; ')}` });
367
- }
368
- async handleLeaseOrPhaseError(taskId, error) {
369
- const classified = this.classifyError(error);
370
- // lease_conflict is a concurrent-access conflict, not a state change.
371
- // No mutation methods (markTaskFailed/markTaskRetryWait) are called.
372
- if (classified.category === 'lease_conflict') {
373
- this.emitDiagnosticianEvent('diagnostician_run_failed', taskId, {
374
- errorCategory: 'lease_conflict',
375
- errorMessage: classified.message,
376
- });
377
- return {
378
- status: 'failed',
379
- taskId,
380
- errorCategory: 'lease_conflict',
381
- failureReason: classified.message,
382
- attemptCount: 1,
383
- };
384
- }
385
- // Non-lease errors (e.g. storage_unavailable before lease) also must not
386
- // use synthetic TaskRecord. Build one with real defaults from options.
387
- this.emitDiagnosticianEvent('diagnostician_run_failed', taskId, {
388
- errorCategory: classified.category,
389
- errorMessage: classified.message,
390
- });
391
- const task = {
392
- taskId,
393
- taskKind: 'diagnostician',
394
- status: 'leased',
395
- createdAt: new Date().toISOString(),
396
- updatedAt: new Date().toISOString(),
397
- attemptCount: 1,
398
- maxAttempts: this.resolvedOptions.defaultMaxAttempts,
399
- };
400
- return this.retryOrFail({ taskId, task, errorCategory: classified.category, failureReason: classified.message });
401
- }
402
- async retryOrFail(ctx) {
403
- // Check if error is permanent (never retry)
404
- if (this.isPermanentError(ctx.errorCategory)) {
405
- await this.stateManager.markTaskFailed(ctx.taskId, ctx.errorCategory);
406
- this.emitDiagnosticianEvent('diagnostician_task_failed', ctx.taskId, {
407
- errorCategory: ctx.errorCategory,
408
- attemptCount: ctx.task.attemptCount,
409
- failureReason: ctx.failureReason,
410
- });
411
- this.phase = RunnerPhase.Failed;
412
- return { status: 'failed', taskId: ctx.taskId, errorCategory: ctx.errorCategory, failureReason: ctx.failureReason, attemptCount: ctx.task.attemptCount };
413
- }
414
- // Check retry policy
415
- const shouldRetry = this.stateManager.getRetryPolicy().shouldRetry(ctx.task);
416
- if (shouldRetry) {
417
- await this.stateManager.markTaskRetryWait(ctx.taskId, ctx.errorCategory);
418
- this.emitDiagnosticianEvent('diagnostician_task_retried', ctx.taskId, {
419
- errorCategory: ctx.errorCategory,
420
- attemptCount: ctx.task.attemptCount,
421
- });
422
- this.phase = RunnerPhase.RetryWaiting;
423
- return { status: 'retried', taskId: ctx.taskId, errorCategory: ctx.errorCategory, failureReason: ctx.failureReason, attemptCount: ctx.task.attemptCount };
424
- }
425
- // Max attempts exceeded
426
- await this.stateManager.markTaskFailed(ctx.taskId, 'max_attempts_exceeded');
427
- this.emitDiagnosticianEvent('diagnostician_task_failed', ctx.taskId, {
428
- errorCategory: 'max_attempts_exceeded',
429
- attemptCount: ctx.task.attemptCount,
430
- failureReason: `Max attempts exceeded: ${ctx.failureReason}`,
431
- });
432
- this.phase = RunnerPhase.Failed;
433
- return {
434
- status: 'failed',
435
- taskId: ctx.taskId,
436
- errorCategory: 'max_attempts_exceeded',
437
- failureReason: `Max attempts exceeded: ${ctx.failureReason}`,
438
- attemptCount: ctx.task.attemptCount,
439
- };
440
- }
441
- // -- Error classification --
442
- PERMANENT_ERROR_CATEGORIES = new Set(Object.freeze(['storage_unavailable', 'workspace_invalid', 'workspace_dirty', 'capability_missing']));
443
- isPermanentError(category) {
444
- return this.PERMANENT_ERROR_CATEGORIES.has(category);
445
- }
446
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this
447
- classifyError(error) {
448
- if (error instanceof PDRuntimeError) {
449
- return { category: error.category, message: error.message };
450
- }
451
- if (error instanceof Error) {
452
- return { category: 'execution_failed', message: error.message };
453
- }
454
- return { category: 'execution_failed', message: String(error) };
455
- }
456
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this
457
- mapRunStatusToErrorCategory(status, _reason) {
458
- switch (status) {
459
- case 'failed': return 'execution_failed';
460
- case 'timed_out': return 'timeout';
461
- case 'cancelled': return 'cancelled';
462
- default: return 'execution_failed';
463
- }
464
- }
465
- // eslint-disable-next-line @typescript-eslint/class-methods-use-this
466
- sleep(ms) {
467
- return new Promise((resolve) => setTimeout(resolve, ms));
468
- }
469
- }
470
- //# sourceMappingURL=diagnostician-runner.js.map