@lmzhen/dsh-evolution-core 0.59.1 → 0.59.3

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 (41) hide show
  1. package/lib/authority-plugin.js +7 -4
  2. package/lib/{extract-plan-BxDhKSki.js → extract-plan-D3ALlAmN.js} +2 -2
  3. package/lib/extract.js +4 -4
  4. package/lib/index.js +9 -9
  5. package/lib/io-node.js +1 -1
  6. package/lib/{mutation-authority-Du-ON0NY.js → mutation-authority-CZpc9F20.js} +222 -4
  7. package/lib/{mutation-storage-adapter-7R3ra0wj.js → mutation-storage-adapter-z1_hyrQn.js} +10 -6
  8. package/lib/{mutations-mvTnWkua.js → mutations-Y-wKod7W.js} +2 -2
  9. package/lib/{quality-CREp6s1G.js → quality-NPGr3VzA.js} +3 -3
  10. package/lib/{review-context-CW_kJAzn.js → review-context-yNiZadPw.js} +1 -1
  11. package/lib/{skill-history-YX84wO20.js → skill-history-BvLWFoOo.js} +2 -2
  12. package/lib/skills.js +1023 -189
  13. package/lib/types/authority-plugin.d.ts +7 -1
  14. package/lib/types/authority-plugin.js +10 -2
  15. package/lib/types/authority.d.ts +49 -0
  16. package/lib/types/authority.js +194 -0
  17. package/lib/types/events.d.ts +2 -0
  18. package/lib/types/mutation-authority.d.ts +31 -2
  19. package/lib/types/mutation-authority.js +45 -1
  20. package/lib/types/mutation-unit.d.ts +23 -1
  21. package/lib/types/mutation-unit.js +7 -3
  22. package/lib/types/skill-observation-source.d.ts +26 -0
  23. package/lib/types/skill-observation-source.js +56 -0
  24. package/lib/types/skill-observation.d.ts +87 -0
  25. package/lib/types/skill-observation.js +110 -0
  26. package/lib/types/skill-root-gate.d.ts +40 -0
  27. package/lib/types/skill-root-gate.js +98 -0
  28. package/lib/types/skill-store.d.ts +22 -3
  29. package/lib/types/skill-store.js +437 -217
  30. package/lib/types/skill-target-locks.d.ts +39 -0
  31. package/lib/types/skill-target-locks.js +64 -0
  32. package/lib/types/skill-write-intent.d.ts +63 -0
  33. package/lib/types/skill-write-intent.js +104 -0
  34. package/lib/types/skill-write-service.d.ts +85 -0
  35. package/lib/types/skill-write-service.js +180 -0
  36. package/lib/types/skills.d.ts +6 -0
  37. package/lib/types/skills.js +6 -0
  38. package/lib/{usage-DrczLTP4.js → usage-D7yHG2Cb.js} +2 -2
  39. package/lib/write.js +3 -3
  40. package/package.json +3 -3
  41. package/lib/{io-GxghO3Ip.js → io-Cpa8wuvj.js} +1 -1
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Per-target promise locks for skill writes.
3
+ *
4
+ * The current SkillLibrary serial queue is per root, so writes to different
5
+ * skills serialize even though they share no bytes. This table is the
6
+ * replacement primitive: one tail promise per canonical target key, and a
7
+ * multi-target acquisition that takes keys in lexical order to make deadlock
8
+ * impossible. It is deliberately pure (no IO, no timeout) so the service can
9
+ * compose it with transactIo/HomeFence rather than duplicate lock semantics.
10
+ *
11
+ * @module @lmzhen/dsh-evolution-core/skill-target-locks
12
+ */
13
+ /** A lock table keyed by canonical skill target key. */
14
+ export declare class SkillTargetLocks {
15
+ private tails;
16
+ /**
17
+ * Run one task while holding one target key.
18
+ * @param targetKey - canonical skill target key.
19
+ * @param task - the read/compare/write critical section.
20
+ * @returns the task's value.
21
+ */
22
+ withLock<T>(targetKey: string, task: () => Promise<T>): Promise<T>;
23
+ /**
24
+ * Run one task while holding several target keys.
25
+ *
26
+ * Keys are deduplicated and acquired in lexical order; the caller may pass
27
+ * them in any order. A task must not call {@link withLock}/{@link withLocks}
28
+ * for a key it already holds (the promise chain is not reentrant), so callers
29
+ * should flatten multi-file units into one acquisition.
30
+ * @param targetKeys - canonical target keys touched by the unit.
31
+ * @param task - the unit's read/compare/write critical section.
32
+ * @returns the task's value.
33
+ */
34
+ withLocks<T>(targetKeys: readonly string[], task: () => Promise<T>): Promise<T>;
35
+ /** Number of live target queues; exposed for leak assertions in tests. */
36
+ get size(): number;
37
+ private acquire;
38
+ }
39
+ //# sourceMappingURL=skill-target-locks.d.ts.map
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Per-target promise locks for skill writes.
3
+ *
4
+ * The current SkillLibrary serial queue is per root, so writes to different
5
+ * skills serialize even though they share no bytes. This table is the
6
+ * replacement primitive: one tail promise per canonical target key, and a
7
+ * multi-target acquisition that takes keys in lexical order to make deadlock
8
+ * impossible. It is deliberately pure (no IO, no timeout) so the service can
9
+ * compose it with transactIo/HomeFence rather than duplicate lock semantics.
10
+ *
11
+ * @module @lmzhen/dsh-evolution-core/skill-target-locks
12
+ */
13
+ /** A lock table keyed by canonical skill target key. */
14
+ export class SkillTargetLocks {
15
+ tails = new Map();
16
+ /**
17
+ * Run one task while holding one target key.
18
+ * @param targetKey - canonical skill target key.
19
+ * @param task - the read/compare/write critical section.
20
+ * @returns the task's value.
21
+ */
22
+ async withLock(targetKey, task) {
23
+ return await this.withLocks([targetKey], task);
24
+ }
25
+ /**
26
+ * Run one task while holding several target keys.
27
+ *
28
+ * Keys are deduplicated and acquired in lexical order; the caller may pass
29
+ * them in any order. A task must not call {@link withLock}/{@link withLocks}
30
+ * for a key it already holds (the promise chain is not reentrant), so callers
31
+ * should flatten multi-file units into one acquisition.
32
+ * @param targetKeys - canonical target keys touched by the unit.
33
+ * @param task - the unit's read/compare/write critical section.
34
+ * @returns the task's value.
35
+ */
36
+ async withLocks(targetKeys, task) {
37
+ const keys = [...new Set(targetKeys)].sort();
38
+ return await this.acquire(keys, 0, task);
39
+ }
40
+ /** Number of live target queues; exposed for leak assertions in tests. */
41
+ get size() {
42
+ return this.tails.size;
43
+ }
44
+ async acquire(keys, index, task) {
45
+ const key = keys[index];
46
+ if (key === undefined)
47
+ return await task();
48
+ const prior = this.tails.get(key) ?? Promise.resolve();
49
+ let release;
50
+ const gate = new Promise((resolve) => { release = resolve; });
51
+ const tail = prior.then(() => gate);
52
+ this.tails.set(key, tail);
53
+ await prior;
54
+ try {
55
+ return await this.acquire(keys, index + 1, task);
56
+ }
57
+ finally {
58
+ release();
59
+ if (this.tails.get(key) === tail)
60
+ this.tails.delete(key);
61
+ }
62
+ }
63
+ }
64
+ //# sourceMappingURL=skill-target-locks.js.map
@@ -0,0 +1,63 @@
1
+ /** Current target state supplied by the storage layer. */
2
+ export type SkillWriteCurrent = {
3
+ readonly kind: 'present';
4
+ /** Opaque version token in the caller's version model. */
5
+ readonly version: string;
6
+ readonly content: string;
7
+ } | {
8
+ readonly kind: 'absent';
9
+ };
10
+ /** What a caller wants to write. */
11
+ export type SkillWriteIntent = {
12
+ readonly kind: 'createIfAbsent';
13
+ readonly next: string;
14
+ } | {
15
+ readonly kind: 'replaceIfVersion';
16
+ /** Version observed before planning the write, in the caller's model. */
17
+ readonly expected: string;
18
+ readonly next: string;
19
+ } | {
20
+ readonly kind: 'editIfVersion';
21
+ readonly expected: string;
22
+ readonly oldString: string;
23
+ readonly newString: string;
24
+ readonly replaceAll?: boolean;
25
+ };
26
+ /** Why an intent was refused. */
27
+ export type SkillWriteRefusalReason = 'already-exists' | 'not-found' | 'stale' | 'not-found-match' | 'ambiguous' | 'invalid';
28
+ /** The decision the caller executes under its lock. */
29
+ export type SkillWriteDecision = {
30
+ readonly kind: 'write';
31
+ readonly next: string;
32
+ /** Number of literal replacements; 0 for create/replace. */
33
+ readonly replacements: number;
34
+ } | {
35
+ readonly kind: 'refuse';
36
+ readonly reason: SkillWriteRefusalReason;
37
+ /** Human-facing detail for a typed tool error. */
38
+ readonly message: string;
39
+ };
40
+ /**
41
+ * Content version used when the caller owns canonical bytes (SkillLibrary
42
+ * reads). Platform-read observations use the platform token instead.
43
+ * @param content - canonical text.
44
+ * @returns sha256 of LF-normalized content.
45
+ */
46
+ export declare function skillContentVersion(content: string): string;
47
+ /**
48
+ * Decide one write against the current state.
49
+ * @param intent - the requested create/replace/edit.
50
+ * @param current - the target state read under the caller's write lock.
51
+ * @returns either the exact next bytes, or a typed refusal.
52
+ */
53
+ export declare function decideSkillWrite(intent: SkillWriteIntent, current: SkillWriteCurrent): SkillWriteDecision;
54
+ /**
55
+ * Apply one literal edit after the caller already checked the version.
56
+ * @param content - current content.
57
+ * @param oldString - exact literal to replace.
58
+ * @param newString - replacement.
59
+ * @param replaceAll - explicit all-occurrences mode; default is unique-match.
60
+ * @returns write decision with replacement count, or a typed refusal.
61
+ */
62
+ export declare function decideLiteralEdit(content: string, oldString: string, newString: string, replaceAll: boolean): SkillWriteDecision;
63
+ //# sourceMappingURL=skill-write-intent.d.ts.map
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Pure write-intent decision: the smallest authority primitive behind
3
+ * `SkillWriteService`.
4
+ *
5
+ * The caller supplies the *current* bytes and version it read under its own
6
+ * lock. This module decides whether the intent may write, and for `edit`
7
+ * performs the literal match after the version check. It has no IO, lock or
8
+ * session model, so the same rules can be tested and reused by the library,
9
+ * approval replay and unit transactions.
10
+ *
11
+ * Version values are opaque here: a caller using platform `FsVersion` passes
12
+ * that token, a caller that owns canonical bytes passes the content hash. The
13
+ * decision only compares equality; it never reinterprets a token.
14
+ *
15
+ * @module @lmzhen/dsh-evolution-core/skill-write-intent
16
+ */
17
+ import { contentHash } from "./mutations.js";
18
+ /**
19
+ * Content version used when the caller owns canonical bytes (SkillLibrary
20
+ * reads). Platform-read observations use the platform token instead.
21
+ * @param content - canonical text.
22
+ * @returns sha256 of LF-normalized content.
23
+ */
24
+ export function skillContentVersion(content) {
25
+ return contentHash(content);
26
+ }
27
+ /**
28
+ * Decide one write against the current state.
29
+ * @param intent - the requested create/replace/edit.
30
+ * @param current - the target state read under the caller's write lock.
31
+ * @returns either the exact next bytes, or a typed refusal.
32
+ */
33
+ export function decideSkillWrite(intent, current) {
34
+ switch (intent.kind) {
35
+ case 'createIfAbsent':
36
+ return current.kind === 'absent'
37
+ ? { kind: 'write', next: intent.next, replacements: 0 }
38
+ : { kind: 'refuse', reason: 'already-exists', message: 'skill target already exists' };
39
+ case 'replaceIfVersion':
40
+ if (current.kind === 'absent') {
41
+ return { kind: 'refuse', reason: 'not-found', message: 'skill target does not exist' };
42
+ }
43
+ if (current.version !== intent.expected) {
44
+ return { kind: 'refuse', reason: 'stale', message: 'skill target changed since it was read' };
45
+ }
46
+ return { kind: 'write', next: intent.next, replacements: 0 };
47
+ case 'editIfVersion': {
48
+ if (current.kind === 'absent') {
49
+ return { kind: 'refuse', reason: 'not-found', message: 'skill target does not exist' };
50
+ }
51
+ // Platform edit order: version before literal matching. A stale writer
52
+ // must re-read even when its old_string would still match a different region.
53
+ if (current.version !== intent.expected) {
54
+ return { kind: 'refuse', reason: 'stale', message: 'skill target changed since it was read' };
55
+ }
56
+ return decideLiteralEdit(current.content, intent.oldString, intent.newString, intent.replaceAll === true);
57
+ }
58
+ }
59
+ }
60
+ /**
61
+ * Apply one literal edit after the caller already checked the version.
62
+ * @param content - current content.
63
+ * @param oldString - exact literal to replace.
64
+ * @param newString - replacement.
65
+ * @param replaceAll - explicit all-occurrences mode; default is unique-match.
66
+ * @returns write decision with replacement count, or a typed refusal.
67
+ */
68
+ export function decideLiteralEdit(content, oldString, newString, replaceAll) {
69
+ if (oldString.length === 0) {
70
+ return { kind: 'refuse', reason: 'invalid', message: 'old_string must be a non-empty string' };
71
+ }
72
+ if (oldString === newString) {
73
+ return { kind: 'refuse', reason: 'invalid', message: 'old_string and new_string must differ' };
74
+ }
75
+ const offsets = matchOffsets(content, oldString);
76
+ if (offsets.length === 0) {
77
+ return { kind: 'refuse', reason: 'not-found-match', message: 'old_string did not appear verbatim' };
78
+ }
79
+ if (!replaceAll && offsets.length > 1) {
80
+ return { kind: 'refuse', reason: 'ambiguous', message: 'old_string appears more than once; make it unique or set replace_all' };
81
+ }
82
+ const first = offsets[0];
83
+ if (first === undefined) {
84
+ return { kind: 'refuse', reason: 'not-found-match', message: 'old_string did not appear verbatim' };
85
+ }
86
+ const next = replaceAll
87
+ ? content.split(oldString).join(newString)
88
+ : content.slice(0, first) + newString + content.slice(first + oldString.length);
89
+ return { kind: 'write', next, replacements: offsets.length };
90
+ }
91
+ /** All non-overlapping occurrences of a literal, in content order. */
92
+ function matchOffsets(content, literal) {
93
+ const offsets = [];
94
+ let from = 0;
95
+ while (from <= content.length - literal.length) {
96
+ const at = content.indexOf(literal, from);
97
+ if (at < 0)
98
+ break;
99
+ offsets.push(at);
100
+ from = at + literal.length;
101
+ }
102
+ return offsets;
103
+ }
104
+ //# sourceMappingURL=skill-write-intent.js.map
@@ -0,0 +1,85 @@
1
+ import type { SkillLibrary, WriteOrigin } from './skill-store.ts';
2
+ import type { SkillObservationStore } from './skill-observation.ts';
3
+ /** Exact execution identity for observations. */
4
+ export type SkillWriteOwner = object;
5
+ /** Stable failure codes for the future model-facing error map. */
6
+ export type SkillWriteErrorCode = 'SKILL_NOT_OBSERVED' | 'SKILL_STALE_VERSION' | 'SKILL_NOT_FOUND' | 'SKILL_ALREADY_EXISTS' | 'SKILL_AMBIGUOUS_EDIT' | 'SKILL_EDIT_NOT_FOUND' | 'SKILL_INVALID';
7
+ /** Result of one service operation. */
8
+ export type SkillWriteServiceResult = {
9
+ readonly ok: true;
10
+ readonly message: string;
11
+ readonly noop?: boolean;
12
+ readonly content?: string | null;
13
+ } | {
14
+ readonly ok: false;
15
+ readonly code: SkillWriteErrorCode;
16
+ readonly message: string;
17
+ };
18
+ /**
19
+ * Read body/support bytes and record the observation for the exact owner.
20
+ *
21
+ * A read failure is a failed read, not an observation; `null` means the file is
22
+ * authoritatively absent and is recorded as such.
23
+ */
24
+ export declare class SkillWriteService {
25
+ private readonly library;
26
+ private readonly observations;
27
+ private readonly locks;
28
+ constructor(library: SkillLibrary, observations: SkillObservationStore);
29
+ /**
30
+ * Read SKILL.md and record present/absent for this owner.
31
+ * @param owner - exact session/review/run identity.
32
+ * @param name - skill name.
33
+ * @returns the body, or null when absent.
34
+ */
35
+ readBody(owner: SkillWriteOwner, name: string): Promise<string | null>;
36
+ /**
37
+ * Read one support file and record present/absent for this owner.
38
+ * @param owner - exact session/review/run identity.
39
+ * @param name - skill name.
40
+ * @param filePath - support path.
41
+ * @returns the bytes, or null when absent.
42
+ */
43
+ readSupport(owner: SkillWriteOwner, name: string, filePath: string): Promise<string | null>;
44
+ /**
45
+ * Replace SKILL.md only when this owner observed its current version.
46
+ * @param owner - exact writer identity.
47
+ * @param name - skill name.
48
+ * @param content - full next body.
49
+ * @returns write outcome or a typed refusal.
50
+ */
51
+ updateBody(owner: SkillWriteOwner, name: string, content: string, origin?: WriteOrigin): Promise<SkillWriteServiceResult>;
52
+ /**
53
+ * Patch SKILL.md only when this owner observed its current version.
54
+ * @param owner - exact writer identity.
55
+ * @param name - skill name.
56
+ * @param oldString - literal to replace.
57
+ * @param newString - replacement.
58
+ * @param replaceAll - explicit all-occurrences mode.
59
+ * @returns write outcome or a typed refusal.
60
+ */
61
+ patchBody(owner: SkillWriteOwner, name: string, oldString: string, newString: string, replaceAll?: boolean, origin?: WriteOrigin): Promise<SkillWriteServiceResult>;
62
+ /**
63
+ * Replace one support file only when this owner observed its current version.
64
+ * @param owner - exact writer identity.
65
+ * @param name - skill name.
66
+ * @param filePath - support path.
67
+ * @param content - full next bytes.
68
+ * @returns write outcome or a typed refusal.
69
+ */
70
+ updateSupport(owner: SkillWriteOwner, name: string, filePath: string, content: string, origin?: WriteOrigin): Promise<SkillWriteServiceResult>;
71
+ /** Remove a support file only after this owner read it at the observed version. */
72
+ removeSupport(owner: SkillWriteOwner, name: string, filePath: string, origin?: WriteOrigin): Promise<SkillWriteServiceResult>;
73
+ /**
74
+ * Create a support file when absent, or update it only after this owner read it.
75
+ * A new support file is a createIfAbsent (no prior read is required); an
76
+ * existing unread file is refused rather than overwritten.
77
+ */
78
+ writeSupport(owner: SkillWriteOwner, name: string, filePath: string, content: string, origin?: WriteOrigin): Promise<SkillWriteServiceResult>;
79
+ /** Record a just-committed SKILL.md write for this owner (create/fallback path). */
80
+ observeBodyWrite(owner: SkillWriteOwner, name: string): Promise<void>;
81
+ /** Record a just-committed support-file write for this owner (fallback path). */
82
+ observeSupportWrite(owner: SkillWriteOwner, name: string, filePath: string): Promise<void>;
83
+ private record;
84
+ }
85
+ //# sourceMappingURL=skill-write-service.d.ts.map
@@ -0,0 +1,180 @@
1
+ /**
2
+ * The first service layer over skill observations and the CAS primitive.
3
+ *
4
+ * It is intentionally narrow while Phase C moves behavior off the tool:
5
+ * read records an observation for one owner; update/patch derive their expected
6
+ * version from that observation and execute through the library mutators with a
7
+ * content anchor, so validation/audit/history stay in their existing owner.
8
+ * existing create/update/patch paths keep their behavior.
9
+ *
10
+ * @module @lmzhen/dsh-evolution-core/skill-write-service
11
+ */
12
+ import { contentHash } from "./mutations.js";
13
+ import { skillBodyTarget, skillSupportTarget } from "./skill-observation.js";
14
+ import { SkillTargetLocks } from "./skill-target-locks.js";
15
+ /**
16
+ * Read body/support bytes and record the observation for the exact owner.
17
+ *
18
+ * A read failure is a failed read, not an observation; `null` means the file is
19
+ * authoritatively absent and is recorded as such.
20
+ */
21
+ export class SkillWriteService {
22
+ library;
23
+ observations;
24
+ locks = new SkillTargetLocks();
25
+ constructor(library, observations) {
26
+ this.library = library;
27
+ this.observations = observations;
28
+ }
29
+ /**
30
+ * Read SKILL.md and record present/absent for this owner.
31
+ * @param owner - exact session/review/run identity.
32
+ * @param name - skill name.
33
+ * @returns the body, or null when absent.
34
+ */
35
+ async readBody(owner, name) {
36
+ const target = skillBodyTarget(name);
37
+ const content = await this.library.read(name);
38
+ this.record(owner, target, content);
39
+ return content;
40
+ }
41
+ /**
42
+ * Read one support file and record present/absent for this owner.
43
+ * @param owner - exact session/review/run identity.
44
+ * @param name - skill name.
45
+ * @param filePath - support path.
46
+ * @returns the bytes, or null when absent.
47
+ */
48
+ async readSupport(owner, name, filePath) {
49
+ const target = skillSupportTarget(name, filePath);
50
+ const content = await this.library.readSupportFile(name, filePath);
51
+ this.record(owner, target, content);
52
+ return content;
53
+ }
54
+ /**
55
+ * Replace SKILL.md only when this owner observed its current version.
56
+ * @param owner - exact writer identity.
57
+ * @param name - skill name.
58
+ * @param content - full next body.
59
+ * @returns write outcome or a typed refusal.
60
+ */
61
+ async updateBody(owner, name, content, origin = 'foreground') {
62
+ const target = skillBodyTarget(name);
63
+ const observed = this.observations.requirePresent(owner, target);
64
+ if (!('version' in observed))
65
+ 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
+ });
72
+ }
73
+ /**
74
+ * Patch SKILL.md only when this owner observed its current version.
75
+ * @param owner - exact writer identity.
76
+ * @param name - skill name.
77
+ * @param oldString - literal to replace.
78
+ * @param newString - replacement.
79
+ * @param replaceAll - explicit all-occurrences mode.
80
+ * @returns write outcome or a typed refusal.
81
+ */
82
+ async patchBody(owner, name, oldString, newString, replaceAll = false, origin = 'foreground') {
83
+ const target = skillBodyTarget(name);
84
+ const observed = this.observations.requirePresent(owner, target);
85
+ if (!('version' in observed))
86
+ 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
+ });
93
+ }
94
+ /**
95
+ * Replace one support file only when this owner observed its current version.
96
+ * @param owner - exact writer identity.
97
+ * @param name - skill name.
98
+ * @param filePath - support path.
99
+ * @param content - full next bytes.
100
+ * @returns write outcome or a typed refusal.
101
+ */
102
+ async updateSupport(owner, name, filePath, content, origin = 'foreground') {
103
+ const target = skillSupportTarget(name, filePath);
104
+ const observed = this.observations.requirePresent(owner, target);
105
+ if (!('version' in observed))
106
+ 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
+ });
113
+ }
114
+ /** Remove a support file only after this owner read it at the observed version. */
115
+ async removeSupport(owner, name, filePath, origin = 'foreground') {
116
+ const target = skillSupportTarget(name, filePath);
117
+ const observed = this.observations.requirePresent(owner, target);
118
+ if (!('version' in observed))
119
+ 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
+ });
126
+ }
127
+ /**
128
+ * Create a support file when absent, or update it only after this owner read it.
129
+ * A new support file is a createIfAbsent (no prior read is required); an
130
+ * existing unread file is refused rather than overwritten.
131
+ */
132
+ async writeSupport(owner, name, filePath, content, origin = 'foreground') {
133
+ const target = skillSupportTarget(name, filePath);
134
+ const observed = this.observations.get(owner, target);
135
+ if (observed === undefined) {
136
+ const current = await this.library.readSupportFile(name, filePath);
137
+ if (current !== null)
138
+ return { ok: false, code: 'SKILL_NOT_OBSERVED', message: 'read the skill target before writing it' };
139
+ this.observations.record(owner, target, { kind: 'absent' });
140
+ const created = await this.library.writeSupportFile(name, filePath, content, origin);
141
+ if (created.ok)
142
+ await this.readSupport(owner, name, filePath);
143
+ return actionResult(created);
144
+ }
145
+ if (observed.kind === 'absent') {
146
+ const created = await this.library.writeSupportFile(name, filePath, content, origin);
147
+ if (created.ok)
148
+ await this.readSupport(owner, name, filePath);
149
+ return actionResult(created);
150
+ }
151
+ return await this.updateSupport(owner, name, filePath, content, origin);
152
+ }
153
+ /** Record a just-committed SKILL.md write for this owner (create/fallback path). */
154
+ async observeBodyWrite(owner, name) {
155
+ await this.readBody(owner, name);
156
+ }
157
+ /** Record a just-committed support-file write for this owner (fallback path). */
158
+ async observeSupportWrite(owner, name, filePath) {
159
+ await this.readSupport(owner, name, filePath);
160
+ }
161
+ record(owner, target, content) {
162
+ this.observations.record(owner, target, content === null
163
+ ? { kind: 'absent' }
164
+ : { kind: 'present', version: contentHash(content) });
165
+ }
166
+ }
167
+ function refusal(kind) {
168
+ return kind === 'unobserved'
169
+ ? { ok: false, code: 'SKILL_NOT_OBSERVED', message: 'read the skill target before writing it' }
170
+ : { ok: false, code: 'SKILL_NOT_FOUND', message: 'skill target does not exist' };
171
+ }
172
+ function anchorOf(version) { return { sha256: version }; }
173
+ function actionResult(result) {
174
+ if (result.ok)
175
+ return { ok: true, message: result.message, ...(result.noop === true ? { noop: true } : {}) };
176
+ if (result.stale === true)
177
+ return { ok: false, code: 'SKILL_STALE_VERSION', message: result.message };
178
+ return { ok: false, code: 'SKILL_INVALID', message: result.message };
179
+ }
180
+ //# sourceMappingURL=skill-write-service.js.map
@@ -4,6 +4,12 @@ export * from './skill-health.ts';
4
4
  export * from './skill-stats.ts';
