@principles/core 1.84.0 → 1.85.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 (22) hide show
  1. package/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.d.ts +2 -0
  2. package/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.d.ts.map +1 -0
  3. package/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.js +398 -0
  4. package/dist/runtime-v2/internalization/__tests__/philosopher-runner-trust-boundary.test.js.map +1 -0
  5. package/dist/runtime-v2/internalization/philosopher-output.d.ts +8 -2
  6. package/dist/runtime-v2/internalization/philosopher-output.d.ts.map +1 -1
  7. package/dist/runtime-v2/internalization/philosopher-output.js +16 -11
  8. package/dist/runtime-v2/internalization/philosopher-output.js.map +1 -1
  9. package/dist/runtime-v2/internalization/philosopher-runner.d.ts +36 -55
  10. package/dist/runtime-v2/internalization/philosopher-runner.d.ts.map +1 -1
  11. package/dist/runtime-v2/internalization/philosopher-runner.js +117 -401
  12. package/dist/runtime-v2/internalization/philosopher-runner.js.map +1 -1
  13. package/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.js +22 -0
  14. package/dist/runtime-v2/runner/__tests__/base-peer-runner-trust-boundary.test.js.map +1 -1
  15. package/dist/runtime-v2/runner/base-peer-runner.d.ts.map +1 -1
  16. package/dist/runtime-v2/runner/base-peer-runner.js +5 -1
  17. package/dist/runtime-v2/runner/base-peer-runner.js.map +1 -1
  18. package/dist/telemetry-event.d.ts +2 -2
  19. package/dist/telemetry-event.d.ts.map +1 -1
  20. package/dist/telemetry-event.js +23 -0
  21. package/dist/telemetry-event.js.map +1 -1
  22. package/package.json +1 -1
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * PhilosopherRunner — Second peer runner for the Internalization Engine (PRI-90).
3
3
  *
4
- * Reads a Dreamer artifact, invokes PDRuntimeAdapter for philosophical analysis,
5
- * validates output, writes Philosopher PIArtifact, and marks task succeeded.
4
+ * Migrated to extend BasePeerRunner (PRI-new). The shared lease → buildContext →
5
+ * invoke poll fetch validate succeed/fail pipeline is now in the base
6
+ * class. This file only contains Philosopher-specific logic.
6
7
  *
7
8
  * Key constraints (ADR-0003):
8
9
  * - Uses PDRuntimeAdapter for all LLM execution (no direct SDK calls)
@@ -17,20 +18,25 @@
17
18
  * 3. fetch Dreamer artifact via PIArtifactStore
18
19
  * 4. startRun with outputSchemaRef: 'philosopher-output-v1'
19
20
  * 5. pollUntilTerminal
20
- * 6. fetchOutput → parse as PhilosopherOutputV1
21
- * 7. validate via PhilosopherValidator
22
- * 8. updateRunOutputpersist serialized output
23
- * 9. write PIArtifact → markTaskSucceeded with philosopher:// resultRef
21
+ * 6. fetchOutput → validate as unknown → cast to PhilosopherOutputV1
22
+ * 7. updateRunOutput persist serialized output
23
+ * 8. write PIArtifact markTaskSucceeded with philosopher:// resultRef
24
24
  *
25
25
  * @see docs/adr/0003-peer-agent-state-machine-orchestration.md
26
+ * @see BasePeerRunner in runner/base-peer-runner.ts
26
27
  */
27
- import type { RuntimeStateManager } from '../store/runtime-state-manager.js';
28
- import type { PDRuntimeAdapter } from '../runtime-protocol.js';
29
- import type { StoreEventEmitter } from '../store/event-emitter.js';
28
+ import type { RunHandle } from '../runtime-protocol.js';
30
29
  import type { PhilosopherOutputV1, PhilosopherValidator } from './philosopher-output.js';
31
- import type { PIArtifactStore } from './pi-artifact.js';
30
+ import type { TaskRecord } from '../task-status.js';
32
31
  import { type PDErrorCategory } from '../error-categories.js';
33
- import { RunnerPhase } from '../runner/runner-phase.js';
32
+ import { BasePeerRunner } from '../runner/base-peer-runner.js';
33
+ import type { PeerRunnerOptions, PeerRunnerDeps, PeerRunnerResult, PeerRunnerValidationResult } from '../runner/peer-runner-types.js';
34
+ /** Context built by PhilosopherRunner.buildContext() and consumed by invokeRuntime(). */
35
+ interface PhilosopherContext {
36
+ readonly contextHash: string;
37
+ readonly dreamerArtifact: string;
38
+ readonly sourceDreamerArtifactId: string;
39
+ }
34
40
  export type PhilosopherRunnerResultStatus = 'succeeded' | 'failed' | 'retried';
