@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
@@ -36,11 +36,13 @@ import { type WriteAuthority } from './write-authority.ts';
36
36
  import { transactIo, type EvolutionIoLike } from './io.ts';
37
37
  import { type Probe } from './probe.ts';
38
38
  import type { SkillLimits } from './limits.ts';
39
- import { type MutationLockPort, type MutationResult } from './mutation-unit.ts';
39
+ import { type MutationLockPort, type MutationResult } from './unit-kernel.ts';
40
40
  import { SkillModel } from './skill-model.ts';
41
41
  import { type ExtractPlanDraft } from './extract-plan.ts';
42
42
  import { type MutationRecord } from './mutations.ts';
43
43
  import { type SkillWriteIntent, type SkillWriteRefusalReason } from './skill-write-intent.ts';
44
+ import type { SkillWritePlan, SkillWriteResult } from './skill-write-plan.ts';
45
+ import { type SkillTarget } from './skill-observation.ts';
44
46
  import { type RevisionAnchor, type RevisionFile } from './skill-revision.ts';
45
47
  import { type ChangeSummary, type UnitHead, type HistoryFence, type SkillVersion } from './skill-history.ts';
46
48
  import { type SkillHealthAssessment, type SkillHealthThresholds } from './skill-health.ts';
@@ -120,6 +122,8 @@ export interface SkillActionResult {
120
122
  stale?: true;
121
123
  /** The locked read's verdict for the caller's anchor. */
122
124
  anchor?: AnchorVerdict;
125
+ /** Committed bytes of this write; null for a removal. */
126
+ after?: string | null;
123
127
  }
124
128
  /**
125
129
  * One section move of a restructure proposal (008 batch B): a body section
@@ -342,6 +346,31 @@ export declare function markerEntryName(marker: 'bundled' | 'hub-installed' | 'p
342
346
  * Single source shared with the plan validator. */
343
347
  export declare function validateRestructureTarget(filePath: string): string | null;
344
348
  export declare function validateSupportPath(filePath: string): string | null;
349
+ /**
350
+ * Index of `pattern` inside `content`, treating whitespace runs (spaces/tabs)
351
+ * as flexible and literal escape sequences (`\n`, `\t`, `\r`) as their real
352
+ * characters: a PATTERN whitespace run matches any content run of any length
353
+ * (even empty), while extra whitespace that only exists in the content is not
354
+ * skipped — the flexibility is one-sided on the pattern, and a backslash-
355
+ * escaped char in the pattern matches the real char in the content
356
+ * (model-copy drift). Returns the [start, end) range in the ORIGINAL content
357
+ * so a patch can replace exactly the matched span and keep every other byte
358
+ * intact. Returns null when no fuzzy match exists.
359
+ */
360
+ interface PlannedRestructureSection {
361
+ rel: string;
362
+ heading: string;
363
+ text: string;
364
+ }
365
+ /** Project one restructure without writing: the operator preview and the store share the planner. */
366
+ export declare function projectRestructureMarkdown(markdown: string, moves: SkillRestructureMove[]): {
367
+ ok: true;
368
+ body: string;
369
+ sections: readonly PlannedRestructureSection[];
370
+ } | {
371
+ ok: false;
372
+ message: string;
373
+ };
345
374
  /** One low-level CAS result; no audit/event is emitted by this primitive. */
