@deepseek-ai/dsh-subagent 0.1.2-alpha.3 → 0.1.2-alpha.4

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.
@@ -1,148 +0,0 @@
1
- /**
2
- * Internal registry of deployment capabilities composed into every continuable
3
- * child's unpublished creation context.
4
- *
5
- * A contribution grants a child-scoped capability without teaching the
6
- * continuation manager which capabilities exist. The manager owns residency;
7
- * this registry owns the join between plugin lifetime, unpublished setup, and
8
- * Activation disposal, so no installation outlives either owner and no removed
9
- * contribution can be installed after revocation reports completion.
10
- *
11
- * @module @deepseek-ai/dsh-subagent/activation-setup-registry
12
- */
13
- import { errorChain } from '@deepseek-ai/dsh-llm';
14
- import { SubagentError } from "./error.js";
15
- /** Re-read mutable removal state after a contribution may have revoked itself. */
16
- function isRemoved(registration) {
17
- return registration.removed;
18
- }
19
- /**
20
- * Owns continuable-child setup registrations, installations, rollback, child
21
- * cleanup, and immediate live revocation.
22
- */
23
- export class SubagentActivationSetupRegistry {
24
- /** Live contributions in installation order. */
25
- registrations = new Set();
26
- /** Child context to its live installations. */
27
- byChild = new Map();
28
- /**
29
- * Register one contribution.
30
- * @param contribution - synchronous child-scope installer.
31
- * @returns an idempotent registration undo.
32
- * @throws after attempting every installation when any disposer fails.
33
- */
34
- register(contribution) {
35
- const registration = { contribution, removed: false, installations: new Set() };
36
- this.registrations.add(registration);
37
- return () => {
38
- if (registration.removed)
39
- return;
40
- // Close before disposal so a snapshotted apply() cannot install after
41
- // revocation reports completion.
42
- registration.removed = true;
43
- this.registrations.delete(registration);
44
- this.releaseAll([...registration.installations], 'contribution removal');
45
- };
46
- }
47
- /**
48
- * Install every live contribution into one unpublished child context.
49
- * @param childCtx - the child's unpublished scoped context.
50
- * @returns the provisioning commit consumed at Agent publication.
51
- */
52
- apply(childCtx) {
53
- const state = { installations: [], invalidated: false };
54
- try {
55
- for (const registration of [...this.registrations]) {
56
- /* v8 ignore next -- only a synchronous re-entrant revocation of an
57
- * already-snapshotted registration reaches this guard. */
58
- if (registration.removed)
59
- continue;
60
- const installation = {
61
- registration,
62
- childCtx,
63
- dispose: registration.contribution(childCtx),
64
- released: false,
65
- transaction: state,
66
- };
67
- registration.installations.add(installation);
68
- state.installations.push(installation);
69
- let indexed = this.byChild.get(childCtx);
70
- if (indexed === undefined) {
71
- indexed = new Set();
72
- this.byChild.set(childCtx, indexed);
73
- }
74
- indexed.add(installation);
75
- // An installer may revoke itself before its installation record exists.
76
- // Dispose that escaped record and invalidate the provisioning batch.
77
- if (isRemoved(registration))
78
- this.release(installation);
79
- }
80
- }
81
- catch (error) {
82
- // Keep the installer failure authoritative, but attempt every rollback.
83
- try {
84
- this.releaseAll([...state.installations], 'setup rollback');
85
- }
86
- catch (releaseFailure) {
87
- /* v8 ignore next -- requires independent installer and rollback faults. */
88
- void releaseFailure;
89
- }
90
- throw error;
91
- }
92
- childCtx.effect(() => () => { this.releaseChild(childCtx); }, 'subagents.activationSetup()');
93
- return {
94
- commit: () => {
95
- if (state.invalidated) {
96
- throw new SubagentError('a continuable-subagent setup contribution was revoked while this child was being built; '
97
- + 'the child was not established', 'ACTIVATION_SETUP_REVOKED');
98
- }
99
- for (const installation of state.installations)
100
- installation.transaction = undefined;
101
- },
102
- };
103
- }
104
- /** Release every remaining installation owned by one disposed child scope. */
105
- releaseChild(childCtx) {
106
- const indexed = this.byChild.get(childCtx) ?? [];
107
- this.releaseAll([...indexed], 'child scope disposal');
108
- }
109
- /**
110
- * Release a batch completely before reporting disposer failures.
111
- * @param installations - records to release.
112
- * @param during - operation name for diagnostics.
113
- */
114
- releaseAll(installations, during) {
115
- const failures = [];
116
- for (const installation of installations) {
117
- try {
118
- this.release(installation);
119
- }
120
- catch (error) {
121
- failures.push(error);
122
- }
123
- }
124
- if (failures.length === 0)
125
- return;
126
- throw new SubagentError(`continuable-subagent setup ${during} failed to release ${failures.length} installation(s): `
127
- + failures.map(failure => errorChain(failure)).join('; '), 'ACTIVATION_SETUP_RELEASE_FAILED');
128
- }
129
- /** Drop one installation from both indices and dispose it exactly once. */
130
- release(installation) {
131
- if (installation.released)
132
- return;
133
- installation.released = true;
134
- installation.registration.installations.delete(installation);
135
- const indexed = this.byChild.get(installation.childCtx);
136
- /* v8 ignore next 4 -- every live installation is indexed until this method removes it. */
137
- if (indexed !== undefined) {
138
- indexed.delete(installation);
139
- if (indexed.size === 0)
140
- this.byChild.delete(installation.childCtx);
141
- }
142
- if (installation.transaction !== undefined)
143
- installation.transaction.invalidated = true;
144
- installation.dispose();
145
- }
146
- }
147
- export default SubagentActivationSetupRegistry;
148
- //# sourceMappingURL=activation-setup-registry.js.map