35
41
  export interface PhilosopherRunnerResult {
36
42
  readonly status: PhilosopherRunnerResultStatus;
@@ -44,14 +50,7 @@ export interface PhilosopherRunnerResult {
44
50
  readonly failureReason?: string;
45
51
  readonly attemptCount: number;
46
52
  }
47
- export interface PhilosopherRunnerOptions {
48
- readonly pollIntervalMs?: number;
49
- readonly timeoutMs?: number;
50
- readonly defaultMaxAttempts?: number;
51
- readonly owner: string;
52
- readonly runtimeKind: string;
53
- readonly agentId?: string;
54
- }
53
+ export type PhilosopherRunnerOptions = PeerRunnerOptions;
55
54
  export interface ResolvedPhilosopherRunnerOptions {
56
55
  readonly pollIntervalMs: number;
57
56
  readonly timeoutMs: number;
@@ -60,44 +59,26 @@ export interface ResolvedPhilosopherRunnerOptions {
60
59
  readonly runtimeKind: string;
61
60
  readonly agentId: string;
62
61
  }
63
- declare const DEFAULT_PHILOSOPHER_RUNNER_OPTIONS: Readonly<Omit<ResolvedPhilosopherRunnerOptions, 'owner' | 'runtimeKind'>>;
64
- declare function resolvePhilosopherRunnerOptions(options: PhilosopherRunnerOptions): ResolvedPhilosopherRunnerOptions;
65
- export interface PhilosopherRunnerDeps {
66
- readonly stateManager: RuntimeStateManager;
67
- readonly runtimeAdapter: PDRuntimeAdapter;
68
- readonly eventEmitter: StoreEventEmitter;
62
+ export declare const DEFAULT_PHILOSOPHER_RUNNER_OPTIONS: Readonly<Omit<ResolvedPhilosopherRunnerOptions, 'owner' | 'runtimeKind'>>;
63
+ export declare function resolvePhilosopherRunnerOptions(options: PhilosopherRunnerOptions): ResolvedPhilosopherRunnerOptions;
64
+ export interface PhilosopherRunnerDeps extends PeerRunnerDeps {
69
65
  readonly validator: PhilosopherValidator;
70
- readonly artifactStore: PIArtifactStore;
71
66
  }
72
- export declare class PhilosopherRunner {
73
- private phase;
74
- private readonly resolvedOptions;
75
- private readonly stateManager;
76
- private readonly runtimeAdapter;
77
- private readonly eventEmitter;
67
+ export declare class PhilosopherRunner extends BasePeerRunner<PhilosopherContext, PhilosopherOutputV1> {
78
68
  private readonly validator;
79
- private readonly artifactStore;
80
- constructor(deps: PhilosopherRunnerDeps, options: PhilosopherRunnerOptions);
81
- get currentPhase(): RunnerPhase;
82
- private emitPhilosopherEvent;
83
- run(taskId: string): Promise<PhilosopherRunnerResult>;
84
- private buildContext;
85
- private static hashContextRefs;
86
- private resolveStoreRunId;
87
- private invokeRuntime;
88
- private pollUntilTerminal;
89
- private fetchAndParseOutput;
90
- private succeedTask;
91
- private handleRuntimeFailure;
92
- private handleValidationError;
93
- private handleLeaseOrPhaseError;
94
- private handlePostLeaseError;
95
- private retryOrFail;
96
- private readonly PERMANENT_ERROR_CATEGORIES;
97
- private isPermanentError;
98
- private classifyError;
99
- private mapRunStatusToErrorCategory;
100
- private sleep;
69
+ constructor(deps: PhilosopherRunnerDeps, options: PeerRunnerOptions);
70
+ get permanentErrorCategories(): ReadonlySet<PDErrorCategory>;
71
+ buildContext(taskId: string): Promise<PhilosopherContext>;
72
+ invokeRuntime(taskId: string, context: PhilosopherContext): Promise<RunHandle>;
73
+ validateOutput(output: unknown, taskId: string): Promise<PeerRunnerValidationResult>;
74
+ succeedTask(taskId: string, runId: string, output: PhilosopherOutputV1, task: TaskRecord, contextHash: string, context: PhilosopherContext): Promise<PeerRunnerResult<PhilosopherOutputV1>>;
75
+ /**
76
+ * Re-inject taskId if stripped by stripLineageFields (PRI-272 / ERR-008).
77
+ * Only fill when absent via Object.hasOwn — present-but-falsy values
78
+ * must reach validation and fail loud (Runtime Contract Rule 3).
79
+ */
80
+ protected postFetchTransform(taskId: string, untrustedOutput: unknown): void;
81
+ protected emitSuccessTelemetry(taskId: string, output: PhilosopherOutputV1): void;
101
82
  }
102
- export { resolvePhilosopherRunnerOptions, DEFAULT_PHILOSOPHER_RUNNER_OPTIONS };
83
+ export {};
103
84
  //# sourceMappingURL=philosopher-runner.d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