5
5
  export * from './skill-operations.ts';
6
6
  export * from './skill-reads.ts';
7
+ export * from './skill-observation.ts';
8
+ export * from './skill-observation-source.ts';
9
+ export * from './skill-write-intent.ts';
10
+ export * from './skill-write-service.ts';
11
+ export * from './skill-target-locks.ts';
12
+ export * from './skill-root-gate.ts';
7
13
  export * from './skill-row-cells.ts';
8
14
  export * from './skill-history.ts';
9
15
  export * from './skill-store.ts';
@@ -4,6 +4,12 @@ export * from "./skill-health.js";
4
4
  export * from "./skill-stats.js";
5
5
  export * from "./skill-operations.js";
6
6
  export * from "./skill-reads.js";
7
+ export * from "./skill-observation.js";
8
+ export * from "./skill-observation-source.js";
9
+ export * from "./skill-write-intent.js";
10
+ export * from "./skill-write-service.js";
11
+ export * from "./skill-target-locks.js";
12
+ export * from "./skill-root-gate.js";
7
13
  export * from "./skill-row-cells.js";
8
14
  export * from "./skill-history.js";
9
15
  export * from "./skill-store.js";
@@ -1,7 +1,7 @@
1
- import { c as transactIo, o as nodeEvolutionIo } from "./io-GxghO3Ip.js";
1
+ import { c as transactIo, o as nodeEvolutionIo } from "./io-Cpa8wuvj.js";
2
2
  import { o as resolveCitations } from "./citations-CZKTUGQF.js";
