@principles/core 1.169.0 → 1.171.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/README.md +38 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/pain-signal.d.ts +11 -71
- package/dist/pain-signal.d.ts.map +1 -1
- package/dist/pain-signal.js +10 -120
- package/dist/pain-signal.js.map +1 -1
- package/dist/principle-tree-ledger.d.ts +4 -87
- package/dist/principle-tree-ledger.d.ts.map +1 -1
- package/dist/principle-tree-ledger.js +51 -148
- package/dist/principle-tree-ledger.js.map +1 -1
- package/dist/runtime-v2/__tests__/architecture-regression.test.js +178 -4
- package/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
- package/dist/runtime-v2/__tests__/barrel-io-cleanup.test.d.ts +12 -0
- package/dist/runtime-v2/__tests__/barrel-io-cleanup.test.d.ts.map +1 -0
- package/dist/runtime-v2/__tests__/barrel-io-cleanup.test.js +46 -0
- package/dist/runtime-v2/__tests__/barrel-io-cleanup.test.js.map +1 -0
- package/dist/runtime-v2/__tests__/io-deletion.test.d.ts +12 -0
- package/dist/runtime-v2/__tests__/io-deletion.test.d.ts.map +1 -0
- package/dist/runtime-v2/__tests__/io-deletion.test.js +92 -0
- package/dist/runtime-v2/__tests__/io-deletion.test.js.map +1 -0
- package/dist/runtime-v2/__tests__/ledger-codec.test.d.ts +2 -0
- package/dist/runtime-v2/__tests__/ledger-codec.test.d.ts.map +1 -0
- package/dist/runtime-v2/__tests__/ledger-codec.test.js +133 -0
- package/dist/runtime-v2/__tests__/ledger-codec.test.js.map +1 -0
- package/dist/runtime-v2/__tests__/ledger-store.test.d.ts +2 -0
- package/dist/runtime-v2/__tests__/ledger-store.test.d.ts.map +1 -0
- package/dist/runtime-v2/__tests__/ledger-store.test.js +65 -0
- package/dist/runtime-v2/__tests__/ledger-store.test.js.map +1 -0
- package/dist/runtime-v2/__tests__/pain-signal-unification.test.d.ts +2 -0
- package/dist/runtime-v2/__tests__/pain-signal-unification.test.d.ts.map +1 -0
- package/dist/runtime-v2/__tests__/pain-signal-unification.test.js +150 -0
- package/dist/runtime-v2/__tests__/pain-signal-unification.test.js.map +1 -0
- package/dist/runtime-v2/index.d.ts +1 -2
- package/dist/runtime-v2/index.d.ts.map +1 -1
- package/dist/runtime-v2/index.js +4 -2
- package/dist/runtime-v2/index.js.map +1 -1
- package/dist/runtime-v2/principle-tree/ledger-codec.d.ts +30 -0
- package/dist/runtime-v2/principle-tree/ledger-codec.d.ts.map +1 -0
- package/dist/runtime-v2/principle-tree/ledger-codec.js +154 -0
- package/dist/runtime-v2/principle-tree/ledger-codec.js.map +1 -0
- package/dist/runtime-v2/types/index.d.ts +2 -0
- package/dist/runtime-v2/types/index.d.ts.map +1 -1
- package/dist/runtime-v2/types/index.js +1 -0
- package/dist/runtime-v2/types/index.js.map +1 -1
- package/dist/runtime-v2/types/ledger-store.d.ts +101 -0
- package/dist/runtime-v2/types/ledger-store.d.ts.map +1 -0
- package/dist/runtime-v2/types/ledger-store.js +15 -0
- package/dist/runtime-v2/types/ledger-store.js.map +1 -0
- package/dist/runtime-v2/types/pain-signal.d.ts +5 -3
- package/dist/runtime-v2/types/pain-signal.d.ts.map +1 -1
- package/dist/runtime-v2/types/pain-signal.js +23 -3
- package/dist/runtime-v2/types/pain-signal.js.map +1 -1
- package/package.json +4 -4
- package/dist/io.d.ts +0 -35
- package/dist/io.d.ts.map +0 -1
- package/dist/io.js +0 -95
- package/dist/io.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# @principles/core
|
|
2
|
+
|
|
3
|
+
> **Pure logic only — no I/O.** This package must not import `fs`, `path`, or any
|
|
4
|
+
> I/O module. All filesystem/DB/network operations belong in `openclaw-plugin`.
|
|
5
|
+
|
|
6
|
+
## Boundary enforcement (PRI-450)
|
|
7
|
+
|
|
8
|
+
Three automated layers prevent I/O from leaking into core:
|
|
9
|
+
|
|
10
|
+
1. **Architecture-regression test** — `runtime-v2/__tests__/architecture-regression.test.ts`
|
|
11
|
+
scans every `.ts` file under `src/` for `fs`/`path` imports and compares against
|
|
12
|
+
an explicit whitelist (`ALLOWED_IO_FILES`). Any new I/O file must be added there.
|
|
13
|
+
|
|
14
|
+
2. **ESLint `no-restricted-imports`** — `eslint.config.js` bans `fs`/`path` imports
|
|
15
|
+
in `packages/principles-core/src/`. Whitelisted files and test files are exempt.
|
|
16
|
+
|
|
17
|
+
3. **PR template & AGENTS.md** — the PR checklist asks whether new `fs`/`path` imports
|
|
18
|
+
were added; AGENTS.md lists "writing I/O code in core" as an anti-pattern trigger.
|
|
19
|
+
|
|
20
|
+
### Adding a new I/O file (rare — prefer plugin)
|
|
21
|
+
|
|
22
|
+
If a core file genuinely needs I/O:
|
|
23
|
+
|
|
24
|
+
1. Add the file path to `ALLOWED_IO_FILES` in `architecture-regression.test.ts`
|
|
25
|
+
2. Add the file path to the exemption list in `eslint.config.js`
|
|
26
|
+
3. Explain in the PR why the I/O cannot live in `openclaw-plugin`
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install @principles/core
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
import { /* ... */ } from '@principles/core';
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
See `package.json` `exports` for available subpaths.
|
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,6 @@ export { PainSignalAdapter } from './pain-signal-adapter.js';
|
|
|
16
16
|
export { TelemetryEventSchema, validateTelemetryEvent } from './telemetry-event.js';
|
|
17
17
|
export type { TelemetryEvent, TelemetryEventValidationResult, TelemetryEventType } from './telemetry-event.js';
|
|
18
18
|
export { PrincipleInjector, DefaultPrincipleInjector, InjectionContext } from './principle-injector.js';
|
|
19
|
-
export { atomicWriteFileSync } from './io.js';
|
|
20
19
|
export { buildAttitudeDirective, detectCorrectionCue, extractMessageContent, isMinimalTrigger, truncateInjectionToBudget, } from './prompt-builder/index.js';
|
|
21
20
|
export type { PromptInjectionPart, SizeGuardOptions } from './prompt-builder/index.js';
|
|
22
21
|
export { matchEmpathyKeywords, createDefaultKeywordStore, applyKeywordUpdates, shouldTriggerOptimization, getKeywordStoreSummary, EMPATHY_SEED_KEYWORDS, DEFAULT_EMPATHY_KEYWORD_CONFIG, scoreToSeverity, severityToPenalty, normalizeSeverity, } from './prompt-builder/index.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACtG,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAG7D,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACpF,YAAY,EAAE,cAAc,EAAE,8BAA8B,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/G,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAGxG,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACtG,YAAY,EAAE,UAAU,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AAG/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;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AAoB,EAAE,MAAM,6BAA6B,CAAC;AACnE,YAAY,EACV,aAAa,EACb,cAAc,EACd,YAAY,EACZ,oBAAoB,GACrB,MAAM,6BAA6B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -16,8 +16,6 @@ export { PainSignalSchema, validatePainSignal, deriveSeverity, PainSeverity } fr
|
|
|
16
16
|
export { TelemetryEventSchema, validateTelemetryEvent } from './telemetry-event.js';
|
|
17
17
|
// PrincipleInjector interface and DefaultPrincipleInjector
|
|
18
18
|
export { DefaultPrincipleInjector } from './principle-injector.js';
|
|
19
|
-
// I/O utilities (D-03: atomicWriteFileSync for crash-safe writes)
|
|
20
|
-
export { atomicWriteFileSync } from './io.js';
|
|
21
19
|
// Prompt builder primitives — pure functions extracted from openclaw-plugin prompt hook (PRI-75)
|
|
22
20
|
export { buildAttitudeDirective, detectCorrectionCue, extractMessageContent, isMinimalTrigger, truncateInjectionToBudget, } from './prompt-builder/index.js';
|
|
23
21
|
// Prompt builder — empathy keyword matching (PRI-81 Phase A)
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mCAAmC;AACnC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAMtG,wBAAwB;AACxB,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAGpF,2DAA2D;AAC3D,OAAO,EAAqB,wBAAwB,EAAoB,MAAM,yBAAyB,CAAC;AAExG,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,mCAAmC;AACnC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB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76 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Pain signal schema — re-exported from runtime-v2/types/pain-signal.ts.
|
|
3
3
|
*
|
|
4
|
-
* This
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* cross-workspace evolution and multi-domain support.
|
|
4
|
+
* This file exists for backward compatibility with imports from
|
|
5
|
+
* @principles/core (top-level barrel). The canonical definition
|
|
6
|
+
* lives in runtime-v2/types/pain-signal.ts (PRI-443).
|
|
8
7
|
*
|
|
9
|
-
*
|
|
8
|
+
* The unified schema merges the stricter validations from both versions:
|
|
9
|
+
* - ISO 8601 timestamp format check
|
|
10
|
+
* - Context size limit (10KB)
|
|
11
|
+
* - version field with default
|
|
12
|
+
* - isStringRecord type guard (no `as` bypass)
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* Severity levels derived from pain score thresholds.
|
|
14
|
-
* - low: 0-39 (minor issue, informational)
|
|
15
|
-
* - medium: 40-69 (moderate error)
|
|
16
|
-
* - high: 70-89 (severe violation)
|
|
17
|
-
* - critical: 90-100 (systemic failure, spiral detected)
|
|
18
|
-
*/
|
|
19
|
-
export declare const PainSeverity: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"low">, import("@sinclair/typebox").TLiteral<"medium">, import("@sinclair/typebox").TLiteral<"high">, import("@sinclair/typebox").TLiteral<"critical">]>;
|
|
20
|
-
export type PainSeverity = Static<typeof PainSeverity>;
|
|
21
|
-
/**
|
|
22
|
-
* TypeBox schema for a universal pain signal.
|
|
23
|
-
*
|
|
24
|
-
* Every signal MUST have: source, score, timestamp, reason, sessionId,
|
|
25
|
-
* agentId, traceId, triggerTextPreview. Optional fields (domain, severity,
|
|
26
|
-
* context) default during validation.
|
|
27
|
-
*/
|
|
28
|
-
export declare const PainSignalSchema: import("@sinclair/typebox").TObject<{
|
|
29
|
-
/** What triggered this pain signal (e.g., 'tool_failure', 'human_intervention') */
|
|
30
|
-
source: import("@sinclair/typebox").TString;
|
|
31
|
-
/** Pain score 0-100 */
|
|
32
|
-
score: import("@sinclair/typebox").TNumber;
|
|
33
|
-
/** ISO 8601 timestamp */
|
|
34
|
-
timestamp: import("@sinclair/typebox").TString;
|
|
35
|
-
/** Human-readable reason / error description */
|
|
36
|
-
reason: import("@sinclair/typebox").TString;
|
|
37
|
-
/** Session ID — identifies which conversation this happened in */
|
|
38
|
-
sessionId: import("@sinclair/typebox").TString;
|
|
39
|
-
/** Agent ID — identifies which agent (main, builder, diagnostician, etc.) */
|
|
40
|
-
agentId: import("@sinclair/typebox").TString;
|
|
41
|
-
/** Correlation trace ID for linking events across the pipeline */
|
|
42
|
-
traceId: import("@sinclair/typebox").TString;
|
|
43
|
-
/** Preview of the text that triggered this pain */
|
|
44
|
-
triggerTextPreview: import("@sinclair/typebox").TString;
|
|
45
|
-
/** Schema version for forward compatibility (e.g., '0.1.0') */
|
|
46
|
-
version: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
47
|
-
/** Domain context (e.g., 'coding', 'writing', 'analysis') */
|
|
48
|
-
domain: import("@sinclair/typebox").TString;
|
|
49
|
-
/** Severity level derived from score */
|
|
50
|
-
severity: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"low">, import("@sinclair/typebox").TLiteral<"medium">, import("@sinclair/typebox").TLiteral<"high">, import("@sinclair/typebox").TLiteral<"critical">]>;
|
|
51
|
-
/** Additional structured context payload */
|
|
52
|
-
context: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnknown>;
|
|
53
|
-
}>;
|
|
54
|
-
export type PainSignal = Static<typeof PainSignalSchema>;
|
|
55
|
-
/**
|
|
56
|
-
* Derives severity from a numeric pain score.
|
|
57
|
-
*/
|
|
58
|
-
export declare function deriveSeverity(score: number): PainSeverity;
|
|
59
|
-
export interface PainSignalValidationResult {
|
|
60
|
-
valid: boolean;
|
|
61
|
-
errors: string[];
|
|
62
|
-
signal?: PainSignal;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Validates an arbitrary object against the PainSignal schema.
|
|
66
|
-
*
|
|
67
|
-
* Returns a structured result with:
|
|
68
|
-
* - `valid`: whether the input conforms to the schema
|
|
69
|
-
* - `errors`: human-readable list of validation failures
|
|
70
|
-
* - `signal`: the typed signal (only present when valid)
|
|
71
|
-
*
|
|
72
|
-
* Missing optional fields (domain, severity, context, version) are filled with defaults
|
|
73
|
-
* before validation so callers get a fully-formed signal back.
|
|
74
|
-
*/
|
|
75
|
-
export declare function validatePainSignal(input: unknown): PainSignalValidationResult;
|
|
14
|
+
export { PainSeverity, PainSignalSchema, deriveSeverity, validatePainSignal, } from './runtime-v2/types/pain-signal.js';
|
|
15
|
+
export type { PainSignal, PainSignalValidationResult, } from './runtime-v2/types/pain-signal.js';
|
|
76
16
|
//# sourceMappingURL=pain-signal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pain-signal.d.ts","sourceRoot":"","sources":["../src/pain-signal.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pain-signal.d.ts","sourceRoot":"","sources":["../src/pain-signal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,kBAAkB,GACnB,MAAM,mCAAmC,CAAC;AAE3C,YAAY,EACV,UAAU,EACV,0BAA0B,GAC3B,MAAM,mCAAmC,CAAC"}
|
package/dist/pain-signal.js
CHANGED
|
@@ -1,125 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Pain signal schema — re-exported from runtime-v2/types/pain-signal.ts.
|
|
3
3
|
*
|
|
4
|
-
* This
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* cross-workspace evolution and multi-domain support.
|
|
4
|
+
* This file exists for backward compatibility with imports from
|
|
5
|
+
* @principles/core (top-level barrel). The canonical definition
|
|
6
|
+
* lives in runtime-v2/types/pain-signal.ts (PRI-443).
|
|
8
7
|
*
|
|
9
|
-
*
|
|
8
|
+
* The unified schema merges the stricter validations from both versions:
|
|
9
|
+
* - ISO 8601 timestamp format check
|
|
10
|
+
* - Context size limit (10KB)
|
|
11
|
+
* - version field with default
|
|
12
|
+
* - isStringRecord type guard (no `as` bypass)
|
|
10
13
|
*/
|
|
11
|
-
|
|
12
|
-
import { Value } from '@sinclair/typebox/value';
|
|
13
|
-
// ---------------------------------------------------------------------------
|
|
14
|
-
// PainSignal Schema
|
|
15
|
-
// ---------------------------------------------------------------------------
|
|
16
|
-
/**
|
|
17
|
-
* Severity levels derived from pain score thresholds.
|
|
18
|
-
* - low: 0-39 (minor issue, informational)
|
|
19
|
-
* - medium: 40-69 (moderate error)
|
|
20
|
-
* - high: 70-89 (severe violation)
|
|
21
|
-
* - critical: 90-100 (systemic failure, spiral detected)
|
|
22
|
-
*/
|
|
23
|
-
export const PainSeverity = Type.Union([
|
|
24
|
-
Type.Literal('low'),
|
|
25
|
-
Type.Literal('medium'),
|
|
26
|
-
Type.Literal('high'),
|
|
27
|
-
Type.Literal('critical'),
|
|
28
|
-
]);
|
|
29
|
-
/**
|
|
30
|
-
* TypeBox schema for a universal pain signal.
|
|
31
|
-
*
|
|
32
|
-
* Every signal MUST have: source, score, timestamp, reason, sessionId,
|
|
33
|
-
* agentId, traceId, triggerTextPreview. Optional fields (domain, severity,
|
|
34
|
-
* context) default during validation.
|
|
35
|
-
*/
|
|
36
|
-
export const PainSignalSchema = Type.Object({
|
|
37
|
-
/** What triggered this pain signal (e.g., 'tool_failure', 'human_intervention') */
|
|
38
|
-
source: Type.String({ minLength: 1 }),
|
|
39
|
-
/** Pain score 0-100 */
|
|
40
|
-
score: Type.Number({ minimum: 0, maximum: 100 }),
|
|
41
|
-
/** ISO 8601 timestamp */
|
|
42
|
-
timestamp: Type.String({ minLength: 1 }),
|
|
43
|
-
/** Human-readable reason / error description */
|
|
44
|
-
reason: Type.String({ minLength: 1 }),
|
|
45
|
-
/** Session ID — identifies which conversation this happened in */
|
|
46
|
-
sessionId: Type.String({ minLength: 1 }),
|
|
47
|
-
/** Agent ID — identifies which agent (main, builder, diagnostician, etc.) */
|
|
48
|
-
agentId: Type.String({ minLength: 1 }),
|
|
49
|
-
/** Correlation trace ID for linking events across the pipeline */
|
|
50
|
-
traceId: Type.String({ minLength: 1 }),
|
|
51
|
-
/** Preview of the text that triggered this pain */
|
|
52
|
-
triggerTextPreview: Type.String(),
|
|
53
|
-
/** Schema version for forward compatibility (e.g., '0.1.0') */
|
|
54
|
-
version: Type.Optional(Type.String({ default: '0.1.0' })),
|
|
55
|
-
/** Domain context (e.g., 'coding', 'writing', 'analysis') */
|
|
56
|
-
domain: Type.String({ default: 'coding' }),
|
|
57
|
-
/** Severity level derived from score */
|
|
58
|
-
severity: PainSeverity,
|
|
59
|
-
/** Additional structured context payload */
|
|
60
|
-
context: Type.Record(Type.String(), Type.Unknown()),
|
|
61
|
-
});
|
|
62
|
-
// ---------------------------------------------------------------------------
|
|
63
|
-
// Default Derivation
|
|
64
|
-
// ---------------------------------------------------------------------------
|
|
65
|
-
/**
|
|
66
|
-
* Derives severity from a numeric pain score.
|
|
67
|
-
*/
|
|
68
|
-
export function deriveSeverity(score) {
|
|
69
|
-
if (score >= 90)
|
|
70
|
-
return 'critical';
|
|
71
|
-
if (score >= 70)
|
|
72
|
-
return 'high';
|
|
73
|
-
if (score >= 40)
|
|
74
|
-
return 'medium';
|
|
75
|
-
return 'low';
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Validates an arbitrary object against the PainSignal schema.
|
|
79
|
-
*
|
|
80
|
-
* Returns a structured result with:
|
|
81
|
-
* - `valid`: whether the input conforms to the schema
|
|
82
|
-
* - `errors`: human-readable list of validation failures
|
|
83
|
-
* - `signal`: the typed signal (only present when valid)
|
|
84
|
-
*
|
|
85
|
-
* Missing optional fields (domain, severity, context, version) are filled with defaults
|
|
86
|
-
* before validation so callers get a fully-formed signal back.
|
|
87
|
-
*/
|
|
88
|
-
export function validatePainSignal(input) {
|
|
89
|
-
if (typeof input !== 'object' || input === null || Array.isArray(input)) {
|
|
90
|
-
return { valid: false, errors: ['Input must be a non-null object'] };
|
|
91
|
-
}
|
|
92
|
-
const raw = input;
|
|
93
|
-
// Apply defaults for optional fields before validation
|
|
94
|
-
const hydrated = {
|
|
95
|
-
...raw,
|
|
96
|
-
domain: raw.domain ?? 'coding',
|
|
97
|
-
version: raw.version ?? '0.1.0',
|
|
98
|
-
severity: raw.severity ?? deriveSeverity(typeof raw.score === 'number' ? raw.score : 0),
|
|
99
|
-
context: raw.context ?? {},
|
|
100
|
-
};
|
|
101
|
-
// Security: enforce context size limit to prevent memory exhaustion
|
|
102
|
-
const MAX_CONTEXT_SIZE = 10_000;
|
|
103
|
-
if (JSON.stringify(hydrated.context).length > MAX_CONTEXT_SIZE) {
|
|
104
|
-
return { valid: false, errors: ['Context object exceeds maximum size (10KB)'] };
|
|
105
|
-
}
|
|
106
|
-
// Validate ISO 8601 timestamp format
|
|
107
|
-
if (typeof hydrated.timestamp === 'string' &&
|
|
108
|
-
isNaN(Date.parse(hydrated.timestamp))) {
|
|
109
|
-
return { valid: false, errors: ['timestamp must be a valid ISO 8601 date string'] };
|
|
110
|
-
}
|
|
111
|
-
// Collect TypeBox errors using Decode (strict, not Cast which coerces)
|
|
112
|
-
const errors = [...Value.Errors(PainSignalSchema, hydrated)];
|
|
113
|
-
if (errors.length > 0) {
|
|
114
|
-
return {
|
|
115
|
-
valid: false,
|
|
116
|
-
errors: errors.map((e) => `${e.path ? `${e.path}: ` : ''}${e.message}`),
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
return {
|
|
120
|
-
valid: true,
|
|
121
|
-
errors: [],
|
|
122
|
-
signal: Value.Cast(PainSignalSchema, hydrated),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
14
|
+
export { PainSeverity, PainSignalSchema, deriveSeverity, validatePainSignal, } from './runtime-v2/types/pain-signal.js';
|
|
125
15
|
//# sourceMappingURL=pain-signal.js.map
|
package/dist/pain-signal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pain-signal.js","sourceRoot":"","sources":["../src/pain-signal.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"pain-signal.js","sourceRoot":"","sources":["../src/pain-signal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,cAAc,EACd,kBAAkB,GACnB,MAAM,mCAAmC,CAAC"}
|
|
@@ -10,93 +10,10 @@
|
|
|
10
10
|
* M8 key insight: ledger operations are single-process. No cross-process
|
|
11
11
|
* locking needed for pd-cli usage. The file write is atomic (rename).
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export type
|
|
16
|
-
export
|
|
17
|
-
export interface Principle {
|
|
18
|
-
id: string;
|
|
19
|
-
version: number;
|
|
20
|
-
text: string;
|
|
21
|
-
triggerPattern: string;
|
|
22
|
-
action: string;
|
|
23
|
-
status: PrincipleStatus;
|
|
24
|
-
priority: PrinciplePriority;
|
|
25
|
-
scope: PrincipleScope;
|
|
26
|
-
evaluability: PrincipleEvaluability;
|
|
27
|
-
valueScore: number;
|
|
28
|
-
adherenceRate: number;
|
|
29
|
-
painPreventedCount: number;
|
|
30
|
-
derivedFromPainIds: string[];
|
|
31
|
-
ruleIds: string[];
|
|
32
|
-
conflictsWithPrincipleIds: string[];
|
|
33
|
-
createdAt: string;
|
|
34
|
-
updatedAt: string;
|
|
35
|
-
}
|
|
36
|
-
export interface Rule {
|
|
37
|
-
id: string;
|
|
38
|
-
principleId: string;
|
|
39
|
-
ruleIds: string[];
|
|
40
|
-
implementationIds: string[];
|
|
41
|
-
type?: string;
|
|
42
|
-
status?: string;
|
|
43
|
-
lifecycleState?: string;
|
|
44
|
-
createdAt?: string;
|
|
45
|
-
updatedAt?: string;
|
|
46
|
-
}
|
|
47
|
-
export interface Implementation {
|
|
48
|
-
id: string;
|
|
49
|
-
ruleId: string;
|
|
50
|
-
type?: string;
|
|
51
|
-
lifecycleState?: string;
|
|
52
|
-
[key: string]: unknown;
|
|
53
|
-
}
|
|
54
|
-
export interface PrincipleValueMetrics {
|
|
55
|
-
principleId: string;
|
|
56
|
-
painPreventedCount?: number;
|
|
57
|
-
lastPainPreventedAt?: string;
|
|
58
|
-
avgPainSeverityPrevented?: number;
|
|
59
|
-
totalOpportunities?: number;
|
|
60
|
-
adheredCount?: number;
|
|
61
|
-
violatedCount?: number;
|
|
62
|
-
implementationCost?: number;
|
|
63
|
-
benefitScore?: number;
|
|
64
|
-
calculatedAt?: string;
|
|
65
|
-
}
|
|
66
|
-
export interface LedgerPrinciple extends Principle {
|
|
67
|
-
suggestedRules?: string[];
|
|
68
|
-
lastTriggeredAt?: string;
|
|
69
|
-
}
|
|
70
|
-
export interface LedgerRule extends Rule {
|
|
71
|
-
implementationIds: string[];
|
|
72
|
-
}
|
|
73
|
-
export interface LedgerTreeStore {
|
|
74
|
-
principles: Record<string, LedgerPrinciple>;
|
|
75
|
-
rules: Record<string, LedgerRule>;
|
|
76
|
-
implementations: Record<string, Implementation>;
|
|
77
|
-
metrics: Record<string, PrincipleValueMetrics>;
|
|
78
|
-
lastUpdated: string;
|
|
79
|
-
}
|
|
80
|
-
export interface LegacyPrincipleTrainingState {
|
|
81
|
-
principleId: string;
|
|
82
|
-
evaluability: 'deterministic' | 'weak_heuristic' | 'manual_only';
|
|
83
|
-
applicableOpportunityCount: number;
|
|
84
|
-
observedViolationCount: number;
|
|
85
|
-
complianceRate: number;
|
|
86
|
-
violationTrend: number;
|
|
87
|
-
generatedSampleCount: number;
|
|
88
|
-
approvedSampleCount: number;
|
|
89
|
-
includedTrainRunIds: string[];
|
|
90
|
-
deployedCheckpointIds: string[];
|
|
91
|
-
lastEvalScore?: number;
|
|
92
|
-
internalizationStatus: 'prompt_only' | 'needs_training' | 'in_training' | 'deployed_pending_eval' | 'internalized' | 'regressed';
|
|
93
|
-
}
|
|
94
|
-
export type LegacyPrincipleTrainingStore = Record<string, LegacyPrincipleTrainingState>;
|
|
95
|
-
export interface HybridLedgerStore {
|
|
96
|
-
trainingStore: LegacyPrincipleTrainingStore;
|
|
97
|
-
tree: LedgerTreeStore;
|
|
98
|
-
}
|
|
99
|
-
export declare const TREE_NAMESPACE = "_tree";
|
|
13
|
+
import type { Principle, Rule, Implementation, PrincipleValueMetrics, LedgerPrinciple, LedgerRule, LedgerTreeStore, LegacyPrincipleTrainingState, LegacyPrincipleTrainingStore, HybridLedgerStore } from './runtime-v2/types/ledger-store.js';
|
|
14
|
+
import { TREE_NAMESPACE } from './runtime-v2/types/ledger-store.js';
|
|
15
|
+
export type { Principle, Rule, Implementation, PrincipleValueMetrics, LedgerPrinciple, LedgerRule, LedgerTreeStore, LegacyPrincipleTrainingState, LegacyPrincipleTrainingStore, HybridLedgerStore, };
|
|
16
|
+
export { TREE_NAMESPACE };
|
|
100
17
|
export declare function loadLedger(stateDir: string): HybridLedgerStore;
|
|
101
18
|
export declare function saveLedger(stateDir: string, store: HybridLedgerStore): void;
|
|
102
19
|
export declare function addPrincipleToLedger(stateDir: string, principle: LedgerPrinciple): LedgerPrinciple;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"principle-tree-ledger.d.ts","sourceRoot":"","sources":["../src/principle-tree-ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;
|
|
1
|
+
{"version":3,"file":"principle-tree-ledger.d.ts","sourceRoot":"","sources":["../src/principle-tree-ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAMH,OAAO,KAAK,EACV,SAAS,EACT,IAAI,EACJ,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,eAAe,EACf,4BAA4B,EAC5B,4BAA4B,EAC5B,iBAAiB,EAClB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAYpE,YAAY,EACV,SAAS,EACT,IAAI,EACJ,cAAc,EACd,qBAAqB,EACrB,eAAe,EACf,UAAU,EACV,eAAe,EACf,4BAA4B,EAC5B,4BAA4B,EAC5B,iBAAiB,GAClB,CAAC;AACF,OAAO,EAAE,cAAc,EAAE,CAAC;AAkG1B,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,iBAAiB,CAE9D;AAED,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,IAAI,CAK3E;AAED,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,eAAe,CAMlG;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,CAiBzH;AAED,wBAAgB,2BAA2B,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,qBAAqB,GAAG,qBAAqB,CAMxI;AAED,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEhE"}
|