@namzu/sdk 55.0.0 → 55.1.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 +11 -0
- 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/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/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/package.json +1 -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/iteration/phases/per-call-review.ts +19 -0
- package/src/tools/resident-history.ts +2 -0
- package/src/tools/resident-tool-evidence.ts +5 -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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod'
|
|
2
|
-
import {
|
|
2
|
+
import { learningEvidenceSchema } from './skill.js'
|
|
3
3
|
|
|
4
4
|
const label = z.string().trim().min(1).max(256)
|
|
5
5
|
export const learningTargetSchema = z.object({
|
|
@@ -23,22 +23,22 @@ export const learningObservationSchema = learningTargetSchema.extend({
|
|
|
23
23
|
outcome: z.enum(['passed', 'failed', 'execution-error', 'unresolved']),
|
|
24
24
|
/** Host verified all execution receipts have settled. This is not a model assertion. */
|
|
25
25
|
usageComplete: z.boolean(),
|
|
26
|
-
evidence:
|
|
26
|
+
evidence: learningEvidenceSchema,
|
|
27
27
|
trace: z.string().trim().min(1).max(32_000),
|
|
28
28
|
})
|
|
29
29
|
|
|
30
30
|
/** @experimental Host-scored observation; failures need retained traces and a versioned evaluator. */
|
|
31
|
-
export type
|
|
31
|
+
export type LearningObservation = Readonly<
|
|
32
32
|
Omit<z.infer<typeof learningObservationSchema>, 'evidence'>
|
|
33
33
|
> & {
|
|
34
34
|
readonly evidence: Readonly<z.infer<typeof learningObservationSchema>['evidence']>
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
/** @experimental Current evaluator and installed skill revision authorized for one experiment. */
|
|
38
|
-
export type
|
|
38
|
+
export type LearningTarget = Readonly<z.infer<typeof learningTargetSchema>>
|
|
39
39
|
|
|
40
40
|
/** @experimental Stable insertion order; a claimed cycle may have no live executor. */
|
|
41
|
-
export interface
|
|
41
|
+
export interface LearningObservationRecord extends LearningObservation {
|
|
42
42
|
readonly ordinal: number
|
|
43
43
|
readonly attemptedCycleId: string | null
|
|
44
44
|
}
|
|
@@ -3,27 +3,27 @@ import { z } from 'zod'
|
|
|
3
3
|
import {
|
|
4
4
|
type HarnessProtectionPlan,
|
|
5
5
|
normalizeHarnessProtection,
|
|
6
|
-
} from '
|
|
6
|
+
} from '../eval/harness-protection.js'
|
|
7
7
|
import {
|
|
8
8
|
type HarnessVerificationBatch,
|
|
9
9
|
reviewHarnessCandidate,
|
|
10
|
-
} from '
|
|
10
|
+
} from '../eval/harness-verification.js'
|
|
11
11
|
|
|
12
12
|
const label = z.string().trim().min(1).max(256)
|
|
13
13
|
const name = z.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/)
|
|
14
14
|
const digest = z.string().regex(/^[a-f0-9]{64}$/)
|
|
15
|
-
export const
|
|
15
|
+
export const learningEvidenceSchema = z.object({
|
|
16
16
|
key: label,
|
|
17
17
|
source: label,
|
|
18
18
|
reason: z.string().trim().min(1).max(1_000),
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
/** @experimental Host provenance for a correction, evaluated activation or rollback. */
|
|
22
|
-
export type
|
|
22
|
+
export type LearningEvidence = Readonly<z.infer<typeof learningEvidenceSchema>>
|
|
23
23
|
|
|
24
24
|
const sourceSchema = z.object({ key: label, revision: label })
|
|
25
25
|
/** @experimental Host-owned source identity and revision; neither is a model assertion. */
|
|
26
|
-
export type
|
|
26
|
+
export type LearningSource = Readonly<z.infer<typeof sourceSchema>>
|
|
27
27
|
|
|
28
28
|
const sourcesSchema = z
|
|
29
29
|
.array(sourceSchema)
|
|
@@ -46,12 +46,12 @@ const candidateSchema = z.object({
|
|
|
46
46
|
})
|
|
47
47
|
|
|
48
48
|
/** @experimental Instructional guidance only; never executable assets or tool permissions. */
|
|
49
|
-
export type
|
|
50
|
-
readonly sources?: readonly
|
|
49
|
+
export type LearningSkillCandidate = Readonly<Omit<z.infer<typeof candidateSchema>, 'sources'>> & {
|
|
50
|
+
readonly sources?: readonly LearningSource[]
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/** Internal canonical snapshot, including immutable source bindings. */
|
|
54
|
-
export function
|
|
54
|
+
export function normalizeLearningSkill(input: LearningSkillCandidate): LearningSkillCandidate {
|
|
55
55
|
const candidate = candidateSchema.parse(input)
|
|
56
56
|
return Object.freeze({
|
|
57
57
|
...candidate,
|
|
@@ -63,7 +63,7 @@ export function normalizeResidentSkill(input: ResidentSkillCandidate): ResidentS
|
|
|
63
63
|
|
|
64
64
|
const learnedSkillSchema = candidateSchema.extend({
|
|
65
65
|
hash: digest,
|
|
66
|
-
evidence:
|
|
66
|
+
evidence: learningEvidenceSchema,
|
|
67
67
|
verification: z.object({
|
|
68
68
|
baselineHash: z.union([digest, z.literal('none')]),
|
|
69
69
|
candidateHash: digest,
|
|
@@ -82,17 +82,17 @@ const learnedSkillSchema = candidateSchema.extend({
|
|
|
82
82
|
})
|
|
83
83
|
|
|
84
84
|
/** @experimental Immutable evaluated content and evidence identity. */
|
|
85
|
-
export type
|
|
86
|
-
readonly sources?: readonly
|
|
85
|
+
export type LearnedSkill = Readonly<Omit<z.infer<typeof learnedSkillSchema>, 'sources'>> & {
|
|
86
|
+
readonly sources?: readonly LearningSource[]
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
export const
|
|
89
|
+
export const learningSchema = z
|
|
90
90
|
.object({
|
|
91
91
|
revision: z.number().int().positive().safe(),
|
|
92
92
|
identity: z
|
|
93
93
|
.object({
|
|
94
94
|
text: z.string().trim().min(1).max(4_000),
|
|
95
|
-
evidence:
|
|
95
|
+
evidence: learningEvidenceSchema,
|
|
96
96
|
})
|
|
97
97
|
.optional(),
|
|
98
98
|
preferences: z
|
|
@@ -100,12 +100,12 @@ export const residentLearningSchema = z
|
|
|
100
100
|
z.object({
|
|
101
101
|
key: name,
|
|
102
102
|
value: z.string().trim().min(1).max(1_000),
|
|
103
|
-
evidence:
|
|
103
|
+
evidence: learningEvidenceSchema,
|
|
104
104
|
}),
|
|
105
105
|
)
|
|
106
106
|
.max(32),
|
|
107
107
|
skills: z.array(learnedSkillSchema).max(16),
|
|
108
|
-
lastChange:
|
|
108
|
+
lastChange: learningEvidenceSchema,
|
|
109
109
|
})
|
|
110
110
|
.superRefine((state, context) => {
|
|
111
111
|
if (
|
|
@@ -113,7 +113,7 @@ export const residentLearningSchema = z
|
|
|
113
113
|
new Set(state.skills.map((s) => s.name)).size !== state.skills.length ||
|
|
114
114
|
state.skills.some(
|
|
115
115
|
(skill) =>
|
|
116
|
-
skill.hash !==
|
|
116
|
+
skill.hash !== hashLearningSkill(skill) ||
|
|
117
117
|
skill.verification.candidateHash !== skill.hash,
|
|
118
118
|
)
|
|
119
119
|
)
|
|
@@ -124,31 +124,31 @@ export const residentLearningSchema = z
|
|
|
124
124
|
})
|
|
125
125
|
|
|
126
126
|
/** @experimental Versioned behavioral overlay; the original resident mandate remains unchanged. */
|
|
127
|
-
export interface
|
|
127
|
+
export interface LearningState {
|
|
128
128
|
readonly revision: number
|
|
129
|
-
readonly identity?: { readonly text: string; readonly evidence:
|
|
129
|
+
readonly identity?: { readonly text: string; readonly evidence: LearningEvidence }
|
|
130
130
|
readonly preferences: readonly {
|
|
131
131
|
readonly key: string
|
|
132
132
|
readonly value: string
|
|
133
|
-
readonly evidence:
|
|
133
|
+
readonly evidence: LearningEvidence
|
|
134
134
|
}[]
|
|
135
|
-
readonly skills: readonly
|
|
136
|
-
readonly lastChange:
|
|
135
|
+
readonly skills: readonly LearnedSkill[]
|
|
136
|
+
readonly lastChange: LearningEvidence
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/** @experimental Corrections name the current preference evidence they supersede. */
|
|
140
|
-
export interface
|
|
140
|
+
export interface LearningProfileUpdate {
|
|
141
141
|
readonly identity?: string
|
|
142
142
|
readonly preferences?: readonly {
|
|
143
143
|
readonly key: string
|
|
144
144
|
readonly value: string
|
|
145
145
|
readonly supersedes: string | null
|
|
146
146
|
}[]
|
|
147
|
-
readonly evidence:
|
|
147
|
+
readonly evidence: LearningEvidence
|
|
148
148
|
}
|
|
149
149
|
|
|
150
150
|
/** @experimental Recorded paired runs; hosts own execution, scoring and independent attribution. */
|
|
151
|
-
export interface
|
|
151
|
+
export interface LearningSkillEvaluation {
|
|
152
152
|
/** Host-owned task selection fixed before generating the candidate. */
|
|
153
153
|
readonly protection: HarnessProtectionPlan
|
|
154
154
|
readonly verification: HarnessVerificationBatch
|
|
@@ -156,8 +156,8 @@ export interface ResidentSkillEvaluation {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
/** Internal immutable snapshot used by storage and admitted context. */
|
|
159
|
-
export function
|
|
160
|
-
const state =
|
|
159
|
+
export function freezeLearning(input: LearningState): LearningState {
|
|
160
|
+
const state = learningSchema.parse(input)
|
|
161
161
|
return Object.freeze({
|
|
162
162
|
...state,
|
|
163
163
|
...(state.identity
|
|
@@ -193,10 +193,10 @@ export function freezeResidentLearning(input: ResidentLearningState): ResidentLe
|
|
|
193
193
|
}
|
|
194
194
|
|
|
195
195
|
function evidenceFor(
|
|
196
|
-
current:
|
|
197
|
-
input:
|
|
198
|
-
):
|
|
199
|
-
const evidence =
|
|
196
|
+
current: LearningState | undefined,
|
|
197
|
+
input: LearningEvidence,
|
|
198
|
+
): LearningEvidence {
|
|
199
|
+
const evidence = learningEvidenceSchema.parse(input)
|
|
200
200
|
const used = [
|
|
201
201
|
current?.lastChange,
|
|
202
202
|
current?.identity?.evidence,
|
|
@@ -208,11 +208,8 @@ function evidenceFor(
|
|
|
208
208
|
return evidence
|
|
209
209
|
}
|
|
210
210
|
|
|
211
|
-
function base(
|
|
212
|
-
current
|
|
213
|
-
evidence: ResidentLearningEvidence,
|
|
214
|
-
): ResidentLearningState {
|
|
215
|
-
const checked = current ? freezeResidentLearning(current) : undefined
|
|
211
|
+
function base(current: LearningState | undefined, evidence: LearningEvidence): LearningState {
|
|
212
|
+
const checked = current ? freezeLearning(current) : undefined
|
|
216
213
|
return {
|
|
217
214
|
...checked,
|
|
218
215
|
revision: (checked?.revision ?? 0) + 1,
|
|
@@ -223,10 +220,10 @@ function base(
|
|
|
223
220
|
}
|
|
224
221
|
|
|
225
222
|
/** Internal pure profile transition; storage owns exact agenda CAS and idle admission. */
|
|
226
|
-
export function
|
|
227
|
-
current:
|
|
228
|
-
input:
|
|
229
|
-
):
|
|
223
|
+
export function reviseLearningProfile(
|
|
224
|
+
current: LearningState | undefined,
|
|
225
|
+
input: LearningProfileUpdate,
|
|
226
|
+
): LearningState {
|
|
230
227
|
const checked = z
|
|
231
228
|
.object({
|
|
232
229
|
identity: z.string().trim().min(1).max(4_000).optional(),
|
|
@@ -240,7 +237,7 @@ export function reviseResidentProfile(
|
|
|
240
237
|
)
|
|
241
238
|
.max(32)
|
|
242
239
|
.optional(),
|
|
243
|
-
evidence:
|
|
240
|
+
evidence: learningEvidenceSchema,
|
|
244
241
|
})
|
|
245
242
|
.parse(input)
|
|
246
243
|
if (checked.identity === undefined && !checked.preferences?.length)
|
|
@@ -262,7 +259,7 @@ export function reviseResidentProfile(
|
|
|
262
259
|
if (index < 0) preferences.push(updated)
|
|
263
260
|
else preferences[index] = updated
|
|
264
261
|
}
|
|
265
|
-
return
|
|
262
|
+
return freezeLearning({
|
|
266
263
|
...next,
|
|
267
264
|
preferences,
|
|
268
265
|
...(checked.identity !== undefined ? { identity: { text: checked.identity, evidence } } : {}),
|
|
@@ -270,7 +267,7 @@ export function reviseResidentProfile(
|
|
|
270
267
|
}
|
|
271
268
|
|
|
272
269
|
/** @experimental Bind evaluation to normalized content and any declared source dependencies. */
|
|
273
|
-
export function
|
|
270
|
+
export function hashLearningSkill(input: LearningSkillCandidate): string {
|
|
274
271
|
const candidate = candidateSchema.parse(input)
|
|
275
272
|
return createHash('sha256')
|
|
276
273
|
.update(
|
|
@@ -286,15 +283,15 @@ export function hashResidentSkill(input: ResidentSkillCandidate): string {
|
|
|
286
283
|
}
|
|
287
284
|
|
|
288
285
|
/** Internal pure activation; reuse the kernel's conservative two-round verification gate. */
|
|
289
|
-
export function
|
|
290
|
-
current:
|
|
291
|
-
input:
|
|
292
|
-
evaluation:
|
|
293
|
-
inputEvidence:
|
|
294
|
-
):
|
|
286
|
+
export function promoteLearningSkill(
|
|
287
|
+
current: LearningState | undefined,
|
|
288
|
+
input: LearningSkillCandidate,
|
|
289
|
+
evaluation: LearningSkillEvaluation,
|
|
290
|
+
inputEvidence: LearningEvidence,
|
|
291
|
+
): LearningState {
|
|
295
292
|
const protection = normalizeHarnessProtection(evaluation.protection)
|
|
296
293
|
const candidate = candidateSchema.parse(input)
|
|
297
|
-
const hash =
|
|
294
|
+
const hash = hashLearningSkill(candidate)
|
|
298
295
|
const baseline = current?.skills.find((s) => s.name === candidate.name)
|
|
299
296
|
if (baseline && (baseline.purpose ?? 'task') !== (candidate.purpose ?? 'task'))
|
|
300
297
|
throw new Error('A skill cannot change learning purpose; use a distinct skill name.')
|
|
@@ -326,7 +323,7 @@ export function promoteResidentSkill(
|
|
|
326
323
|
)
|
|
327
324
|
if (review.decision !== 'accept')
|
|
328
325
|
throw new Error(`Resident skill promotion ${review.decision}: ${review.reason}`)
|
|
329
|
-
const skill:
|
|
326
|
+
const skill: LearnedSkill = {
|
|
330
327
|
...candidate,
|
|
331
328
|
hash,
|
|
332
329
|
evidence,
|
|
@@ -346,44 +343,44 @@ export function promoteResidentSkill(
|
|
|
346
343
|
},
|
|
347
344
|
}
|
|
348
345
|
const next = base(current, evidence)
|
|
349
|
-
return
|
|
346
|
+
return freezeLearning({
|
|
350
347
|
...next,
|
|
351
348
|
skills: [...next.skills.filter((s) => s.name !== candidate.name), skill],
|
|
352
349
|
})
|
|
353
350
|
}
|
|
354
351
|
|
|
355
352
|
/** Internal rollback appends a new learning version while preserving current profile values. */
|
|
356
|
-
export function
|
|
357
|
-
current:
|
|
358
|
-
historical:
|
|
353
|
+
export function restoreLearningSkill(
|
|
354
|
+
current: LearningState | undefined,
|
|
355
|
+
historical: LearningState | undefined,
|
|
359
356
|
skillName: string,
|
|
360
|
-
inputEvidence:
|
|
361
|
-
):
|
|
357
|
+
inputEvidence: LearningEvidence,
|
|
358
|
+
): LearningState {
|
|
362
359
|
name.parse(skillName)
|
|
363
360
|
if (!current?.skills.some((s) => s.name === skillName))
|
|
364
361
|
throw new Error('No active resident skill to roll back.')
|
|
365
362
|
const next = base(current, evidenceFor(current, inputEvidence))
|
|
366
363
|
const previous = historical
|
|
367
|
-
?
|
|
364
|
+
? freezeLearning(historical).skills.find((s) => s.name === skillName)
|
|
368
365
|
: undefined
|
|
369
|
-
return
|
|
366
|
+
return freezeLearning({
|
|
370
367
|
...next,
|
|
371
368
|
skills: [...next.skills.filter((s) => s.name !== skillName), ...(previous ? [previous] : [])],
|
|
372
369
|
})
|
|
373
370
|
}
|
|
374
371
|
|
|
375
372
|
/** @experimental Exact skill selection and a character cap, independent of provider token budgets. */
|
|
376
|
-
export interface
|
|
373
|
+
export interface LearningProjectionOptions {
|
|
377
374
|
readonly maxChars: number
|
|
378
375
|
readonly skillNames: readonly string[]
|
|
379
376
|
/** Defaults to task guidance. Exploration policies never enter ordinary task context. */
|
|
380
377
|
readonly purpose?: 'task' | 'exploration'
|
|
381
378
|
/** Fresh host observations for this projection; absent/mismatched dependencies withhold guidance. */
|
|
382
|
-
readonly sources?: readonly
|
|
379
|
+
readonly sources?: readonly LearningSource[]
|
|
383
380
|
}
|
|
384
381
|
|
|
385
382
|
/** @experimental Omitted entries are counted; no partial skill instruction is emitted. */
|
|
386
|
-
export interface
|
|
383
|
+
export interface LearningProjection {
|
|
387
384
|
readonly text: string
|
|
388
385
|
readonly revision: number | null
|
|
389
386
|
readonly includedSkills: readonly string[]
|
|
@@ -396,10 +393,10 @@ export interface ResidentLearningProjection {
|
|
|
396
393
|
}
|
|
397
394
|
|
|
398
395
|
/** @experimental Bounded context data; never registers tools, loads files or executes a skill. */
|
|
399
|
-
export function
|
|
400
|
-
current:
|
|
401
|
-
options:
|
|
402
|
-
):
|
|
396
|
+
export function projectLearning(
|
|
397
|
+
current: LearningState | undefined,
|
|
398
|
+
options: LearningProjectionOptions,
|
|
399
|
+
): LearningProjection {
|
|
403
400
|
if (!Number.isSafeInteger(options.maxChars) || options.maxChars < 0 || options.maxChars > 64_000)
|
|
404
401
|
throw new TypeError('Resident learning context requires maxChars between 0 and 64000.')
|
|
405
402
|
const selected = z.array(name).max(16).parse(options.skillNames)
|
|
@@ -420,10 +417,10 @@ export function projectResidentLearning(
|
|
|
420
417
|
omitted: selected.length,
|
|
421
418
|
withheldSkills: Object.freeze([]),
|
|
422
419
|
})
|
|
423
|
-
const state =
|
|
420
|
+
const state = freezeLearning(current)
|
|
424
421
|
const pieces: string[] = []
|
|
425
422
|
const includedSkills: string[] = []
|
|
426
|
-
const withheldSkills:
|
|
423
|
+
const withheldSkills: LearningProjection['withheldSkills'][number][] = []
|
|
427
424
|
let omitted = 0
|
|
428
425
|
let length = 0
|
|
429
426
|
const add = (value: unknown): boolean => {
|