3
3
  import { n as isRecord } from "./guards-3f02mnf2.js";
4
- import { p as parseFrontmatter, u as frontmatterBlock } from "./mutations-mvTnWkua.js";
4
+ import { p as parseFrontmatter, u as frontmatterBlock } from "./mutations-Y-wKod7W.js";
5
5
  import { join } from "node:path";
6
6
  //#region lib/types/reference-rewrite.js
7
7
  /**
package/lib/write.js CHANGED
@@ -1,6 +1,6 @@
1
- import { r as contentHash } from "./mutations-mvTnWkua.js";
2
- import { p as entryTarget } from "./skill-history-YX84wO20.js";
3
- import { C as writeUnitEvidence, D as fileMutationLock, E as MutationUnit, O as validateMutationRequest, S as upsertUnitIndex, T as writeUnitSnapshot, _ as unitIndexPath, a as UNIT_JOURNAL_SCHEMA_VERSION, b as unitSnapshotsDir, c as unitJournalPath, d as UNIT_STORAGE_SCHEMA_VERSION, f as readUnitEvidence, g as unitEvidencePath, h as readUnitSnapshot, i as UNIT_JOURNAL_PHASES, k as WriteKernel, l as unitJournalPhaseRank, m as readUnitReceipt, n as unitJournalPort, o as assertUnitJournalTransition, p as readUnitIndex, r as unitSnapshotPort, s as readUnitJournal, t as pruneTreeChangeUnits, u as writeUnitJournal, v as unitReceiptPath, w as writeUnitReceipt, x as unitStorageKey, y as unitSnapshotPath } from "./mutation-storage-adapter-7R3ra0wj.js";
1
+ import { r as contentHash } from "./mutations-Y-wKod7W.js";
2
+ import { p as entryTarget } from "./skill-history-BvLWFoOo.js";
3
+ import { C as writeUnitEvidence, D as fileMutationLock, E as MutationUnit, O as validateMutationRequest, S as upsertUnitIndex, T as writeUnitSnapshot, _ as unitIndexPath, a as UNIT_JOURNAL_SCHEMA_VERSION, b as unitSnapshotsDir, c as unitJournalPath, d as UNIT_STORAGE_SCHEMA_VERSION, f as readUnitEvidence, g as unitEvidencePath, h as readUnitSnapshot, i as UNIT_JOURNAL_PHASES, k as WriteKernel, l as unitJournalPhaseRank, m as readUnitReceipt, n as unitJournalPort, o as assertUnitJournalTransition, p as readUnitIndex, r as unitSnapshotPort, s as readUnitJournal, t as pruneTreeChangeUnits, u as writeUnitJournal, v as unitReceiptPath, w as writeUnitReceipt, x as unitStorageKey, y as unitSnapshotPath } from "./mutation-storage-adapter-z1_hyrQn.js";
4
4
  //#region lib/types/unit-undo.js
5
5
  /**
6
6
  * Cross-skill unit undo executor.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@lmzhen/dsh-evolution-core",
3
3
  "description": "Shared stores, prompts, signals and lifecycle logic for the dsh-evolution plugin family (community build)",
4
- "version": "0.59.1",
4
+ "version": "0.59.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -98,8 +98,8 @@
98
98
  "yaml": "^2.4.2",
99
99
  "zod": "^4.4.3",
100
100
  "@deepseek-ai/schemastery": "^3.18.5",
101
- "@lmzhen/dsh-evolution-adapter": "0.59.1",
102
- "@lmzhen/dsh-evolution-platform-contract": "0.59.1"
101
+ "@lmzhen/dsh-evolution-adapter": "0.59.3",
102
+ "@lmzhen/dsh-evolution-platform-contract": "0.59.3"
103
103
  },
104
104
  "peerDependencies": {
105
105
  "@deepseek-ai/cordis": "^4.0.5"
@@ -1,7 +1,7 @@
1
+ import { randomBytes } from "node:crypto";
1
2
  import { cp, lstat, mkdir, open, readFile, readdir, rename, rm, stat } from "node:fs/promises";
2
3
  import { basename, dirname, join } from "node:path";
3
4
  import { copyFileSync, existsSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
4
- import { randomBytes } from "node:crypto";
5
5
  //#region lib/types/probe.js
6
6
  function probePresent(value) {
7
7
  return {