@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.
Files changed (151) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/dist/{manager/resident/learning-cycle.d.ts → learning/cycle.d.ts} +45 -36
  3. package/dist/learning/cycle.d.ts.map +1 -0
  4. package/dist/{manager/resident/learning-cycle.js → learning/cycle.js} +52 -20
  5. package/dist/learning/cycle.js.map +1 -0
  6. package/dist/learning/deprecated.d.ts +86 -0
  7. package/dist/learning/deprecated.d.ts.map +1 -0
  8. package/dist/learning/deprecated.js +22 -0
  9. package/dist/learning/deprecated.js.map +1 -0
  10. package/dist/learning/experience-store.d.ts +35 -0
  11. package/dist/learning/experience-store.d.ts.map +1 -0
  12. package/dist/learning/experience-store.js +143 -0
  13. package/dist/learning/experience-store.js.map +1 -0
  14. package/dist/learning/experience.d.ts +150 -0
  15. package/dist/learning/experience.d.ts.map +1 -0
  16. package/dist/learning/experience.js +146 -0
  17. package/dist/learning/experience.js.map +1 -0
  18. package/dist/learning/generator.d.ts +118 -0
  19. package/dist/learning/generator.d.ts.map +1 -0
  20. package/dist/learning/generator.js +275 -0
  21. package/dist/learning/generator.js.map +1 -0
  22. package/dist/learning/leak-tripwire.d.ts +66 -0
  23. package/dist/learning/leak-tripwire.d.ts.map +1 -0
  24. package/dist/learning/leak-tripwire.js +208 -0
  25. package/dist/learning/leak-tripwire.js.map +1 -0
  26. package/dist/{manager/resident/learning-observation.d.ts → learning/observation.d.ts} +4 -4
  27. package/dist/learning/observation.d.ts.map +1 -0
  28. package/dist/{manager/resident/learning-observation.js → learning/observation.js} +3 -3
  29. package/dist/learning/observation.js.map +1 -0
  30. package/dist/{manager/resident/learning.d.ts → learning/skill.d.ts} +29 -29
  31. package/dist/learning/skill.d.ts.map +1 -0
  32. package/dist/{manager/resident/learning.js → learning/skill.js} +27 -27
  33. package/dist/learning/skill.js.map +1 -0
  34. package/dist/{manager/resident/learning-store.d.ts → learning/store.d.ts} +38 -31
  35. package/dist/learning/store.d.ts.map +1 -0
  36. package/dist/{manager/resident/learning-store.js → learning/store.js} +52 -20
  37. package/dist/learning/store.js.map +1 -0
  38. package/dist/manager/resident/activity.d.ts +30 -6
  39. package/dist/manager/resident/activity.d.ts.map +1 -1
  40. package/dist/manager/resident/activity.js.map +1 -1
  41. package/dist/manager/resident/agenda.d.ts +42 -12
  42. package/dist/manager/resident/agenda.d.ts.map +1 -1
  43. package/dist/manager/resident/agenda.js +9 -7
  44. package/dist/manager/resident/agenda.js.map +1 -1
  45. package/dist/manager/resident/consumption.d.ts +27 -5
  46. package/dist/manager/resident/consumption.d.ts.map +1 -1
  47. package/dist/manager/resident/consumption.js +2 -0
  48. package/dist/manager/resident/consumption.js.map +1 -1
  49. package/dist/manager/resident/delivery-window.d.ts +7 -1
  50. package/dist/manager/resident/delivery-window.d.ts.map +1 -1
  51. package/dist/manager/resident/delivery-window.js +2 -0
  52. package/dist/manager/resident/delivery-window.js.map +1 -1
  53. package/dist/manager/resident/evidence-recall.d.ts +7 -1
  54. package/dist/manager/resident/evidence-recall.d.ts.map +1 -1
  55. package/dist/manager/resident/evidence-recall.js +2 -0
  56. package/dist/manager/resident/evidence-recall.js.map +1 -1
  57. package/dist/manager/resident/history.d.ts +45 -9
  58. package/dist/manager/resident/history.d.ts.map +1 -1
  59. package/dist/manager/resident/history.js.map +1 -1
  60. package/dist/manager/resident/host.d.ts +44 -10
  61. package/dist/manager/resident/host.d.ts.map +1 -1
  62. package/dist/manager/resident/host.js +4 -2
  63. package/dist/manager/resident/host.js.map +1 -1
  64. package/dist/manager/resident/initiative.d.ts +32 -6
  65. package/dist/manager/resident/initiative.d.ts.map +1 -1
  66. package/dist/manager/resident/initiative.js +2 -0
  67. package/dist/manager/resident/initiative.js.map +1 -1
  68. package/dist/manager/resident/loop.d.ts +22 -4
  69. package/dist/manager/resident/loop.d.ts.map +1 -1
  70. package/dist/manager/resident/loop.js +7 -1
  71. package/dist/manager/resident/loop.js.map +1 -1
  72. package/dist/manager/resident/outbox.d.ts +42 -8
  73. package/dist/manager/resident/outbox.d.ts.map +1 -1
  74. package/dist/manager/resident/outbox.js +2 -0
  75. package/dist/manager/resident/outbox.js.map +1 -1
  76. package/dist/manager/resident/proposal.d.ts +17 -3
  77. package/dist/manager/resident/proposal.d.ts.map +1 -1
  78. package/dist/manager/resident/proposal.js +2 -0
  79. package/dist/manager/resident/proposal.js.map +1 -1
  80. package/dist/manager/resident/store.d.ts +27 -5
  81. package/dist/manager/resident/store.d.ts.map +1 -1
  82. package/dist/manager/resident/store.js +7 -1
  83. package/dist/manager/resident/store.js.map +1 -1
  84. package/dist/manager/resident/tool-evidence.d.ts +45 -9
  85. package/dist/manager/resident/tool-evidence.d.ts.map +1 -1
  86. package/dist/manager/resident/tool-evidence.js +5 -1
  87. package/dist/manager/resident/tool-evidence.js.map +1 -1
  88. package/dist/prompt/resident-learning.d.ts +12 -2
  89. package/dist/prompt/resident-learning.d.ts.map +1 -1
  90. package/dist/prompt/resident-learning.js +6 -5
  91. package/dist/prompt/resident-learning.js.map +1 -1
  92. package/dist/prompt/resident-step.d.ts +10 -4
  93. package/dist/prompt/resident-step.d.ts.map +1 -1
  94. package/dist/prompt/resident-step.js +6 -4
  95. package/dist/prompt/resident-step.js.map +1 -1
  96. package/dist/public-runtime.d.ts +9 -3
  97. package/dist/public-runtime.d.ts.map +1 -1
  98. package/dist/public-runtime.js +10 -3
  99. package/dist/public-runtime.js.map +1 -1
  100. package/dist/public-types.d.ts +9 -4
  101. package/dist/public-types.d.ts.map +1 -1
  102. package/dist/runtime/query/iteration/phases/per-call-review.d.ts +9 -0
  103. package/dist/runtime/query/iteration/phases/per-call-review.d.ts.map +1 -1
  104. package/dist/runtime/query/iteration/phases/per-call-review.js +19 -0
  105. package/dist/runtime/query/iteration/phases/per-call-review.js.map +1 -1
  106. package/dist/tools/resident-history.d.ts +2 -0
  107. package/dist/tools/resident-history.d.ts.map +1 -1
  108. package/dist/tools/resident-history.js +2 -0
  109. package/dist/tools/resident-history.js.map +1 -1
  110. package/dist/tools/resident-tool-evidence.d.ts +5 -1
  111. package/dist/tools/resident-tool-evidence.d.ts.map +1 -1
  112. package/dist/tools/resident-tool-evidence.js +5 -1
  113. package/dist/tools/resident-tool-evidence.js.map +1 -1
  114. package/package.json +1 -1
  115. package/src/{manager/resident/learning-cycle.ts → learning/cycle.ts} +130 -78
  116. package/src/learning/deprecated.ts +124 -0
  117. package/src/learning/experience-store.ts +202 -0
  118. package/src/learning/experience.ts +238 -0
  119. package/src/learning/generator.ts +388 -0
  120. package/src/learning/leak-tripwire.ts +280 -0
  121. package/src/{manager/resident/learning-observation.ts → learning/observation.ts} +5 -5
  122. package/src/{manager/resident/learning.ts → learning/skill.ts} +64 -67
  123. package/src/{manager/resident/learning-store.ts → learning/store.ts} +97 -67
  124. package/src/manager/resident/activity.ts +30 -6
  125. package/src/manager/resident/agenda.ts +63 -33
  126. package/src/manager/resident/consumption.ts +27 -5
  127. package/src/manager/resident/delivery-window.ts +7 -1
  128. package/src/manager/resident/evidence-recall.ts +7 -1
  129. package/src/manager/resident/history.ts +45 -9
  130. package/src/manager/resident/host.ts +45 -11
  131. package/src/manager/resident/initiative.ts +32 -6
  132. package/src/manager/resident/loop.ts +22 -4
  133. package/src/manager/resident/outbox.ts +42 -8
  134. package/src/manager/resident/proposal.ts +17 -3
  135. package/src/manager/resident/store.ts +27 -5
  136. package/src/manager/resident/tool-evidence.ts +45 -9
  137. package/src/prompt/resident-learning.ts +16 -7
  138. package/src/prompt/resident-step.ts +19 -13
  139. package/src/public-runtime.ts +35 -5
  140. package/src/public-types.ts +96 -34
  141. package/src/runtime/query/iteration/phases/per-call-review.ts +19 -0
  142. package/src/tools/resident-history.ts +2 -0
  143. package/src/tools/resident-tool-evidence.ts +5 -1
  144. package/dist/manager/resident/learning-cycle.d.ts.map +0 -1
  145. package/dist/manager/resident/learning-cycle.js.map +0 -1
  146. package/dist/manager/resident/learning-observation.d.ts.map +0 -1
  147. package/dist/manager/resident/learning-observation.js.map +0 -1
  148. package/dist/manager/resident/learning-store.d.ts.map +0 -1
  149. package/dist/manager/resident/learning-store.js.map +0 -1
  150. package/dist/manager/resident/learning.d.ts.map +0 -1
  151. package/dist/manager/resident/learning.js.map +0 -1
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod'
2
- import { residentLearningEvidenceSchema } from './learning.js'
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: residentLearningEvidenceSchema,
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 ResidentLearningObservation = Readonly<
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 ResidentLearningTarget = Readonly<z.infer<typeof learningTargetSchema>>
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 ResidentLearningObservationRecord extends ResidentLearningObservation {
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 '../../eval/harness-protection.js'
6
+ } from '../eval/harness-protection.js'
7
7
  import {
8
8
  type HarnessVerificationBatch,
9
9
  reviewHarnessCandidate,
10
- } from '../../eval/harness-verification.js'
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 residentLearningEvidenceSchema = z.object({
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 ResidentLearningEvidence = Readonly<z.infer<typeof residentLearningEvidenceSchema>>
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 ResidentLearningSource = Readonly<z.infer<typeof sourceSchema>>
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 ResidentSkillCandidate = Readonly<Omit<z.infer<typeof candidateSchema>, 'sources'>> & {
50
- readonly sources?: readonly ResidentLearningSource[]
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 normalizeResidentSkill(input: ResidentSkillCandidate): ResidentSkillCandidate {
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: residentLearningEvidenceSchema,
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 ResidentLearnedSkill = Readonly<Omit<z.infer<typeof learnedSkillSchema>, 'sources'>> & {
86
- readonly sources?: readonly ResidentLearningSource[]
85
+ export type LearnedSkill = Readonly<Omit<z.infer<typeof learnedSkillSchema>, 'sources'>> & {
86
+ readonly sources?: readonly LearningSource[]
87
87
  }
88
88
 
89
- export const residentLearningSchema = z
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: residentLearningEvidenceSchema,
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: residentLearningEvidenceSchema,
103
+ evidence: learningEvidenceSchema,
104
104
  }),
105
105
  )
106
106
  .max(32),
107
107
  skills: z.array(learnedSkillSchema).max(16),
108
- lastChange: residentLearningEvidenceSchema,
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 !== hashResidentSkill(skill) ||
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 ResidentLearningState {
127
+ export interface LearningState {
128
128
  readonly revision: number
129
- readonly identity?: { readonly text: string; readonly evidence: ResidentLearningEvidence }
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: ResidentLearningEvidence
133
+ readonly evidence: LearningEvidence
134
134
  }[]
135
- readonly skills: readonly ResidentLearnedSkill[]
136
- readonly lastChange: ResidentLearningEvidence
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 ResidentProfileUpdate {
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: ResidentLearningEvidence
147
+ readonly evidence: LearningEvidence
148
148
  }
149
149
 
150
150
  /** @experimental Recorded paired runs; hosts own execution, scoring and independent attribution. */
151
- export interface ResidentSkillEvaluation {
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 freezeResidentLearning(input: ResidentLearningState): ResidentLearningState {
160
- const state = residentLearningSchema.parse(input)
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: ResidentLearningState | undefined,
197
- input: ResidentLearningEvidence,
198
- ): ResidentLearningEvidence {
199
- const evidence = residentLearningEvidenceSchema.parse(input)
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: ResidentLearningState | undefined,
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 reviseResidentProfile(
227
- current: ResidentLearningState | undefined,
228
- input: ResidentProfileUpdate,
229
- ): ResidentLearningState {
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: residentLearningEvidenceSchema,
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 freezeResidentLearning({
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 hashResidentSkill(input: ResidentSkillCandidate): string {
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 promoteResidentSkill(
290
- current: ResidentLearningState | undefined,
291
- input: ResidentSkillCandidate,
292
- evaluation: ResidentSkillEvaluation,
293
- inputEvidence: ResidentLearningEvidence,
294
- ): ResidentLearningState {
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 = hashResidentSkill(candidate)
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: ResidentLearnedSkill = {
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 freezeResidentLearning({
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 restoreResidentSkill(
357
- current: ResidentLearningState | undefined,
358
- historical: ResidentLearningState | undefined,
353
+ export function restoreLearningSkill(
354
+ current: LearningState | undefined,
355
+ historical: LearningState | undefined,
359
356
  skillName: string,
360
- inputEvidence: ResidentLearningEvidence,
361
- ): ResidentLearningState {
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
- ? freezeResidentLearning(historical).skills.find((s) => s.name === skillName)
364
+ ? freezeLearning(historical).skills.find((s) => s.name === skillName)
368
365
  : undefined
369
- return freezeResidentLearning({
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 ResidentLearningProjectionOptions {
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 ResidentLearningSource[]
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 ResidentLearningProjection {
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 projectResidentLearning(
400
- current: ResidentLearningState | undefined,
401
- options: ResidentLearningProjectionOptions,
402
- ): ResidentLearningProjection {
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 = freezeResidentLearning(current)
420
+ const state = freezeLearning(current)
424
421
  const pieces: string[] = []
425
422
  const includedSkills: string[] = []
426
- const withheldSkills: ResidentLearningProjection['withheldSkills'][number][] = []
423
+ const withheldSkills: LearningProjection['withheldSkills'][number][] = []
427
424
  let omitted = 0
428
425
  let length = 0
429
426
  const add = (value: unknown): boolean => {