@namzu/sdk 55.0.0 → 56.0.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/CHANGELOG.md +23 -0
- package/dist/compaction/serializer.d.ts.map +1 -1
- package/dist/compaction/serializer.js +27 -15
- package/dist/compaction/serializer.js.map +1 -1
- package/dist/compaction/verifier.d.ts.map +1 -1
- package/dist/compaction/verifier.js +3 -2
- package/dist/compaction/verifier.js.map +1 -1
- package/dist/constants/compaction/index.d.ts +3 -1
- package/dist/constants/compaction/index.d.ts.map +1 -1
- package/dist/constants/compaction/index.js +3 -1
- package/dist/constants/compaction/index.js.map +1 -1
- package/dist/{manager/resident/learning-cycle.d.ts → learning/cycle.d.ts} +45 -36
- package/dist/learning/cycle.d.ts.map +1 -0
- package/dist/{manager/resident/learning-cycle.js → learning/cycle.js} +52 -20
- package/dist/learning/cycle.js.map +1 -0
- package/dist/learning/deprecated.d.ts +86 -0
- package/dist/learning/deprecated.d.ts.map +1 -0
- package/dist/learning/deprecated.js +22 -0
- package/dist/learning/deprecated.js.map +1 -0
- package/dist/learning/experience-store.d.ts +35 -0
- package/dist/learning/experience-store.d.ts.map +1 -0
- package/dist/learning/experience-store.js +143 -0
- package/dist/learning/experience-store.js.map +1 -0
- package/dist/learning/experience.d.ts +150 -0
- package/dist/learning/experience.d.ts.map +1 -0
- package/dist/learning/experience.js +146 -0
- package/dist/learning/experience.js.map +1 -0
- package/dist/learning/generator.d.ts +118 -0
- package/dist/learning/generator.d.ts.map +1 -0
- package/dist/learning/generator.js +275 -0
- package/dist/learning/generator.js.map +1 -0
- package/dist/learning/leak-tripwire.d.ts +66 -0
- package/dist/learning/leak-tripwire.d.ts.map +1 -0
- package/dist/learning/leak-tripwire.js +208 -0
- package/dist/learning/leak-tripwire.js.map +1 -0
- package/dist/{manager/resident/learning-observation.d.ts → learning/observation.d.ts} +4 -4
- package/dist/learning/observation.d.ts.map +1 -0
- package/dist/{manager/resident/learning-observation.js → learning/observation.js} +3 -3
- package/dist/learning/observation.js.map +1 -0
- package/dist/{manager/resident/learning.d.ts → learning/skill.d.ts} +29 -29
- package/dist/learning/skill.d.ts.map +1 -0
- package/dist/{manager/resident/learning.js → learning/skill.js} +27 -27
- package/dist/learning/skill.js.map +1 -0
- package/dist/{manager/resident/learning-store.d.ts → learning/store.d.ts} +38 -31
- package/dist/learning/store.d.ts.map +1 -0
- package/dist/{manager/resident/learning-store.js → learning/store.js} +52 -20
- package/dist/learning/store.js.map +1 -0
- package/dist/manager/resident/activity.d.ts +30 -6
- package/dist/manager/resident/activity.d.ts.map +1 -1
- package/dist/manager/resident/activity.js.map +1 -1
- package/dist/manager/resident/agenda.d.ts +42 -12
- package/dist/manager/resident/agenda.d.ts.map +1 -1
- package/dist/manager/resident/agenda.js +9 -7
- package/dist/manager/resident/agenda.js.map +1 -1
- package/dist/manager/resident/consumption.d.ts +27 -5
- package/dist/manager/resident/consumption.d.ts.map +1 -1
- package/dist/manager/resident/consumption.js +2 -0
- package/dist/manager/resident/consumption.js.map +1 -1
- package/dist/manager/resident/delivery-window.d.ts +7 -1
- package/dist/manager/resident/delivery-window.d.ts.map +1 -1
- package/dist/manager/resident/delivery-window.js +2 -0
- package/dist/manager/resident/delivery-window.js.map +1 -1
- package/dist/manager/resident/evidence-recall.d.ts +7 -1
- package/dist/manager/resident/evidence-recall.d.ts.map +1 -1
- package/dist/manager/resident/evidence-recall.js +2 -0
- package/dist/manager/resident/evidence-recall.js.map +1 -1
- package/dist/manager/resident/history.d.ts +45 -9
- package/dist/manager/resident/history.d.ts.map +1 -1
- package/dist/manager/resident/history.js.map +1 -1
- package/dist/manager/resident/host.d.ts +44 -10
- package/dist/manager/resident/host.d.ts.map +1 -1
- package/dist/manager/resident/host.js +4 -2
- package/dist/manager/resident/host.js.map +1 -1
- package/dist/manager/resident/initiative.d.ts +32 -6
- package/dist/manager/resident/initiative.d.ts.map +1 -1
- package/dist/manager/resident/initiative.js +2 -0
- package/dist/manager/resident/initiative.js.map +1 -1
- package/dist/manager/resident/loop.d.ts +22 -4
- package/dist/manager/resident/loop.d.ts.map +1 -1
- package/dist/manager/resident/loop.js +7 -1
- package/dist/manager/resident/loop.js.map +1 -1
- package/dist/manager/resident/outbox.d.ts +42 -8
- package/dist/manager/resident/outbox.d.ts.map +1 -1
- package/dist/manager/resident/outbox.js +2 -0
- package/dist/manager/resident/outbox.js.map +1 -1
- package/dist/manager/resident/proposal.d.ts +17 -3
- package/dist/manager/resident/proposal.d.ts.map +1 -1
- package/dist/manager/resident/proposal.js +2 -0
- package/dist/manager/resident/proposal.js.map +1 -1
- package/dist/manager/resident/store.d.ts +27 -5
- package/dist/manager/resident/store.d.ts.map +1 -1
- package/dist/manager/resident/store.js +7 -1
- package/dist/manager/resident/store.js.map +1 -1
- package/dist/manager/resident/tool-evidence.d.ts +45 -9
- package/dist/manager/resident/tool-evidence.d.ts.map +1 -1
- package/dist/manager/resident/tool-evidence.js +5 -1
- package/dist/manager/resident/tool-evidence.js.map +1 -1
- package/dist/prompt/resident-learning.d.ts +12 -2
- package/dist/prompt/resident-learning.d.ts.map +1 -1
- package/dist/prompt/resident-learning.js +6 -5
- package/dist/prompt/resident-learning.js.map +1 -1
- package/dist/prompt/resident-step.d.ts +10 -4
- package/dist/prompt/resident-step.d.ts.map +1 -1
- package/dist/prompt/resident-step.js +6 -4
- package/dist/prompt/resident-step.js.map +1 -1
- package/dist/public-runtime.d.ts +9 -3
- package/dist/public-runtime.d.ts.map +1 -1
- package/dist/public-runtime.js +10 -3
- package/dist/public-runtime.js.map +1 -1
- package/dist/public-types.d.ts +9 -4
- package/dist/public-types.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-context.d.ts +4 -0
- package/dist/runtime/query/file-evidence-context.d.ts.map +1 -1
- package/dist/runtime/query/file-evidence-context.js +5 -1
- package/dist/runtime/query/file-evidence-context.js.map +1 -1
- package/dist/runtime/query/iteration/index.d.ts +2 -0
- package/dist/runtime/query/iteration/index.d.ts.map +1 -1
- package/dist/runtime/query/iteration/index.js +19 -11
- package/dist/runtime/query/iteration/index.js.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts +9 -0
- package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/per-call-review.js +19 -0
- package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.d.ts.map +1 -1
- package/dist/runtime/query/iteration/phases/tool-review.js +4 -1
- package/dist/runtime/query/iteration/phases/tool-review.js.map +1 -1
- package/dist/runtime/query/iteration/step-context.d.ts +42 -0
- package/dist/runtime/query/iteration/step-context.d.ts.map +1 -1
- package/dist/runtime/query/iteration/step-context.js +114 -0
- package/dist/runtime/query/iteration/step-context.js.map +1 -1
- package/dist/runtime/query/iteration/step-shaping.d.ts +9 -1
- package/dist/runtime/query/iteration/step-shaping.d.ts.map +1 -1
- package/dist/runtime/query/iteration/step-shaping.js +21 -11
- package/dist/runtime/query/iteration/step-shaping.js.map +1 -1
- package/dist/runtime/query/steering.d.ts +13 -0
- package/dist/runtime/query/steering.d.ts.map +1 -1
- package/dist/runtime/query/steering.js +42 -0
- package/dist/runtime/query/steering.js.map +1 -1
- package/dist/scheduler/completion-inbox.js +1 -1
- package/dist/scheduler/completion-inbox.js.map +1 -1
- package/dist/tools/builtins/bash.d.ts +3 -5
- package/dist/tools/builtins/bash.d.ts.map +1 -1
- package/dist/tools/builtins/bash.js +14 -15
- package/dist/tools/builtins/bash.js.map +1 -1
- package/dist/tools/builtins/edit.js +1 -1
- package/dist/tools/builtins/edit.js.map +1 -1
- package/dist/tools/env-scrub.d.ts +8 -0
- package/dist/tools/env-scrub.d.ts.map +1 -1
- package/dist/tools/env-scrub.js +13 -0
- package/dist/tools/env-scrub.js.map +1 -1
- package/dist/tools/resident-history.d.ts +2 -0
- package/dist/tools/resident-history.d.ts.map +1 -1
- package/dist/tools/resident-history.js +2 -0
- package/dist/tools/resident-history.js.map +1 -1
- package/dist/tools/resident-tool-evidence.d.ts +5 -1
- package/dist/tools/resident-tool-evidence.d.ts.map +1 -1
- package/dist/tools/resident-tool-evidence.js +5 -1
- package/dist/tools/resident-tool-evidence.js.map +1 -1
- package/dist/turn/evidence-recall.d.ts +15 -3
- package/dist/turn/evidence-recall.d.ts.map +1 -1
- package/dist/turn/evidence-recall.js +116 -27
- package/dist/turn/evidence-recall.js.map +1 -1
- package/dist/types/message/notice-frame.d.ts +1 -1
- package/dist/types/message/notice-frame.d.ts.map +1 -1
- package/dist/types/message/notice-frame.js +1 -0
- package/dist/types/message/notice-frame.js.map +1 -1
- package/package.json +1 -1
- package/src/compaction/serializer.ts +29 -17
- package/src/compaction/verifier.ts +3 -2
- package/src/constants/compaction/index.ts +3 -1
- package/src/{manager/resident/learning-cycle.ts → learning/cycle.ts} +130 -78
- package/src/learning/deprecated.ts +124 -0
- package/src/learning/experience-store.ts +202 -0
- package/src/learning/experience.ts +238 -0
- package/src/learning/generator.ts +388 -0
- package/src/learning/leak-tripwire.ts +280 -0
- package/src/{manager/resident/learning-observation.ts → learning/observation.ts} +5 -5
- package/src/{manager/resident/learning.ts → learning/skill.ts} +64 -67
- package/src/{manager/resident/learning-store.ts → learning/store.ts} +97 -67
- package/src/manager/resident/activity.ts +30 -6
- package/src/manager/resident/agenda.ts +63 -33
- package/src/manager/resident/consumption.ts +27 -5
- package/src/manager/resident/delivery-window.ts +7 -1
- package/src/manager/resident/evidence-recall.ts +7 -1
- package/src/manager/resident/history.ts +45 -9
- package/src/manager/resident/host.ts +45 -11
- package/src/manager/resident/initiative.ts +32 -6
- package/src/manager/resident/loop.ts +22 -4
- package/src/manager/resident/outbox.ts +42 -8
- package/src/manager/resident/proposal.ts +17 -3
- package/src/manager/resident/store.ts +27 -5
- package/src/manager/resident/tool-evidence.ts +45 -9
- package/src/prompt/resident-learning.ts +16 -7
- package/src/prompt/resident-step.ts +19 -13
- package/src/public-runtime.ts +35 -5
- package/src/public-types.ts +96 -34
- package/src/runtime/query/file-evidence-context.ts +8 -1
- package/src/runtime/query/iteration/index.ts +27 -13
- package/src/runtime/query/iteration/phases/per-call-review.ts +19 -0
- package/src/runtime/query/iteration/phases/tool-review.ts +3 -0
- package/src/runtime/query/iteration/step-context.ts +138 -0
- package/src/runtime/query/iteration/step-shaping.ts +39 -13
- package/src/runtime/query/steering.ts +51 -0
- package/src/scheduler/completion-inbox.ts +1 -1
- package/src/tools/builtins/bash.ts +14 -14
- package/src/tools/builtins/edit.ts +1 -1
- package/src/tools/env-scrub.ts +13 -0
- package/src/tools/resident-history.ts +2 -0
- package/src/tools/resident-tool-evidence.ts +5 -1
- package/src/turn/evidence-recall.ts +125 -30
- package/src/types/message/notice-frame.ts +3 -1
- package/dist/manager/resident/learning-cycle.d.ts.map +0 -1
- package/dist/manager/resident/learning-cycle.js.map +0 -1
- package/dist/manager/resident/learning-observation.d.ts.map +0 -1
- package/dist/manager/resident/learning-observation.js.map +0 -1
- package/dist/manager/resident/learning-store.d.ts.map +0 -1
- package/dist/manager/resident/learning-store.js.map +0 -1
- package/dist/manager/resident/learning.d.ts.map +0 -1
- package/dist/manager/resident/learning.js.map +0 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { randomBytes } from 'node:crypto';
|
|
2
|
+
/** @experimental Thrown for a leak. It is a leak, not a false positive: do not retry past it. */
|
|
3
|
+
export class LearningLeakError extends Error {
|
|
4
|
+
findings;
|
|
5
|
+
constructor(findings) {
|
|
6
|
+
super(describeLeak(findings));
|
|
7
|
+
this.name = 'LearningLeakError';
|
|
8
|
+
this.findings = findings;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
const MIN_PROTECTED_LENGTH = 12;
|
|
12
|
+
const MAX_SCAN_CHARS = 1_000_000;
|
|
13
|
+
const DEFAULT_MARKERS = [
|
|
14
|
+
['grader-verdict', /\b(?:grader|judge|evaluator|scorer)[\s_-]*verdicts?\b/i],
|
|
15
|
+
['answer-key', /\b(?:answer[\s_-]*key|expected[\s_-]*answers?|reference[\s_-]*answers?)\b/i],
|
|
16
|
+
[
|
|
17
|
+
'protection-fixture',
|
|
18
|
+
/\bprotection[\s_-]*(?:task|fixture)[\s_-]*(?:contents?|prompts?|answers?)\b/i,
|
|
19
|
+
],
|
|
20
|
+
['hidden-rubric', /\b(?:hidden|private|held[\s_-]*out)[\s_-]*(?:rubric|test[\s_-]*cases?)\b/i],
|
|
21
|
+
];
|
|
22
|
+
const DEFAULT_SECRETS = [
|
|
23
|
+
['private-key', /-----BEGIN [A-Z ]*PRIVATE KEY-----/],
|
|
24
|
+
['api-key', /\bsk-[A-Za-z0-9_-]{20,}/],
|
|
25
|
+
['cloud-key', /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/],
|
|
26
|
+
['token', /\b(?:gh[pousr]_[A-Za-z0-9]{30,}|xox[abprs]-[A-Za-z0-9-]{10,})/],
|
|
27
|
+
['bearer', /\bBearer\s+[A-Za-z0-9._~+/-]{24,}=*/],
|
|
28
|
+
];
|
|
29
|
+
/** @experimental A fresh canary to plant in evaluator data. It matches nothing else. */
|
|
30
|
+
export function createLearningCanary() {
|
|
31
|
+
return `namzu-canary-${randomBytes(12).toString('hex')}`;
|
|
32
|
+
}
|
|
33
|
+
/** Fold case, zero-width characters and whitespace runs so spacing tricks do not hide a match. */
|
|
34
|
+
function fold(text) {
|
|
35
|
+
return text.replace(/[-]/g, '').replace(/\s+/g, ' ').toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
function globToRegExp(glob) {
|
|
38
|
+
let out = '';
|
|
39
|
+
for (let i = 0; i < glob.length; i++) {
|
|
40
|
+
const c = glob[i];
|
|
41
|
+
if (c === '*') {
|
|
42
|
+
if (glob[i + 1] === '*') {
|
|
43
|
+
i++;
|
|
44
|
+
if (glob[i + 1] === '/') {
|
|
45
|
+
i++;
|
|
46
|
+
out += '(?:.*/)?';
|
|
47
|
+
}
|
|
48
|
+
else
|
|
49
|
+
out += '.*';
|
|
50
|
+
}
|
|
51
|
+
else
|
|
52
|
+
out += '[^/]*';
|
|
53
|
+
}
|
|
54
|
+
else if (c === '?')
|
|
55
|
+
out += '[^/]';
|
|
56
|
+
else
|
|
57
|
+
out += c.replace(/[.+^${}()|[\]\\]/g, '\\$&');
|
|
58
|
+
}
|
|
59
|
+
return new RegExp(`^${out}$`);
|
|
60
|
+
}
|
|
61
|
+
function normalizePath(path) {
|
|
62
|
+
return path
|
|
63
|
+
.replace(/\\/g, '/')
|
|
64
|
+
.replace(/^(?:\.\/)+/, '')
|
|
65
|
+
.replace(/\/{2,}/g, '/');
|
|
66
|
+
}
|
|
67
|
+
/** Tokens of a text that look like locations, so a path glob can be tried on them. */
|
|
68
|
+
function pathTokens(text) {
|
|
69
|
+
return text
|
|
70
|
+
.split(/[\s"'`<>()[\]{},;|=]+/)
|
|
71
|
+
.map((token) => normalizePath(token.replace(/[:.]+$/, '')))
|
|
72
|
+
.filter((token) => token.length > 0 && token.length < 512);
|
|
73
|
+
}
|
|
74
|
+
/** Plain-text forms, matched against the folded (lowercased) text. Hex is case-insensitive that way. */
|
|
75
|
+
function plainForms(canary) {
|
|
76
|
+
return [fold(canary), Buffer.from(canary, 'utf8').toString('hex')];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Base64 forms of the canary at each of the three alignments it can have inside
|
|
80
|
+
* a larger encoded blob, in standard and url-safe alphabets. The characters
|
|
81
|
+
* that depend on the bytes before or after the canary are dropped, so what is
|
|
82
|
+
* left is identical wherever the canary sits. Matched case-sensitively.
|
|
83
|
+
*/
|
|
84
|
+
function base64Forms(canary) {
|
|
85
|
+
const forms = new Set();
|
|
86
|
+
const body = Buffer.from(canary, 'utf8');
|
|
87
|
+
for (let lead = 0; lead < 3; lead++) {
|
|
88
|
+
const encoded = Buffer.concat([Buffer.alloc(lead, 0x78), body]).toString('base64');
|
|
89
|
+
const unpadded = encoded.replace(/=+$/, '');
|
|
90
|
+
const trailing = (lead + body.length) % 3 === 0 ? 0 : 1;
|
|
91
|
+
const stable = unpadded.slice(lead === 0 ? 0 : lead + 1, unpadded.length - trailing);
|
|
92
|
+
if (stable.length < 8)
|
|
93
|
+
continue;
|
|
94
|
+
forms.add(stable);
|
|
95
|
+
forms.add(stable.replace(/\+/g, '-').replace(/\//g, '_'));
|
|
96
|
+
}
|
|
97
|
+
return [...forms];
|
|
98
|
+
}
|
|
99
|
+
/** Text with whitespace and zero-width characters removed, so wrapped base64 still matches. */
|
|
100
|
+
function compact(text) {
|
|
101
|
+
return text.replace(/[\u200b-\u200f\u2060\ufeff]/g, '').replace(/\s+/g, '');
|
|
102
|
+
}
|
|
103
|
+
function stripZeroWidth(text) {
|
|
104
|
+
return text.replace(/[\u200b-\u200f\u2060\ufeff]/g, '');
|
|
105
|
+
}
|
|
106
|
+
function compile(guard) {
|
|
107
|
+
const markers = [
|
|
108
|
+
...DEFAULT_MARKERS.map(([n, r]) => [`default:${n}`, r]),
|
|
109
|
+
];
|
|
110
|
+
for (const [i, marker] of (guard.markers ?? []).entries()) {
|
|
111
|
+
if (typeof marker !== 'string' && marker.global)
|
|
112
|
+
throw new Error('A leak marker must not be a global RegExp.');
|
|
113
|
+
const escaped = typeof marker === 'string'
|
|
114
|
+
? new RegExp(fold(marker).replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))
|
|
115
|
+
: marker;
|
|
116
|
+
markers.push([`marker[${i}]`, escaped]);
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
paths: (guard.paths ?? []).map((g, i) => [`path[${i}]`, globToRegExp(normalizePath(g))]),
|
|
120
|
+
canaries: (guard.canaries ?? []).map((c, i) => {
|
|
121
|
+
if (fold(c).length < 8)
|
|
122
|
+
throw new Error('A leak canary must be at least 8 characters.');
|
|
123
|
+
return [`canary[${i}]`, plainForms(c), base64Forms(c)];
|
|
124
|
+
}),
|
|
125
|
+
markers,
|
|
126
|
+
protectedContents: (guard.protectedContents ?? []).flatMap((c, i) => {
|
|
127
|
+
const folded = fold(c).trim();
|
|
128
|
+
if (folded.length < MIN_PROTECTED_LENGTH)
|
|
129
|
+
throw new Error(`Protected content must be at least ${MIN_PROTECTED_LENGTH} characters; shorter text matches innocently.`);
|
|
130
|
+
return [[`protected-content[${i}]`, folded]];
|
|
131
|
+
}),
|
|
132
|
+
secrets: (guard.secrets ?? []).flatMap((s, i) => {
|
|
133
|
+
if (s.length < 8)
|
|
134
|
+
throw new Error('A literal secret to guard must be at least 8 characters.');
|
|
135
|
+
return [[`secret[${i}]`, s]];
|
|
136
|
+
}),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* @experimental Inspect each subject against the guard (the built-in markers
|
|
141
|
+
* and secret shapes always apply). Returns every finding; empty means nothing
|
|
142
|
+
* was seen, which is not a proof that nothing leaked.
|
|
143
|
+
*/
|
|
144
|
+
export function scanForLearningLeak(guard, subjects) {
|
|
145
|
+
const compiled = compile(guard ?? {});
|
|
146
|
+
const findings = [];
|
|
147
|
+
const seen = new Set();
|
|
148
|
+
const add = (kind, subject, rule) => {
|
|
149
|
+
const key = `${kind}|${subject}|${rule}`;
|
|
150
|
+
if (seen.has(key))
|
|
151
|
+
return;
|
|
152
|
+
seen.add(key);
|
|
153
|
+
findings.push({ kind, subject, rule });
|
|
154
|
+
};
|
|
155
|
+
for (const item of subjects) {
|
|
156
|
+
for (const path of item.paths ?? []) {
|
|
157
|
+
const normalized = normalizePath(path);
|
|
158
|
+
for (const [rule, re] of compiled.paths)
|
|
159
|
+
if (re.test(normalized))
|
|
160
|
+
add('path', item.subject, rule);
|
|
161
|
+
}
|
|
162
|
+
if (item.text === undefined)
|
|
163
|
+
continue;
|
|
164
|
+
const text = item.text.length > MAX_SCAN_CHARS ? item.text.slice(0, MAX_SCAN_CHARS) : item.text;
|
|
165
|
+
const folded = fold(text);
|
|
166
|
+
const lower = text.toLowerCase();
|
|
167
|
+
const packed = compiled.canaries.length ? compact(text) : '';
|
|
168
|
+
for (const [rule, forms, encoded] of compiled.canaries)
|
|
169
|
+
if (forms.some((f) => folded.includes(f) || lower.includes(f)) ||
|
|
170
|
+
encoded.some((f) => packed.includes(f)))
|
|
171
|
+
add('canary', item.subject, rule);
|
|
172
|
+
for (const [rule, content] of compiled.protectedContents)
|
|
173
|
+
if (folded.includes(content))
|
|
174
|
+
add('protected-content', item.subject, rule);
|
|
175
|
+
for (const [rule, re] of compiled.markers)
|
|
176
|
+
if (re.test(folded) || re.test(text))
|
|
177
|
+
add('marker', item.subject, rule);
|
|
178
|
+
for (const [rule, secret] of compiled.secrets)
|
|
179
|
+
if (text.includes(secret))
|
|
180
|
+
add('secret', item.subject, rule);
|
|
181
|
+
const unzeroed = stripZeroWidth(text);
|
|
182
|
+
for (const [name, re] of DEFAULT_SECRETS)
|
|
183
|
+
if (re.test(text) || re.test(unzeroed))
|
|
184
|
+
add('secret', item.subject, `default:${name}`);
|
|
185
|
+
if (compiled.paths.length) {
|
|
186
|
+
for (const token of pathTokens(text))
|
|
187
|
+
for (const [rule, re] of compiled.paths)
|
|
188
|
+
if (re.test(token))
|
|
189
|
+
add('path', item.subject, rule);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
return findings;
|
|
193
|
+
}
|
|
194
|
+
/** @experimental Throws {@link LearningLeakError} when any subject carries evaluator-side material. */
|
|
195
|
+
export function assertNoLearningLeak(guard, subjects) {
|
|
196
|
+
const findings = scanForLearningLeak(guard, subjects);
|
|
197
|
+
if (findings.length)
|
|
198
|
+
throw new LearningLeakError(findings);
|
|
199
|
+
}
|
|
200
|
+
function describeLeak(findings) {
|
|
201
|
+
const where = findings
|
|
202
|
+
.slice(0, 6)
|
|
203
|
+
.map((f) => `${f.subject} (${f.kind}, ${f.rule})`)
|
|
204
|
+
.join('; ');
|
|
205
|
+
const more = findings.length > 6 ? `; and ${findings.length - 6} more` : '';
|
|
206
|
+
return `Leak refused: evaluator-side material reached the learning input or output at ${where}${more}. This is a leak, not a false positive. Nothing was built from it, and the matched text is not repeated here. Remove it from the evidence source or the evaluator data location and rerun.`;
|
|
207
|
+
}
|
|
208
|
+
//# sourceMappingURL=leak-tripwire.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"leak-tripwire.js","sourceRoot":"","sources":["../../src/learning/leak-tripwire.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAyDzC,iGAAiG;AACjG,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IAClC,QAAQ,CAAgC;IACjD,YAAY,QAAwC;QACnD,KAAK,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC,CAAA;QAC7B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;QAC/B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;IACzB,CAAC;CACD;AAED,MAAM,oBAAoB,GAAG,EAAE,CAAA;AAC/B,MAAM,cAAc,GAAG,SAAS,CAAA;AAEhC,MAAM,eAAe,GAA2C;IAC/D,CAAC,gBAAgB,EAAE,wDAAwD,CAAC;IAC5E,CAAC,YAAY,EAAE,4EAA4E,CAAC;IAC5F;QACC,oBAAoB;QACpB,8EAA8E;KAC9E;IACD,CAAC,eAAe,EAAE,2EAA2E,CAAC;CAC9F,CAAA;AAED,MAAM,eAAe,GAA2C;IAC/D,CAAC,aAAa,EAAE,oCAAoC,CAAC;IACrD,CAAC,SAAS,EAAE,yBAAyB,CAAC;IACtC,CAAC,WAAW,EAAE,+BAA+B,CAAC;IAC9C,CAAC,OAAO,EAAE,+DAA+D,CAAC;IAC1E,CAAC,QAAQ,EAAE,qCAAqC,CAAC;CACjD,CAAA;AAED,wFAAwF;AACxF,MAAM,UAAU,oBAAoB;IACnC,OAAO,gBAAgB,WAAW,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAA;AACzD,CAAC;AAED,kGAAkG;AAClG,SAAS,IAAI,CAAC,IAAY;IACzB,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CA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AE,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,GAAG,CAAC;SACjD,IAAI,CAAC,IAAI,CAAC,CAAA;IACZ,MAAM,IAAI,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,QAAQ,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAA;IAC3E,OAAO,iFAAiF,KAAK,GAAG,IAAI,4LAA4L,CAAA;AACjS,CAAC"}
|
|
@@ -72,14 +72,14 @@ export declare const learningObservationSchema: z.ZodObject<{
|
|
|
72
72
|
taskKey: string;
|
|
73
73
|
}>;
|
|
74
74
|
/** @experimental Host-scored observation; failures need retained traces and a versioned evaluator. */
|
|
75
|
-
export type
|
|
75
|
+
export type LearningObservation = Readonly<Omit<z.infer<typeof learningObservationSchema>, 'evidence'>> & {
|
|
76
76
|
readonly evidence: Readonly<z.infer<typeof learningObservationSchema>['evidence']>;
|
|
77
77
|
};
|
|
78
78
|
/** @experimental Current evaluator and installed skill revision authorized for one experiment. */
|
|
79
|
-
export type
|
|
79
|
+
export type LearningTarget = Readonly<z.infer<typeof learningTargetSchema>>;
|
|
80
80
|
/** @experimental Stable insertion order; a claimed cycle may have no live executor. */
|
|
81
|
-
export interface
|
|
81
|
+
export interface LearningObservationRecord extends LearningObservation {
|
|
82
82
|
readonly ordinal: number;
|
|
83
83
|
readonly attemptedCycleId: string | null;
|
|
84
84
|
}
|
|
85
|
-
//# sourceMappingURL=
|
|
85
|
+
//# sourceMappingURL=observation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observation.d.ts","sourceRoot":"","sources":["../../src/learning/observation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAIvB,eAAO,MAAM,oBAAoB;;;;;;;;;;;;EAI/B,CAAA;AAOF,eAAO,MAAM,yBAAyB;;;;;IACrC,qDAAqD;;IAErD,gFAAgF;;IAEhF,wFAAwF;;;IAGxF,wFAAwF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAIvF,CAAA;AAEF,sGAAsG;AACtG,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CACzC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,EAAE,UAAU,CAAC,CAC3D,GAAG;IACH,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC,UAAU,CAAC,CAAC,CAAA;CAClF,CAAA;AAED,kGAAkG;AAClG,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC,CAAA;AAE3E,uFAAuF;AACvF,MAAM,WAAW,yBAA0B,SAAQ,mBAAmB;IACrE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAA;CACxC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import {
|
|
2
|
+
import { learningEvidenceSchema } from './skill.js';
|
|
3
3
|
const label = z.string().trim().min(1).max(256);
|
|
4
4
|
export const learningTargetSchema = z.object({
|
|
5
5
|
skillName: z.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/),
|
|
@@ -20,7 +20,7 @@ export const learningObservationSchema = learningTargetSchema.extend({
|
|
|
20
20
|
outcome: z.enum(['passed', 'failed', 'execution-error', 'unresolved']),
|
|
21
21
|
/** Host verified all execution receipts have settled. This is not a model assertion. */
|
|
22
22
|
usageComplete: z.boolean(),
|
|
23
|
-
evidence:
|
|
23
|
+
evidence: learningEvidenceSchema,
|
|
24
24
|
trace: z.string().trim().min(1).max(32_000),
|
|
25
25
|
});
|
|
26
|
-
//# sourceMappingURL=
|
|
26
|
+
//# sourceMappingURL=observation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"observation.js","sourceRoot":"","sources":["../../src/learning/observation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAA;AAEnD,MAAM,KAAK,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;AAC/C,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,4BAA4B,CAAC;IACzD,iBAAiB,EAAE,KAAK;IACxB,gBAAgB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,CAAC,CAAC;CAClF,CAAC,CAAA;AAEF,MAAM,SAAS,GAAG,CAAC;KACjB,MAAM,EAAE;KACR,IAAI,EAAE;KACN,SAAS,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,CAAC,CAAA;AAErC,MAAM,CAAC,MAAM,yBAAyB,GAAG,oBAAoB,CAAC,MAAM,CAAC;IACpE,qDAAqD;IACrD,SAAS,EAAE,SAAS;IACpB,gFAAgF;IAChF,MAAM,EAAE,SAAS;IACjB,wFAAwF;IACxF,OAAO,EAAE,KAAK;IACd,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,QAAQ,EAAE,iBAAiB,EAAE,YAAY,CAAC,CAAC;IACtE,wFAAwF;IACxF,aAAa,EAAE,CAAC,CAAC,OAAO,EAAE;IAC1B,QAAQ,EAAE,sBAAsB;IAChC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC;CAC3C,CAAC,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { type HarnessProtectionPlan } from '
|
|
3
|
-
import { type HarnessVerificationBatch } from '
|
|
4
|
-
export declare const
|
|
2
|
+
import { type HarnessProtectionPlan } from '../eval/harness-protection.js';
|
|
3
|
+
import { type HarnessVerificationBatch } from '../eval/harness-verification.js';
|
|
4
|
+
export declare const learningEvidenceSchema: z.ZodObject<{
|
|
5
5
|
key: z.ZodString;
|
|
6
6
|
source: z.ZodString;
|
|
7
7
|
reason: z.ZodString;
|
|
@@ -15,7 +15,7 @@ export declare const residentLearningEvidenceSchema: z.ZodObject<{
|
|
|
15
15
|
source: string;
|
|
16
16
|
}>;
|
|
17
17
|
/** @experimental Host provenance for a correction, evaluated activation or rollback. */
|
|
18
|
-
export type
|
|
18
|
+
export type LearningEvidence = Readonly<z.infer<typeof learningEvidenceSchema>>;
|
|
19
19
|
declare const sourceSchema: z.ZodObject<{
|
|
20
20
|
key: z.ZodString;
|
|
21
21
|
revision: z.ZodString;
|
|
@@ -27,7 +27,7 @@ declare const sourceSchema: z.ZodObject<{
|
|
|
27
27
|
revision: string;
|
|
28
28
|
}>;
|
|
29
29
|
/** @experimental Host-owned source identity and revision; neither is a model assertion. */
|
|
30
|
-
export type
|
|
30
|
+
export type LearningSource = Readonly<z.infer<typeof sourceSchema>>;
|
|
31
31
|
declare const candidateSchema: z.ZodObject<{
|
|
32
32
|
name: z.ZodString;
|
|
33
33
|
/** Omitted means ordinary task guidance; exploration policies require explicit projection. */
|
|
@@ -77,11 +77,11 @@ declare const candidateSchema: z.ZodObject<{
|
|
|
77
77
|
}[] | undefined;
|
|
78
78
|
}>;
|
|
79
79
|
/** @experimental Instructional guidance only; never executable assets or tool permissions. */
|
|
80
|
-
export type
|
|
81
|
-
readonly sources?: readonly
|
|
80
|
+
export type LearningSkillCandidate = Readonly<Omit<z.infer<typeof candidateSchema>, 'sources'>> & {
|
|
81
|
+
readonly sources?: readonly LearningSource[];
|
|
82
82
|
};
|
|
83
83
|
/** Internal canonical snapshot, including immutable source bindings. */
|
|
84
|
-
export declare function
|
|
84
|
+
export declare function normalizeLearningSkill(input: LearningSkillCandidate): LearningSkillCandidate;
|
|
85
85
|
declare const learnedSkillSchema: z.ZodObject<{
|
|
86
86
|
name: z.ZodString;
|
|
87
87
|
/** Omitted means ordinary task guidance; exploration policies require explicit projection. */
|
|
@@ -225,10 +225,10 @@ declare const learnedSkillSchema: z.ZodObject<{
|
|
|
225
225
|
}[] | undefined;
|
|
226
226
|
}>;
|
|
227
227
|
/** @experimental Immutable evaluated content and evidence identity. */
|
|
228
|
-
export type
|
|
229
|
-
readonly sources?: readonly
|
|
228
|
+
export type LearnedSkill = Readonly<Omit<z.infer<typeof learnedSkillSchema>, 'sources'>> & {
|
|
229
|
+
readonly sources?: readonly LearningSource[];
|
|
230
230
|
};
|
|
231
|
-
export declare const
|
|
231
|
+
export declare const learningSchema: z.ZodEffects<z.ZodObject<{
|
|
232
232
|
revision: z.ZodNumber;
|
|
233
233
|
identity: z.ZodOptional<z.ZodObject<{
|
|
234
234
|
text: z.ZodString;
|
|
@@ -658,58 +658,58 @@ export declare const residentLearningSchema: z.ZodEffects<z.ZodObject<{
|
|
|
658
658
|
} | undefined;
|
|
659
659
|
}>;
|
|
660
660
|
/** @experimental Versioned behavioral overlay; the original resident mandate remains unchanged. */
|
|
661
|
-
export interface
|
|
661
|
+
export interface LearningState {
|
|
662
662
|
readonly revision: number;
|
|
663
663
|
readonly identity?: {
|
|
664
664
|
readonly text: string;
|
|
665
|
-
readonly evidence:
|
|
665
|
+
readonly evidence: LearningEvidence;
|
|
666
666
|
};
|
|
667
667
|
readonly preferences: readonly {
|
|
668
668
|
readonly key: string;
|
|
669
669
|
readonly value: string;
|
|
670
|
-
readonly evidence:
|
|
670
|
+
readonly evidence: LearningEvidence;
|
|
671
671
|
}[];
|
|
672
|
-
readonly skills: readonly
|
|
673
|
-
readonly lastChange:
|
|
672
|
+
readonly skills: readonly LearnedSkill[];
|
|
673
|
+
readonly lastChange: LearningEvidence;
|
|
674
674
|
}
|
|
675
675
|
/** @experimental Corrections name the current preference evidence they supersede. */
|
|
676
|
-
export interface
|
|
676
|
+
export interface LearningProfileUpdate {
|
|
677
677
|
readonly identity?: string;
|
|
678
678
|
readonly preferences?: readonly {
|
|
679
679
|
readonly key: string;
|
|
680
680
|
readonly value: string;
|
|
681
681
|
readonly supersedes: string | null;
|
|
682
682
|
}[];
|
|
683
|
-
readonly evidence:
|
|
683
|
+
readonly evidence: LearningEvidence;
|
|
684
684
|
}
|
|
685
685
|
/** @experimental Recorded paired runs; hosts own execution, scoring and independent attribution. */
|
|
686
|
-
export interface
|
|
686
|
+
export interface LearningSkillEvaluation {
|
|
687
687
|
/** Host-owned task selection fixed before generating the candidate. */
|
|
688
688
|
readonly protection: HarnessProtectionPlan;
|
|
689
689
|
readonly verification: HarnessVerificationBatch;
|
|
690
690
|
readonly confirmation?: HarnessVerificationBatch;
|
|
691
691
|
}
|
|
692
692
|
/** Internal immutable snapshot used by storage and admitted context. */
|
|
693
|
-
export declare function
|
|
693
|
+
export declare function freezeLearning(input: LearningState): LearningState;
|
|
694
694
|
/** Internal pure profile transition; storage owns exact agenda CAS and idle admission. */
|
|
695
|
-
export declare function
|
|
695
|
+
export declare function reviseLearningProfile(current: LearningState | undefined, input: LearningProfileUpdate): LearningState;
|
|
696
696
|
/** @experimental Bind evaluation to normalized content and any declared source dependencies. */
|
|
697
|
-
export declare function
|
|
697
|
+
export declare function hashLearningSkill(input: LearningSkillCandidate): string;
|
|
698
698
|
/** Internal pure activation; reuse the kernel's conservative two-round verification gate. */
|
|
699
|
-
export declare function
|
|
699
|
+
export declare function promoteLearningSkill(current: LearningState | undefined, input: LearningSkillCandidate, evaluation: LearningSkillEvaluation, inputEvidence: LearningEvidence): LearningState;
|
|
700
700
|
/** Internal rollback appends a new learning version while preserving current profile values. */
|
|
701
|
-
export declare function
|
|
701
|
+
export declare function restoreLearningSkill(current: LearningState | undefined, historical: LearningState | undefined, skillName: string, inputEvidence: LearningEvidence): LearningState;
|
|
702
702
|
/** @experimental Exact skill selection and a character cap, independent of provider token budgets. */
|
|
703
|
-
export interface
|
|
703
|
+
export interface LearningProjectionOptions {
|
|
704
704
|
readonly maxChars: number;
|
|
705
705
|
readonly skillNames: readonly string[];
|
|
706
706
|
/** Defaults to task guidance. Exploration policies never enter ordinary task context. */
|
|
707
707
|
readonly purpose?: 'task' | 'exploration';
|
|
708
708
|
/** Fresh host observations for this projection; absent/mismatched dependencies withhold guidance. */
|
|
709
|
-
readonly sources?: readonly
|
|
709
|
+
readonly sources?: readonly LearningSource[];
|
|
710
710
|
}
|
|
711
711
|
/** @experimental Omitted entries are counted; no partial skill instruction is emitted. */
|
|
712
|
-
export interface
|
|
712
|
+
export interface LearningProjection {
|
|
713
713
|
readonly text: string;
|
|
714
714
|
readonly revision: number | null;
|
|
715
715
|
readonly includedSkills: readonly string[];
|
|
@@ -721,6 +721,6 @@ export interface ResidentLearningProjection {
|
|
|
721
721
|
}[];
|
|
722
722
|
}
|
|
723
723
|
/** @experimental Bounded context data; never registers tools, loads files or executes a skill. */
|
|
724
|
-
export declare function
|
|
724
|
+
export declare function projectLearning(current: LearningState | undefined, options: LearningProjectionOptions): LearningProjection;
|
|
725
725
|
export {};
|
|
726
|
-
//# sourceMappingURL=
|
|
726
|
+
//# sourceMappingURL=skill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"skill.d.ts","sourceRoot":"","sources":["../../src/learning/skill.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EACN,KAAK,qBAAqB,EAE1B,MAAM,+BAA+B,CAAA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AAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;IACtC,yFAAyF;IACzF,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,aAAa,CAAA;IACzC,qGAAqG;IACrG,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,cAAc,EAAE,CAAA;CAC5C;AAED,0FAA0F;AAC1F,MAAM,WAAW,kBAAkB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IAChC,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IAC1C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,cAAc,EAAE,SAAS;QACjC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;QACrB,QAAQ,CAAC,MAAM,EAAE,gBAAgB,GAAG,mBAAmB,GAAG,mBAAmB,CAAA;QAC7E,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAA;KACtC,EAAE,CAAA;CACH;AAED,kGAAkG;AAClG,wBAAgB,eAAe,CAC9B,OAAO,EAAE,aAAa,GAAG,SAAS,EAClC,OAAO,EAAE,yBAAyB,GAChC,kBAAkB,CA2FpB"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { normalizeHarnessProtection, } from '
|
|
4
|
-
import { reviewHarnessCandidate, } from '
|
|
3
|
+
import { normalizeHarnessProtection, } from '../eval/harness-protection.js';
|
|
4
|
+
import { reviewHarnessCandidate, } from '../eval/harness-verification.js';
|
|
5
5
|
const label = z.string().trim().min(1).max(256);
|
|
6
6
|
const name = z.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/);
|
|
7
7
|
const digest = z.string().regex(/^[a-f0-9]{64}$/);
|
|
8
|
-
export const
|
|
8
|
+
export const learningEvidenceSchema = z.object({
|
|
9
9
|
key: label,
|
|
10
10
|
source: label,
|
|
11
11
|
reason: z.string().trim().min(1).max(1_000),
|
|
@@ -30,7 +30,7 @@ const candidateSchema = z.object({
|
|
|
30
30
|
sources: sourcesSchema.optional(),
|
|
31
31
|
});
|
|
32
32
|
/** Internal canonical snapshot, including immutable source bindings. */
|
|
33
|
-
export function
|
|
33
|
+
export function normalizeLearningSkill(input) {
|
|
34
34
|
const candidate = candidateSchema.parse(input);
|
|
35
35
|
return Object.freeze({
|
|
36
36
|
...candidate,
|
|
@@ -41,7 +41,7 @@ export function normalizeResidentSkill(input) {
|
|
|
41
41
|
}
|
|
42
42
|
const learnedSkillSchema = candidateSchema.extend({
|
|
43
43
|
hash: digest,
|
|
44
|
-
evidence:
|
|
44
|
+
evidence: learningEvidenceSchema,
|
|
45
45
|
verification: z.object({
|
|
46
46
|
baselineHash: z.union([digest, z.literal('none')]),
|
|
47
47
|
candidateHash: digest,
|
|
@@ -58,29 +58,29 @@ const learnedSkillSchema = candidateSchema.extend({
|
|
|
58
58
|
.optional(),
|
|
59
59
|
}),
|
|
60
60
|
});
|
|
61
|
-
export const
|
|
61
|
+
export const learningSchema = z
|
|
62
62
|
.object({
|
|
63
63
|
revision: z.number().int().positive().safe(),
|
|
64
64
|
identity: z
|
|
65
65
|
.object({
|
|
66
66
|
text: z.string().trim().min(1).max(4_000),
|
|
67
|
-
evidence:
|
|
67
|
+
evidence: learningEvidenceSchema,
|
|
68
68
|
})
|
|
69
69
|
.optional(),
|
|
70
70
|
preferences: z
|
|
71
71
|
.array(z.object({
|
|
72
72
|
key: name,
|
|
73
73
|
value: z.string().trim().min(1).max(1_000),
|
|
74
|
-
evidence:
|
|
74
|
+
evidence: learningEvidenceSchema,
|
|
75
75
|
}))
|
|
76
76
|
.max(32),
|
|
77
77
|
skills: z.array(learnedSkillSchema).max(16),
|
|
78
|
-
lastChange:
|
|
78
|
+
lastChange: learningEvidenceSchema,
|
|
79
79
|
})
|
|
80
80
|
.superRefine((state, context) => {
|
|
81
81
|
if (new Set(state.preferences.map((p) => p.key)).size !== state.preferences.length ||
|
|
82
82
|
new Set(state.skills.map((s) => s.name)).size !== state.skills.length ||
|
|
83
|
-
state.skills.some((skill) => skill.hash !==
|
|
83
|
+
state.skills.some((skill) => skill.hash !== hashLearningSkill(skill) ||
|
|
84
84
|
skill.verification.candidateHash !== skill.hash))
|
|
85
85
|
context.addIssue({
|
|
86
86
|
code: z.ZodIssueCode.custom,
|
|
@@ -88,8 +88,8 @@ export const residentLearningSchema = z
|
|
|
88
88
|
});
|
|
89
89
|
});
|
|
90
90
|
/** Internal immutable snapshot used by storage and admitted context. */
|
|
91
|
-
export function
|
|
92
|
-
const state =
|
|
91
|
+
export function freezeLearning(input) {
|
|
92
|
+
const state = learningSchema.parse(input);
|
|
93
93
|
return Object.freeze({
|
|
94
94
|
...state,
|
|
95
95
|
...(state.identity
|
|
@@ -118,7 +118,7 @@ export function freezeResidentLearning(input) {
|
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
120
|
function evidenceFor(current, input) {
|
|
121
|
-
const evidence =
|
|
121
|
+
const evidence = learningEvidenceSchema.parse(input);
|
|
122
122
|
const used = [
|
|
123
123
|
current?.lastChange,
|
|
124
124
|
current?.identity?.evidence,
|
|
@@ -130,7 +130,7 @@ function evidenceFor(current, input) {
|
|
|
130
130
|
return evidence;
|
|
131
131
|
}
|
|
132
132
|
function base(current, evidence) {
|
|
133
|
-
const checked = current ?
|
|
133
|
+
const checked = current ? freezeLearning(current) : undefined;
|
|
134
134
|
return {
|
|
135
135
|
...checked,
|
|
136
136
|
revision: (checked?.revision ?? 0) + 1,
|
|
@@ -140,7 +140,7 @@ function base(current, evidence) {
|
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
142
|
/** Internal pure profile transition; storage owns exact agenda CAS and idle admission. */
|
|
143
|
-
export function
|
|
143
|
+
export function reviseLearningProfile(current, input) {
|
|
144
144
|
const checked = z
|
|
145
145
|
.object({
|
|
146
146
|
identity: z.string().trim().min(1).max(4_000).optional(),
|
|
@@ -152,7 +152,7 @@ export function reviseResidentProfile(current, input) {
|
|
|
152
152
|
}))
|
|
153
153
|
.max(32)
|
|
154
154
|
.optional(),
|
|
155
|
-
evidence:
|
|
155
|
+
evidence: learningEvidenceSchema,
|
|
156
156
|
})
|
|
157
157
|
.parse(input);
|
|
158
158
|
if (checked.identity === undefined && !checked.preferences?.length)
|
|
@@ -174,14 +174,14 @@ export function reviseResidentProfile(current, input) {
|
|
|
174
174
|
else
|
|
175
175
|
preferences[index] = updated;
|
|
176
176
|
}
|
|
177
|
-
return
|
|
177
|
+
return freezeLearning({
|
|
178
178
|
...next,
|
|
179
179
|
preferences,
|
|
180
180
|
...(checked.identity !== undefined ? { identity: { text: checked.identity, evidence } } : {}),
|
|
181
181
|
});
|
|
182
182
|
}
|
|
183
183
|
/** @experimental Bind evaluation to normalized content and any declared source dependencies. */
|
|
184
|
-
export function
|
|
184
|
+
export function hashLearningSkill(input) {
|
|
185
185
|
const candidate = candidateSchema.parse(input);
|
|
186
186
|
return createHash('sha256')
|
|
187
187
|
.update(JSON.stringify([
|
|
@@ -194,10 +194,10 @@ export function hashResidentSkill(input) {
|
|
|
194
194
|
.digest('hex');
|
|
195
195
|
}
|
|
196
196
|
/** Internal pure activation; reuse the kernel's conservative two-round verification gate. */
|
|
197
|
-
export function
|
|
197
|
+
export function promoteLearningSkill(current, input, evaluation, inputEvidence) {
|
|
198
198
|
const protection = normalizeHarnessProtection(evaluation.protection);
|
|
199
199
|
const candidate = candidateSchema.parse(input);
|
|
200
|
-
const hash =
|
|
200
|
+
const hash = hashLearningSkill(candidate);
|
|
201
201
|
const baseline = current?.skills.find((s) => s.name === candidate.name);
|
|
202
202
|
if (baseline && (baseline.purpose ?? 'task') !== (candidate.purpose ?? 'task'))
|
|
203
203
|
throw new Error('A skill cannot change learning purpose; use a distinct skill name.');
|
|
@@ -242,27 +242,27 @@ export function promoteResidentSkill(current, input, evaluation, inputEvidence)
|
|
|
242
242
|
},
|
|
243
243
|
};
|
|
244
244
|
const next = base(current, evidence);
|
|
245
|
-
return
|
|
245
|
+
return freezeLearning({
|
|
246
246
|
...next,
|
|
247
247
|
skills: [...next.skills.filter((s) => s.name !== candidate.name), skill],
|
|
248
248
|
});
|
|
249
249
|
}
|
|
250
250
|
/** Internal rollback appends a new learning version while preserving current profile values. */
|
|
251
|
-
export function
|
|
251
|
+
export function restoreLearningSkill(current, historical, skillName, inputEvidence) {
|
|
252
252
|
name.parse(skillName);
|
|
253
253
|
if (!current?.skills.some((s) => s.name === skillName))
|
|
254
254
|
throw new Error('No active resident skill to roll back.');
|
|
255
255
|
const next = base(current, evidenceFor(current, inputEvidence));
|
|
256
256
|
const previous = historical
|
|
257
|
-
?
|
|
257
|
+
? freezeLearning(historical).skills.find((s) => s.name === skillName)
|
|
258
258
|
: undefined;
|
|
259
|
-
return
|
|
259
|
+
return freezeLearning({
|
|
260
260
|
...next,
|
|
261
261
|
skills: [...next.skills.filter((s) => s.name !== skillName), ...(previous ? [previous] : [])],
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
264
|
/** @experimental Bounded context data; never registers tools, loads files or executes a skill. */
|
|
265
|
-
export function
|
|
265
|
+
export function projectLearning(current, options) {
|
|
266
266
|
if (!Number.isSafeInteger(options.maxChars) || options.maxChars < 0 || options.maxChars > 64_000)
|
|
267
267
|
throw new TypeError('Resident learning context requires maxChars between 0 and 64000.');
|
|
268
268
|
const selected = z.array(name).max(16).parse(options.skillNames);
|
|
@@ -284,7 +284,7 @@ export function projectResidentLearning(current, options) {
|
|
|
284
284
|
omitted: selected.length,
|
|
285
285
|
withheldSkills: Object.freeze([]),
|
|
286
286
|
});
|
|
287
|
-
const state =
|
|
287
|
+
const state = freezeLearning(current);
|
|
288
288
|
const pieces = [];
|
|
289
289
|
const includedSkills = [];
|
|
290
290
|
const withheldSkills = [];
|
|
@@ -350,4 +350,4 @@ export function projectResidentLearning(current, options) {
|
|
|
350
350
|
withheldSkills: Object.freeze(withheldSkills),
|
|
351
351
|
});
|
|
352
352
|
}
|
|
353
|
-
//# sourceMappingURL=
|
|
353
|
+
//# sourceMappingURL=skill.js.map
|