346
375
  export interface SkillFileCasResult {
347
376
  readonly ok: boolean;
@@ -368,7 +397,7 @@ export declare class SkillLibrary {
368
397
  private readonly serial;
369
398
  /** Transitional target locks (same key as SkillWriteService). */
370
399
  private readonly targetLocks;
371
- /** Root structural gate; simple writes still use the serial until D.5d. */
400
+ /** Root structural gate; shared per canonical root across library instances. */
372
401
  private readonly rootGate;
373
402
  /** V10-03 (P2-18): see the constructor's threatExemptLabels. Empty by
374
403
  * default — the strict ANY-hit-blocks policy is unchanged. */
@@ -385,14 +414,34 @@ export declare class SkillLibrary {
385
414
  constructor(root?: string, io?: EvolutionIoLike, limits?: SkillLimits, onMutation?: (event: EvolutionSkillMutatedEvent) => void, transact?: typeof transactIo, threatExemptLabels?: readonly string[], authority?: WriteAuthority, mutationLock?: MutationLockPort, fence?: HistoryFence);
386
415
  /**
387
416
  * Transitional root lock for mutators that still own their write path. The
388
- * extract/restructure path takes the same lock through MutationUnit, so those
417
+ * extract/restructure path takes the same lock through UnitKernel, so those
389
418
  * two paths cannot interleave with create/update/patch across processes.
390
419
  */
391
420
  private unitHeadForOps;
392
421
  /** Transitional: serialize one target even while the root serial remains. */
393
422
  private withTarget;
423
+ /** Canonicalize several logical target keys for one lock acquisition. */
424
+ private canonicalLockKeys;
425
+ /**
426
+ * Attach the canonical realpath identity to one observation target.
427
+ * @param target - logical skill target.
428
+ * @returns the target with `identityKey`; the logical targetKey is unchanged.
429
+ */
430
+ identify(target: SkillTarget): Promise<SkillTarget>;
431
+ /**
432
+ * Canonical in-process lock identity for one skill target key.
433
+ *
434
+ * A logical `skill::name::path` key is resolved through realpath (or the
435
+ * nearest existing ancestor for a not-yet-created file) and hashed, so two
436
+ * spellings/symlinks of the same host file share one promise-lock queue. The
437
+ * logical targetKey stays the observation/approval key until the observation
438
+ * resolver phase; this method only fixes the provider lock identity.
439
+ * @param targetKey - the family's logical skill target key.
440
+ * @returns the canonical lock key, or the input for non-skill keys.
441
+ */
442
+ private canonicalTargetKey;
394
443
  private withMutationLock;
395
- /** The one MutationUnit constructor: storage ports are fixed here, callers pass the rest. */
444
+ /** The one UnitKernel constructor: storage ports are fixed here, callers pass the rest. */
396
445
  private commitUnit;
397
446
  /** The one frontmatter pipeline for create/update/patch; patch keeps its cap checks outside. */
398
447
  private prepareBody;
@@ -772,6 +821,26 @@ export declare class SkillLibrary {
772
821
  private restoreFromArchiveCore;
773
822
  /** Result of the low-level CAS primitive. It intentionally has no audit/event. */
774
823
  writeFileCas(rawName: string, filePath: string, intent: SkillWriteIntent): Promise<SkillFileCasResult>;
824
+ /**
825
+ * Execute one plan-level write through the existing mutators.
826
+ *
827
+ * H1 deliberately supports one op only: it is the stable seam the tool and
828
+ * approval will move onto, while the multi-op UnitTransaction path is the
829
+ * next phase. Refusing a partial plan is safer than committing half of it.
830
+ * @param plan - origin plus the single operation to apply.
831
+ * @returns the action result; `outcomes` stays empty until the provider
832
+ * returns before/after/version in the next phase.
833
+ */
834
+ apply(plan: SkillWritePlan): Promise<SkillWriteResult>;
835
+ /**
836
+ * Commit a multi-op plan as one atomic unit. Each op is first prepared by the
837
+ * existing single-op mutator in a collector context (so its validation and
838
+ * anchor/CAS checks stay the source of truth), then all collected writes are
839
+ * handed to ONE UnitKernel. Any preparation failure or stale anchor leaves
840
+ * every target untouched.
841
+ */
842
+ private applyMulti;
843
+ private applyOne;
775
844
  writeSupportFile(rawName: string, filePath: string, content: string, origin?: WriteOrigin, anchor?: WriteAnchor): Promise<SkillActionResult>;
776
845
  private writeSupportFileCore;
777
846
  removeSupportFile(rawName: string, filePath: string, origin?: WriteOrigin, anchor?: WriteAnchor, unitId?: string): Promise<SkillActionResult>;