@lmzhen/dsh-evolution-core 0.59.5 → 0.60.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 (111) hide show
  1. package/README.md +3 -1
  2. package/lib/authority-plugin.js +3 -2
  3. package/lib/composition/index.js +2 -2
  4. package/lib/{composition-B_F4TYOD.js → composition-BSqh70z_.js} +1 -1
  5. package/lib/{ensure-BpVDuDnA.js → ensure-DTCuxAxR.js} +1 -1
  6. package/lib/{extract-plan-D3ALlAmN.js → extract-plan-CP__XlEs.js} +2 -2
  7. package/lib/extract.js +4 -4
  8. package/lib/http-routes.js +3 -2
  9. package/lib/index.js +15 -15
  10. package/lib/{io-Cpa8wuvj.js → io-DT4-MXLr.js} +25 -1
  11. package/lib/io-node.js +1 -1
  12. package/lib/io-platform.js +163 -0
  13. package/lib/io-registry.js +10 -0
  14. package/lib/{mutation-authority-CZpc9F20.js → mutation-authority-C3RYyiaT.js} +66 -41
  15. package/lib/{mutation-storage-adapter-z1_hyrQn.js → mutation-storage-adapter-CSVn34dK.js} +334 -212
  16. package/lib/{mutations-Y-wKod7W.js → mutations-JKFlfhSO.js} +1 -1
  17. package/lib/policy.js +1 -1
  18. package/lib/{quality-NPGr3VzA.js → quality-C0ri2SgY.js} +2 -2
  19. package/lib/restrictor.js +1 -1
  20. package/lib/result.js +1 -1
  21. package/lib/{review-context-yNiZadPw.js → review-context-D2LIOEi-.js} +2 -2
  22. package/lib/runtime/plugin.js +2 -2
  23. package/lib/{session-projection-DM15fsRp.js → session-projection-Dnmm5bzt.js} +1 -1
  24. package/lib/{skill-history-BvLWFoOo.js → skill-history-BOZ4HCDB.js} +2 -2
  25. package/lib/skills.js +739 -129
  26. package/lib/state/domain/index.js +433 -0
  27. package/lib/state/index.js +136 -0
  28. package/lib/state/migrate.js +90 -0
  29. package/lib/state/storage.js +605 -0
  30. package/lib/state/store-plugin.js +23 -0
  31. package/lib/state/store.js +268 -0
  32. package/lib/subagent/index.js +1 -1
  33. package/lib/types/authority-plugin.d.ts +1 -1
  34. package/lib/types/authority-plugin.js +2 -1
  35. package/lib/types/authority.d.ts +1 -1
  36. package/lib/types/authority.js +75 -48
  37. package/lib/types/composition/ensure.js +1 -1
  38. package/lib/types/contract.d.ts +8 -0
  39. package/lib/types/http-routes.d.ts +1 -0
  40. package/lib/types/http-routes.js +2 -1
  41. package/lib/types/io-platform.d.ts +74 -0
  42. package/lib/types/io-platform.js +178 -0
  43. package/lib/types/io-registry.d.ts +4 -0
  44. package/lib/types/io-registry.js +10 -0
  45. package/lib/types/io.d.ts +7 -0
  46. package/lib/types/io.js +25 -1
  47. package/lib/types/mutation-authority.d.ts +1 -1
  48. package/lib/types/mutation-storage-adapter.d.ts +1 -1
  49. package/lib/types/opt-in.js +2 -2
  50. package/lib/types/params.js +2 -2
  51. package/lib/types/policy.js +1 -1
  52. package/lib/types/restrictor.js +2 -2
  53. package/lib/types/result.d.ts +1 -1
  54. package/lib/types/result.js +1 -1
  55. package/lib/types/runtime/coherence.js +1 -1
  56. package/lib/types/runtime/llm.d.ts +1 -1
  57. package/lib/types/runtime/llm.js +1 -1
  58. package/lib/types/runtime/platform.d.ts +3 -3
  59. package/lib/types/runtime/platform.js +2 -2
  60. package/lib/types/runtime/projections.d.ts +1 -1
  61. package/lib/types/scope.js +1 -1
  62. package/lib/types/session-projection.d.ts +1 -1
  63. package/lib/types/signals.d.ts +1 -1
  64. package/lib/types/skill-observation.d.ts +4 -5
  65. package/lib/types/skill-observation.js +18 -2
  66. package/lib/types/skill-store.d.ts +73 -4
  67. package/lib/types/skill-store.js +376 -29
  68. package/lib/types/skill-write-plan.d.ts +80 -0
  69. package/lib/types/skill-write-plan.js +2 -0
  70. package/lib/types/skill-write-service.d.ts +84 -2
  71. package/lib/types/skill-write-service.js +214 -35
  72. package/lib/types/skills.d.ts +2 -0
  73. package/lib/types/skills.js +2 -0
  74. package/lib/types/state/conformance.d.ts +47 -0
  75. package/lib/types/state/conformance.js +246 -0
  76. package/lib/types/state/constants.d.ts +52 -0
  77. package/lib/types/state/constants.js +52 -0
  78. package/lib/types/state/domain/compatibility.d.ts +40 -0
  79. package/lib/types/state/domain/compatibility.js +36 -0
  80. package/lib/types/state/domain/index.d.ts +81 -0
  81. package/lib/types/state/domain/index.js +592 -0
  82. package/lib/types/state/index.d.ts +63 -0
  83. package/lib/types/state/index.js +174 -0
  84. package/lib/types/state/medium-declaration.d.ts +37 -0
  85. package/lib/types/state/medium-declaration.js +53 -0
  86. package/lib/types/state/migrate.d.ts +34 -0
  87. package/lib/types/state/migrate.js +103 -0
  88. package/lib/types/state/record-contract.d.ts +56 -0
  89. package/lib/types/state/record-contract.js +120 -0
  90. package/lib/types/state/storage.d.ts +112 -0
  91. package/lib/types/state/storage.js +178 -0
  92. package/lib/types/state/store-plugin.d.ts +14 -0
  93. package/lib/types/state/store-plugin.js +18 -0
  94. package/lib/types/state/store.d.ts +39 -0
  95. package/lib/types/state/store.js +270 -0
  96. package/lib/types/store-ledger.js +2 -2
  97. package/lib/types/subagent/run.d.ts +1 -1
  98. package/lib/types/subagent/types.d.ts +4 -4
  99. package/lib/types/system-skill-writer.d.ts +21 -0
  100. package/lib/types/system-skill-writer.js +15 -0
  101. package/lib/types/{write-kernel.d.ts → target-writer.d.ts} +32 -15
  102. package/lib/types/{write-kernel.js → target-writer.js} +40 -8
  103. package/lib/types/tool-dispatch.js +6 -3
  104. package/lib/types/{mutation-unit.d.ts → unit-kernel.d.ts} +44 -13
  105. package/lib/types/{mutation-unit.js → unit-kernel.js} +163 -120
  106. package/lib/types/write.d.ts +1 -2
  107. package/lib/types/write.js +1 -2
  108. package/lib/{usage-D7yHG2Cb.js → usage-BO4Zj_zB.js} +2 -2
  109. package/lib/write.js +4 -4
  110. package/package.json +30 -3
  111. package/persisted-write-inventory.json +14 -5
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=skill-write-plan.js.map
@@ -1,5 +1,6 @@
1
- import type { SkillLibrary, WriteOrigin } from './skill-store.ts';
1
+ import type { SkillLibrary, SkillSectionEdit, WriteOrigin } from './skill-store.ts';
2
2
  import type { SkillObservationStore } from './skill-observation.ts';
3
+ import type { SkillWritePlan } from './skill-write-plan.ts';
3
4
  /** Exact execution identity for observations. */
4
5
  export type SkillWriteOwner = object;
5
6
  /** Stable failure codes for the future model-facing error map. */
@@ -10,6 +11,17 @@ export type SkillWriteServiceResult = {
10
11
  readonly message: string;
11
12
  readonly noop?: boolean;
12
13
  readonly content?: string | null;
14
+ readonly path?: string;
15
+ readonly normalizedFrontmatterFields?: readonly string[];
16
+ } | {
17
+ readonly ok: false;
18
+ readonly code: SkillWriteErrorCode;
19
+ readonly message: string;
20
+ };
21
+ /** Result of planning one write action. */
22
+ export type SkillWritePlanResult = {
23
+ readonly ok: true;
24
+ readonly plan: SkillWritePlan;
13
25
  } | {
14
26
  readonly ok: false;
15
27
  readonly code: SkillWriteErrorCode;
@@ -24,7 +36,6 @@ export type SkillWriteServiceResult = {
24
36
  export declare class SkillWriteService {
25
37
  private readonly library;
26
38
  private readonly observations;
27
- private readonly locks;
28
39
  constructor(library: SkillLibrary, observations: SkillObservationStore);
29
40
  /**
30
41
  * Read SKILL.md and record present/absent for this owner.
@@ -41,6 +52,77 @@ export declare class SkillWriteService {
41
52
  * @returns the bytes, or null when absent.
42
53
  */
43
54
  readSupport(owner: SkillWriteOwner, name: string, filePath: string): Promise<string | null>;
55
+ /**
56
+ * Plan a create. Creation is createIfAbsent by definition and needs no prior
57
+ * read; the provider's `create` path keeps managed/protection semantics.
58
+ * @param owner - writer identity (unused for create, kept for a uniform API).
59
+ * @param name - skill name.
60
+ * @param content - full body.
61
+ * @param managed - add the managed marker (non-foreground origin).
62
+ * @returns the plan or a typed refusal.
63
+ */
64
+ planCreate(owner: SkillWriteOwner, name: string, content: string, origin?: WriteOrigin, managed?: boolean): Promise<SkillWritePlanResult>;
65
+ /**
66
+ * Plan a full body replacement from this owner's observation.
67
+ * @param owner - exact writer.
68
+ * @param name - skill name.
69
+ * @param content - next body.
70
+ * @param origin - write face.
71
+ * @returns the plan or a typed refusal.
72
+ */
73
+ planUpdate(owner: SkillWriteOwner, name: string, content: string, origin?: WriteOrigin): Promise<SkillWritePlanResult>;
74
+ /**
75
+ * Plan a literal patch against a body or support target.
76
+ *
77
+ * A section patch always targets the body and ignores `filePath`; that is the
78
+ * same contract the library has always had, but now it is explicit in the
79
+ * plan instead of a tool branch.
80
+ * @param owner - exact writer.
81
+ * @param name - skill name.
82
+ * @param input - literal edit or section edit.
83
+ * @param origin - write face.
84
+ * @returns the plan or a typed refusal.
85
+ */
86
+ planPatch(owner: SkillWriteOwner, name: string, input: {
87
+ readonly oldString?: string;
88
+ readonly newString?: string;
89
+ readonly replaceAll?: boolean;
90
+ readonly filePath?: string;
91
+ readonly section?: SkillSectionEdit;
92
+ }, origin?: WriteOrigin): Promise<SkillWritePlanResult>;
93
+ /**
94
+ * Plan a full support-file write. A newly observed/absent file is
95
+ * createIfAbsent; an already observed file is replaceIfVersion. An unread
96
+ * existing file is refused instead of overwritten.
97
+ * @param owner - exact writer.
98
+ * @param name - skill name.
99
+ * @param filePath - support path.
100
+ * @param content - next bytes.
101
+ * @param origin - write face.
102
+ * @returns the plan or a typed refusal.
103
+ */
104
+ planWriteSupport(owner: SkillWriteOwner, name: string, filePath: string, content: string, origin?: WriteOrigin): Promise<SkillWritePlanResult>;
105
+ /**
106
+ * Plan removing one support file from this owner's observation.
107
+ * @param owner - exact writer.
108
+ * @param name - skill name.
109
+ * @param filePath - support path.
110
+ * @param origin - write face.
111
+ * @returns the plan or a typed refusal.
112
+ */
113
+ planRemoveSupport(owner: SkillWriteOwner, name: string, filePath: string, origin?: WriteOrigin): Promise<SkillWritePlanResult>;
114
+ /**
115
+ * Apply one plan through the provider and record the committed result for
116
+ * this owner. The re-read is temporary H2 bookkeeping; H5 replaces it with
117
+ * the provider's `SkillWriteOutcome`, so a post-commit read failure can never
118
+ * turn a landed write into a tool failure.
119
+ * @param plan - the write plan.
120
+ * @param owner - exact writer identity; omitted by internal callers that do
121
+ * not own observations.
122
+ * @returns the service-level result.
123
+ */
124
+ apply(plan: SkillWritePlan, owner?: SkillWriteOwner): Promise<SkillWriteServiceResult>;
125
+ private observeOutcomes;
44
126
  /**
45
127
  * Replace SKILL.md only when this owner observed its current version.
46
128
  * @param owner - exact writer identity.
@@ -11,7 +11,6 @@
11
11
  */
12
12
  import { contentHash } from "./mutations.js";
13
13
  import { skillBodyTarget, skillSupportTarget } from "./skill-observation.js";
14
- import { SkillTargetLocks } from "./skill-target-locks.js";
15
14
  /**
16
15
  * Read body/support bytes and record the observation for the exact owner.
17
16
  *
@@ -21,7 +20,6 @@ import { SkillTargetLocks } from "./skill-target-locks.js";
21
20
  export class SkillWriteService {
22
21
  library;
23
22
  observations;
24
- locks = new SkillTargetLocks();
25
23
  constructor(library, observations) {
26
24
  this.library = library;
27
25
  this.observations = observations;
@@ -33,7 +31,7 @@ export class SkillWriteService {
33
31
  * @returns the body, or null when absent.
34
32
  */
35
33
  async readBody(owner, name) {
36
- const target = skillBodyTarget(name);
34
+ const target = await this.library.identify(skillBodyTarget(name));
37
35
  const content = await this.library.read(name);
38
36
  this.record(owner, target, content);
39
37
  return content;
@@ -46,11 +44,188 @@ export class SkillWriteService {
46
44
  * @returns the bytes, or null when absent.
47
45
  */
48
46
  async readSupport(owner, name, filePath) {
49
- const target = skillSupportTarget(name, filePath);
47
+ const target = await this.library.identify(skillSupportTarget(name, filePath));
50
48
  const content = await this.library.readSupportFile(name, filePath);
51
49
  this.record(owner, target, content);
52
50
  return content;
53
51
  }
52
+ /**
53
+ * Plan a create. Creation is createIfAbsent by definition and needs no prior
54
+ * read; the provider's `create` path keeps managed/protection semantics.
55
+ * @param owner - writer identity (unused for create, kept for a uniform API).
56
+ * @param name - skill name.
57
+ * @param content - full body.
58
+ * @param managed - add the managed marker (non-foreground origin).
59
+ * @returns the plan or a typed refusal.
60
+ */
61
+ async planCreate(owner, name, content, origin = 'foreground', managed = false) {
62
+ void owner;
63
+ return {
64
+ ok: true,
65
+ plan: {
66
+ origin,
67
+ ops: [{ kind: 'createSkill', skill: name, content, ...(managed ? { managed: true } : {}) }],
68
+ },
69
+ };
70
+ }
71
+ /**
72
+ * Plan a full body replacement from this owner's observation.
73
+ * @param owner - exact writer.
74
+ * @param name - skill name.
75
+ * @param content - next body.
76
+ * @param origin - write face.
77
+ * @returns the plan or a typed refusal.
78
+ */
79
+ async planUpdate(owner, name, content, origin = 'foreground') {
80
+ const target = await this.library.identify(skillBodyTarget(name));
81
+ const observed = this.observations.requirePresent(owner, target);
82
+ if (!('version' in observed))
83
+ return planRefusal(observed.kind);
84
+ return {
85
+ ok: true,
86
+ plan: {
87
+ origin,
88
+ ops: [{ kind: 'write', target, content, expect: { kind: 'present', version: observed.version } }],
89
+ },
90
+ };
91
+ }
92
+ /**
93
+ * Plan a literal patch against a body or support target.
94
+ *
95
+ * A section patch always targets the body and ignores `filePath`; that is the
96
+ * same contract the library has always had, but now it is explicit in the
97
+ * plan instead of a tool branch.
98
+ * @param owner - exact writer.
99
+ * @param name - skill name.
100
+ * @param input - literal edit or section edit.
101
+ * @param origin - write face.
102
+ * @returns the plan or a typed refusal.
103
+ */
104
+ async planPatch(owner, name, input, origin = 'foreground') {
105
+ if (input.section !== undefined) {
106
+ const target = await this.library.identify(skillBodyTarget(name));
107
+ const observed = this.observations.requirePresent(owner, target);
108
+ if (!('version' in observed))
109
+ return planRefusal(observed.kind);
110
+ return {
111
+ ok: true,
112
+ plan: {
113
+ origin,
114
+ ops: [{
115
+ kind: 'patchSection',
116
+ target,
117
+ section: input.section,
118
+ expect: { kind: 'present', version: observed.version },
119
+ }],
120
+ },
121
+ };
122
+ }
123
+ const filePath = input.filePath ?? '';
124
+ const logicalTarget = filePath === '' ? skillBodyTarget(name) : skillSupportTarget(name, filePath);
125
+ const target = await this.library.identify(logicalTarget);
126
+ const observed = this.observations.requirePresent(owner, target);
127
+ if (!('version' in observed))
128
+ return planRefusal(observed.kind);
129
+ return {
130
+ ok: true,
131
+ plan: {
132
+ origin,
133
+ ops: [{
134
+ kind: 'patch',
135
+ target,
136
+ oldString: input.oldString ?? '',
137
+ newString: input.newString ?? '',
138
+ replaceAll: input.replaceAll === true,
139
+ expect: { kind: 'present', version: observed.version },
140
+ }],
141
+ },
142
+ };
143
+ }
144
+ /**
145
+ * Plan a full support-file write. A newly observed/absent file is
146
+ * createIfAbsent; an already observed file is replaceIfVersion. An unread
147
+ * existing file is refused instead of overwritten.
148
+ * @param owner - exact writer.
149
+ * @param name - skill name.
150
+ * @param filePath - support path.
151
+ * @param content - next bytes.
152
+ * @param origin - write face.
153
+ * @returns the plan or a typed refusal.
154
+ */
155
+ async planWriteSupport(owner, name, filePath, content, origin = 'foreground') {
156
+ const target = await this.library.identify(skillSupportTarget(name, filePath));
157
+ const observed = this.observations.get(owner, target);
158
+ if (observed === undefined) {
159
+ // This read decides absent vs existing; it is not recorded as a read
160
+ // observation. The real createIfAbsent guard is the kernel anchor.
161
+ const current = await this.library.readSupportFile(name, filePath);
162
+ if (current !== null)
163
+ return notObserved();
164
+ return { ok: true, plan: { origin, ops: [{ kind: 'write', target, content, expect: { kind: 'absent' } }] } };
165
+ }
166
+ if (observed.kind === 'absent') {
167
+ return { ok: true, plan: { origin, ops: [{ kind: 'write', target, content, expect: { kind: 'absent' } }] } };
168
+ }
169
+ return {
170
+ ok: true,
171
+ plan: {
172
+ origin,
173
+ ops: [{ kind: 'write', target, content, expect: { kind: 'present', version: observed.version } }],
174
+ },
175
+ };
176
+ }
177
+ /**
178
+ * Plan removing one support file from this owner's observation.
179
+ * @param owner - exact writer.
180
+ * @param name - skill name.
181
+ * @param filePath - support path.
182
+ * @param origin - write face.
183
+ * @returns the plan or a typed refusal.
184
+ */
185
+ async planRemoveSupport(owner, name, filePath, origin = 'foreground') {
186
+ const target = await this.library.identify(skillSupportTarget(name, filePath));
187
+ const observed = this.observations.requirePresent(owner, target);
188
+ if (!('version' in observed))
189
+ return planRefusal(observed.kind);
190
+ return {
191
+ ok: true,
192
+ plan: {
193
+ origin,
194
+ ops: [{ kind: 'remove', target, expect: { kind: 'present', version: observed.version } }],
195
+ },
196
+ };
197
+ }
198
+ /**
199
+ * Apply one plan through the provider and record the committed result for
200
+ * this owner. The re-read is temporary H2 bookkeeping; H5 replaces it with
201
+ * the provider's `SkillWriteOutcome`, so a post-commit read failure can never
202
+ * turn a landed write into a tool failure.
203
+ * @param plan - the write plan.
204
+ * @param owner - exact writer identity; omitted by internal callers that do
205
+ * not own observations.
206
+ * @returns the service-level result.
207
+ */
208
+ async apply(plan, owner) {
209
+ const result = await this.library.apply(plan);
210
+ if (result.ok && owner !== undefined) {
211
+ try {
212
+ await this.observeOutcomes(result, owner);
213
+ }
214
+ catch {
215
+ // The write is already committed; an observation-cache failure must not
216
+ // turn a landed write into a tool failure (K6).
217
+ }
218
+ }
219
+ return actionResult(result, plan);
220
+ }
221
+ async observeOutcomes(result, owner) {
222
+ for (const outcome of result.outcomes) {
223
+ if (outcome.version === undefined)
224
+ continue;
225
+ const target = outcome.target.identityKey === undefined ? await this.library.identify(outcome.target) : outcome.target;
226
+ this.observations.record(owner, target, outcome.version === '' ? { kind: 'absent' } : { kind: 'present', version: outcome.version });
227
+ }
228
+ }
54
229
  /**
55
230
  * Replace SKILL.md only when this owner observed its current version.
56
231
  * @param owner - exact writer identity.
@@ -59,16 +234,14 @@ export class SkillWriteService {
59
234
  * @returns write outcome or a typed refusal.
60
235
  */
61
236
  async updateBody(owner, name, content, origin = 'foreground') {
62
- const target = skillBodyTarget(name);
237
+ const target = await this.library.identify(skillBodyTarget(name));
63
238
  const observed = this.observations.requirePresent(owner, target);
64
239
  if (!('version' in observed))
65
240
  return refusal(observed.kind);
66
- return await this.locks.withLock(target.targetKey, async () => {
67
- const result = await this.library.update(name, content, origin, anchorOf(observed.version));
68
- if (result.ok)
69
- await this.readBody(owner, name);
70
- return actionResult(result);
71
- });
241
+ const result = await this.library.update(name, content, origin, anchorOf(observed.version));
242
+ if (result.ok)
243
+ await this.readBody(owner, name);
244
+ return actionResult(result);
72
245
  }
73
246
  /**
74
247
  * Patch SKILL.md only when this owner observed its current version.
@@ -80,16 +253,14 @@ export class SkillWriteService {
80
253
  * @returns write outcome or a typed refusal.
81
254
  */
82
255
  async patchBody(owner, name, oldString, newString, replaceAll = false, origin = 'foreground') {
83
- const target = skillBodyTarget(name);
256
+ const target = await this.library.identify(skillBodyTarget(name));
84
257
  const observed = this.observations.requirePresent(owner, target);
85
258
  if (!('version' in observed))
86
259
  return refusal(observed.kind);
87
- return await this.locks.withLock(target.targetKey, async () => {
88
- const result = await this.library.patch(name, oldString, newString, '', replaceAll, origin, anchorOf(observed.version));
89
- if (result.ok)
90
- await this.readBody(owner, name);
91
- return actionResult(result);
92
- });
260
+ const result = await this.library.patch(name, oldString, newString, '', replaceAll, origin, anchorOf(observed.version));
261
+ if (result.ok)
262
+ await this.readBody(owner, name);
263
+ return actionResult(result);
93
264
  }
94
265
  /**
95
266
  * Replace one support file only when this owner observed its current version.
@@ -100,29 +271,25 @@ export class SkillWriteService {
100
271
  * @returns write outcome or a typed refusal.
101
272
  */
102
273
  async updateSupport(owner, name, filePath, content, origin = 'foreground') {
103
- const target = skillSupportTarget(name, filePath);
274
+ const target = await this.library.identify(skillSupportTarget(name, filePath));
104
275
  const observed = this.observations.requirePresent(owner, target);
105
276
  if (!('version' in observed))
106
277
  return refusal(observed.kind);
107
- return await this.locks.withLock(target.targetKey, async () => {
108
- const result = await this.library.writeSupportFile(name, filePath, content, origin, anchorOf(observed.version));
109
- if (result.ok)
110
- await this.readSupport(owner, name, filePath);
111
- return actionResult(result);
112
- });
278
+ const result = await this.library.writeSupportFile(name, filePath, content, origin, anchorOf(observed.version));
279
+ if (result.ok)
280
+ await this.readSupport(owner, name, filePath);
281
+ return actionResult(result);
113
282
  }
114
283
  /** Remove a support file only after this owner read it at the observed version. */
115
284
  async removeSupport(owner, name, filePath, origin = 'foreground') {
116
- const target = skillSupportTarget(name, filePath);
285
+ const target = await this.library.identify(skillSupportTarget(name, filePath));
117
286
  const observed = this.observations.requirePresent(owner, target);
118
287
  if (!('version' in observed))
119
288
  return refusal(observed.kind);
120
- return await this.locks.withLock(target.targetKey, async () => {
121
- const result = await this.library.removeSupportFile(name, filePath, origin, anchorOf(observed.version));
122
- if (result.ok)
123
- this.observations.record(owner, target, { kind: 'absent' });
124
- return actionResult(result);
125
- });
289
+ const result = await this.library.removeSupportFile(name, filePath, origin, anchorOf(observed.version));
290
+ if (result.ok)
291
+ this.observations.record(owner, target, { kind: 'absent' });
292
+ return actionResult(result);
126
293
  }
127
294
  /**
128
295
  * Create a support file when absent, or update it only after this owner read it.
@@ -130,7 +297,7 @@ export class SkillWriteService {
130
297
  * existing unread file is refused rather than overwritten.
131
298
  */
132
299
  async writeSupport(owner, name, filePath, content, origin = 'foreground') {
133
- const target = skillSupportTarget(name, filePath);
300
+ const target = await this.library.identify(skillSupportTarget(name, filePath));
134
301
  const observed = this.observations.get(owner, target);
135
302
  if (observed === undefined) {
136
303
  const current = await this.library.readSupportFile(name, filePath);
@@ -169,10 +336,22 @@ function refusal(kind) {
169
336
  ? { ok: false, code: 'SKILL_NOT_OBSERVED', message: 'read the skill target before writing it' }
170
337
  : { ok: false, code: 'SKILL_NOT_FOUND', message: 'skill target does not exist' };
171
338
  }
339
+ function planRefusal(kind) {
340
+ return refusal(kind);
341
+ }
342
+ function notObserved() {
343
+ return planRefusal('unobserved');
344
+ }
172
345
  function anchorOf(version) { return { sha256: version }; }
173
- function actionResult(result) {
346
+ function actionResult(result, plan) {
174
347
  if (result.ok)
175
- return { ok: true, message: result.message, ...(result.noop === true ? { noop: true } : {}) };
348
+ return { ok: true, message: result.message, ...(result.noop === true ? { noop: true } : {}), ...(result.path === undefined ? {} : { path: result.path }), ...(result.normalizedFrontmatterFields === undefined ? {} : { normalizedFrontmatterFields: result.normalizedFrontmatterFields }) };
349
+ const only = plan?.ops.length === 1 ? plan.ops[0] : undefined;
350
+ const absentCreate = only !== undefined
351
+ && (only.kind === 'createSkill' || (only.kind === 'write' && only.target.relPath === '' && only.expect.kind === 'absent' && only.create !== false))
352
+ && (result.stale === true || /已存在|target appeared|changed after plan|concurrent modification/i.test(result.message));
353
+ if (absentCreate)
354
+ return { ok: false, code: 'SKILL_ALREADY_EXISTS', message: result.message };
176
355
  if (result.stale === true)
177
356
  return { ok: false, code: 'SKILL_STALE_VERSION', message: result.message };
178
357
  return { ok: false, code: 'SKILL_INVALID', message: result.message };
@@ -7,7 +7,9 @@ export * from './skill-reads.ts';
7
7
  export * from './skill-observation.ts';
8
8
  export * from './skill-observation-source.ts';
9
9
  export * from './skill-write-intent.ts';
10
+ export * from './skill-write-plan.ts';
10
11
  export * from './skill-write-service.ts';
12
+ export * from './system-skill-writer.ts';
11
13
  export * from './skill-target-locks.ts';
12
14
  export * from './skill-root-gate.ts';
13
15
  export * from './skill-row-cells.ts';
@@ -7,7 +7,9 @@ export * from "./skill-reads.js";
7
7
  export * from "./skill-observation.js";
8
8
  export * from "./skill-observation-source.js";
9
9
  export * from "./skill-write-intent.js";
10
+ export * from "./skill-write-plan.js";
10
11
  export * from "./skill-write-service.js";
12
+ export * from "./system-skill-writer.js";
11
13
  export * from "./skill-target-locks.js";
12
14
  export * from "./skill-root-gate.js";
13
15
  export * from "./skill-row-cells.js";
@@ -0,0 +1,47 @@
1
+ import type { EvolutionStateStorage } from './index.ts';
2
+ /**
3
+ * The assertion surface this suite needs. Vitest's `expect` satisfies it in-tree;
4
+ * a host with any other runner wraps its own in a few lines. Deliberately
5
+ * structural and minimal — the suite must not import a test runner.
6
+ */
7
+ export interface ConformanceAssert {
8
+ (actual: unknown): {
9
+ toBe(expected: unknown): void;
10
+ toEqual(expected: unknown): void;
11
+ toBeDefined(): void;
12
+ toBeUndefined(): void;
13
+ toBeNull(): void;
14
+ toContain(expected: unknown): void;
15
+ toHaveLength(length: number): void;
16
+ toBeGreaterThan(expected: number): void;
17
+ not: {
18
+ toBe(expected: unknown): void;
19
+ toContain(expected: unknown): void;
20
+ };
21
+ rejects: {
22
+ toThrow(expected?: unknown): Promise<void>;
23
+ };
24
+ };
25
+ }
26
+ /**
27
+ * The values a PROVIDER UNDER TEST may need to vary (U-2): a third-party medium can already hold
28
+ * records in the `c-…` namespace, and a strict schema may insist on a parseable `createdAt`. Every
29
+ * field defaults to the in-tree literals, so an existing caller's two-argument call is unchanged.
30
+ */
31
+ export interface ConformanceOptions {
32
+ /** Namespace for every pending record this run creates (default `'c-'`). */
33
+ idPrefix?: string;
34
+ /** Namespace for every claim id (default `'claim-'`). */
35
+ claimPrefix?: string;
36
+ /** The `createdAt` stamp every fixture record carries (default `'now'`). A provider whose
37
+ * schema requires a parseable time passes a real stamp here. */
38
+ createdAt?: string;
39
+ /** The review-state session the round-trip vector writes (default `'s-consistent'`). */
40
+ sessionId?: string;
41
+ /** The review-state session the ATTRIBUTION vector pins (default `attributionSessionId`). */
42
+ attributionSessionId?: string;
43
+ /** Namespace for the per-session cap vector's sessions (default `'s-cap-'`). */
44
+ reviewSessionPrefix?: string;
45
+ }
46
+ export declare function runStateProviderConsistency(provider: EvolutionStateStorage, assert: ConformanceAssert, options?: ConformanceOptions): Promise<void>;
47
+ //# sourceMappingURL=conformance.d.ts.map