@klarkxy/dsh-fusion 0.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.
@@ -0,0 +1,173 @@
1
+ //#region src/contracts.d.ts
2
+ /** Public, browser-safe Fusion records. Native Sessions remain the transcript authority. */
3
+ declare const FUSION_PLUGIN = "@klarkxy/dsh-fusion";
4
+ declare const FUSION_RPC_CHANNEL = "/dsh-fusion";
5
+ declare const FUSION_PURPOSE = "fusion.sidekick";
6
+ declare const FUSION_TOOLS: readonly ["fusion_delegate", "fusion_report", "fusion_review", "fusion_read", "fusion_decide", "fusion_cancel"];
7
+ type FusionProfile = 'generic' | 'writing';
8
+ type TaskState = 'dispatching' | 'working' | 'decision' | 'review' | 'accepted' | 'cancelled' | 'failed' | 'interrupted';
9
+ type ModelRoute = {
10
+ provider: string;
11
+ model: string;
12
+ reasoningEffort?: string;
13
+ };
14
+ type Json = null | boolean | number | string | Json[] | {
15
+ [key: string]: Json;
16
+ };
17
+ interface FusionActor {
18
+ sessionId: string;
19
+ parentSessionId?: string;
20
+ project: string;
21
+ }
22
+ interface FusionBrief {
23
+ title: string;
24
+ goal: string;
25
+ context: string;
26
+ constraints: string[];
27
+ acceptance: string[];
28
+ }
29
+ /** A domain-owned, versioned destination. The Writer cannot replace this target. */
30
+ interface FusionTarget {
31
+ domain: string;
32
+ data: {
33
+ [key: string]: Json;
34
+ };
35
+ }
36
+ interface FusionCandidate {
37
+ id: string;
38
+ taskRevision: number;
39
+ revision: number;
40
+ text: string;
41
+ hash: string;
42
+ report: string;
43
+ createdAt: number;
44
+ }
45
+ interface FusionReview {
46
+ candidateId: string;
47
+ candidateHash: string;
48
+ verdict: 'accept' | 'revise' | 'reject';
49
+ feedback: string;
50
+ createdAt: number;
51
+ }
52
+ interface FusionTask {
53
+ id: string;
54
+ revision: number;
55
+ state: TaskState;
56
+ brief: FusionBrief;
57
+ target?: FusionTarget;
58
+ candidates: FusionCandidate[];
59
+ reviews: FusionReview[];
60
+ messageIds: string[];
61
+ dispatchId: string;
62
+ reportIds: string[];
63
+ /** Last report whose native Lead notification was confirmed and durably recorded. */
64
+ notifiedReportId?: string;
65
+ /** Whether the latest native inbox submission is known to have been accepted. */
66
+ delivery: 'pending' | 'accepted' | 'uncertain';
67
+ decision?: string;
68
+ error?: string;
69
+ cleanup?: 'pending' | 'done' | 'failed';
70
+ adoption?: 'pending' | 'applied' | 'dismissed' | 'conflict';
71
+ /** Persist before filesystem mutation; never replay an uncertain write. */
72
+ application?: {
73
+ id: string;
74
+ candidateId: string;
75
+ candidateHash: string;
76
+ path: string;
77
+ beforeVersion: string;
78
+ afterHash: string;
79
+ state: 'pending' | 'applied' | 'conflict';
80
+ version?: string;
81
+ };
82
+ createdAt: number;
83
+ updatedAt: number;
84
+ }
85
+ interface FusionPair {
86
+ id: string;
87
+ leadSessionId: string;
88
+ childSessionId: string;
89
+ project: string;
90
+ profile: FusionProfile;
91
+ route: ModelRoute;
92
+ /** A successful initial inbox admission, not a claim about provider prompt caching. */
93
+ established: boolean;
94
+ tasks: FusionTask[];
95
+ createdAt: number;
96
+ }
97
+ interface FusionState {
98
+ version: 1;
99
+ revision: number;
100
+ pairs: FusionPair[];
101
+ }
102
+ interface FusionStore {
103
+ load(): FusionState;
104
+ save(next: FusionState): Promise<void>;
105
+ }
106
+ /** This port adapts native subagents. It must not own another Agent loop or inbox. */
107
+ interface FusionNative {
108
+ dispatch(input: {
109
+ pair: FusionPair;
110
+ task: FusionTask;
111
+ prompt: string;
112
+ signal: AbortSignal;
113
+ }): Promise<{
114
+ messageId: string;
115
+ }>;
116
+ notify(input: {
117
+ pair: FusionPair;
118
+ task: FusionTask;
119
+ actor: FusionActor;
120
+ text: string;
121
+ signal: AbortSignal;
122
+ }): Promise<void>;
123
+ stop(pair: FusionPair, stopLead: boolean): Promise<void>;
124
+ }
125
+ interface FusionStatus {
126
+ available: boolean;
127
+ profile: FusionProfile;
128
+ configured: boolean;
129
+ revision?: number;
130
+ error?: string;
131
+ pair?: FusionPair;
132
+ /** Cumulative native-session figures, not an estimate of this task's cost. */
133
+ usage?: {
134
+ leadTokens: number | null;
135
+ sidekickTokens: number | null;
136
+ cost: null;
137
+ };
138
+ activity?: {
139
+ lead: string;
140
+ sidekick: string;
141
+ };
142
+ }
143
+ type RpcResult<T = unknown> = {
144
+ ok: true;
145
+ value: T;
146
+ } | {
147
+ ok: false;
148
+ error: {
149
+ code: string;
150
+ message: string;
151
+ };
152
+ };
153
+ declare const isWorking: (state: TaskState) => boolean;
154
+ declare const emptyFusionState: () => FusionState;
155
+ /** Browser commands identify stored authority; no command accepts replacement candidate text. */
156
+ interface FusionCandidateAction {
157
+ sessionId: string;
158
+ taskId: string;
159
+ taskRevision: number;
160
+ candidateId: string;
161
+ hash: string;
162
+ }
163
+ interface FusionPreview {
164
+ path: string;
165
+ before: string;
166
+ after: string;
167
+ version: string;
168
+ candidateId: string;
169
+ hash: string;
170
+ }
171
+ //#endregion
172
+ export { FUSION_PLUGIN, FUSION_PURPOSE, FUSION_RPC_CHANNEL, FUSION_TOOLS, FusionActor, FusionBrief, FusionCandidate, FusionCandidateAction, FusionNative, FusionPair, FusionPreview, FusionProfile, FusionReview, FusionState, FusionStatus, FusionStore, FusionTarget, FusionTask, Json, ModelRoute, RpcResult, TaskState, emptyFusionState, isWorking };
173
+ //# sourceMappingURL=contracts.d.ts.map
@@ -0,0 +1,28 @@
1
+ //#region src/contracts.ts
2
+ /** Public, browser-safe Fusion records. Native Sessions remain the transcript authority. */
3
+ const FUSION_PLUGIN = "@klarkxy/dsh-fusion";
4
+ const FUSION_RPC_CHANNEL = "/dsh-fusion";
5
+ const FUSION_PURPOSE = "fusion.sidekick";
6
+ const FUSION_TOOLS = [
7
+ "fusion_delegate",
8
+ "fusion_report",
9
+ "fusion_review",
10
+ "fusion_read",
11
+ "fusion_decide",
12
+ "fusion_cancel"
13
+ ];
14
+ const isWorking = (state) => [
15
+ "dispatching",
16
+ "working",
17
+ "decision",
18
+ "review"
19
+ ].includes(state);
20
+ const emptyFusionState = () => ({
21
+ version: 1,
22
+ revision: 0,
23
+ pairs: []
24
+ });
25
+ //#endregion
26
+ export { FUSION_PLUGIN, FUSION_PURPOSE, FUSION_RPC_CHANNEL, FUSION_TOOLS, emptyFusionState, isWorking };
27
+
28
+ //# sourceMappingURL=contracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contracts.js","names":[],"sources":["../src/contracts.ts"],"sourcesContent":["/** Public, browser-safe Fusion records. Native Sessions remain the transcript authority. */\nexport const FUSION_PLUGIN = '@klarkxy/dsh-fusion'\nexport const FUSION_RPC_CHANNEL = '/dsh-fusion'\nexport const FUSION_PURPOSE = 'fusion.sidekick'\nexport const FUSION_TOOLS = ['fusion_delegate', 'fusion_report', 'fusion_review', 'fusion_read', 'fusion_decide', 'fusion_cancel'] as const\nexport type FusionProfile = 'generic' | 'writing'\nexport type TaskState = 'dispatching' | 'working' | 'decision' | 'review' | 'accepted' | 'cancelled' | 'failed' | 'interrupted'\nexport type ModelRoute = { provider: string; model: string; reasoningEffort?: string }\nexport type Json = null | boolean | number | string | Json[] | { [key: string]: Json }\nexport interface FusionActor { sessionId: string; parentSessionId?: string; project: string }\nexport interface FusionBrief {\n title: string\n goal: string\n context: string\n constraints: string[]\n acceptance: string[]\n}\n/** A domain-owned, versioned destination. The Writer cannot replace this target. */\nexport interface FusionTarget { domain: string; data: { [key: string]: Json } }\nexport interface FusionCandidate {\n id: string\n taskRevision: number\n revision: number\n text: string\n hash: string\n report: string\n createdAt: number\n}\nexport interface FusionReview {\n candidateId: string\n candidateHash: string\n verdict: 'accept' | 'revise' | 'reject'\n feedback: string\n createdAt: number\n}\nexport interface FusionTask {\n id: string\n revision: number\n state: TaskState\n brief: FusionBrief\n target?: FusionTarget\n candidates: FusionCandidate[]\n reviews: FusionReview[]\n messageIds: string[]\n dispatchId: string\n reportIds: string[]\n /** Last report whose native Lead notification was confirmed and durably recorded. */\n notifiedReportId?: string\n /** Whether the latest native inbox submission is known to have been accepted. */\n delivery: 'pending' | 'accepted' | 'uncertain'\n decision?: string\n error?: string\n cleanup?: 'pending' | 'done' | 'failed'\n adoption?: 'pending' | 'applied' | 'dismissed' | 'conflict'\n /** Persist before filesystem mutation; never replay an uncertain write. */\n application?: {\n id: string; candidateId: string; candidateHash: string; path: string\n beforeVersion: string; afterHash: string; state: 'pending' | 'applied' | 'conflict'; version?: string\n }\n createdAt: number\n updatedAt: number\n}\nexport interface FusionPair {\n id: string\n leadSessionId: string\n childSessionId: string\n project: string\n profile: FusionProfile\n route: ModelRoute\n /** A successful initial inbox admission, not a claim about provider prompt caching. */\n established: boolean\n tasks: FusionTask[]\n createdAt: number\n}\nexport interface FusionState { version: 1; revision: number; pairs: FusionPair[] }\nexport interface FusionStore { load(): FusionState; save(next: FusionState): Promise<void> }\n/** This port adapts native subagents. It must not own another Agent loop or inbox. */\nexport interface FusionNative {\n dispatch(input: { pair: FusionPair; task: FusionTask; prompt: string; signal: AbortSignal }): Promise<{ messageId: string }>\n notify(input: { pair: FusionPair; task: FusionTask; actor: FusionActor; text: string; signal: AbortSignal }): Promise<void>\n stop(pair: FusionPair, stopLead: boolean): Promise<void>\n}\nexport interface FusionStatus {\n available: boolean\n profile: FusionProfile\n configured: boolean\n revision?: number\n error?: string\n pair?: FusionPair\n /** Cumulative native-session figures, not an estimate of this task's cost. */\n usage?: { leadTokens: number | null; sidekickTokens: number | null; cost: null }\n activity?: { lead: string; sidekick: string }\n}\nexport type RpcResult<T = unknown> = { ok: true; value: T } | { ok: false; error: { code: string; message: string } }\nexport const isWorking = (state: TaskState): boolean => ['dispatching', 'working', 'decision', 'review'].includes(state)\nexport const emptyFusionState = (): FusionState => ({ version: 1, revision: 0, pairs: [] })\n\n/** Browser commands identify stored authority; no command accepts replacement candidate text. */\nexport interface FusionCandidateAction {\n sessionId: string; taskId: string; taskRevision: number; candidateId: string; hash: string\n}\nexport interface FusionPreview {\n path: string; before: string; after: string; version: string\n candidateId: string; hash: string\n}\n"],"mappings":";;AACA,MAAa,gBAAgB;AAC7B,MAAa,qBAAqB;AAClC,MAAa,iBAAiB;AAC9B,MAAa,eAAe;CAAC;CAAmB;CAAiB;CAAiB;CAAe;CAAiB;AAAe;AA0FjI,MAAa,aAAa,UAA8B;CAAC;CAAe;CAAW;CAAY;AAAQ,CAAC,CAAC,SAAS,KAAK;AACvH,MAAa,0BAAuC;CAAE,SAAS;CAAG,UAAU;CAAG,OAAO,CAAC;AAAE"}
@@ -0,0 +1,38 @@
1
+ import { FusionActor, FusionCandidate, FusionTarget } from "./contracts.js";
2
+ //#region src/host-contracts.d.ts
3
+ /** Implemented by the Editor Host; the standalone plugin has no manuscript dependency. */
4
+ interface FusionWritingHost {
5
+ matches(header: {
6
+ agentPreset?: string;
7
+ }): boolean;
8
+ /** Exact native names, checked again by the execution guard, never just hidden from the model. */
9
+ readonly writerTools: readonly string[];
10
+ allowLeadTool(name: string, args: unknown): boolean;
11
+ capture(actor: FusionActor, input: unknown, signal: AbortSignal): Promise<FusionTarget>;
12
+ /** Holds the existing workspace write lock, including dirty-draft and version checks. */
13
+ transact<T>(actor: FusionActor, target: FusionTarget, candidate: FusionCandidate, signal: AbortSignal, run: (access: FusionApplicationAccess) => Promise<T>): Promise<T>;
14
+ }
15
+ interface FusionApplicationPreview {
16
+ path: string;
17
+ before: string;
18
+ after: string;
19
+ /** Empty only for an exclusive create whose destination does not exist. */
20
+ version: string;
21
+ }
22
+ interface FusionApplicationAccess {
23
+ /** Read without requiring the old baseline, for reconciling an already persisted intent. */
24
+ inspect(): Promise<{
25
+ text: string;
26
+ version: string;
27
+ } | undefined>;
28
+ /** Revalidates original target and basis and refuses any unsaved author draft. */
29
+ prepare(): Promise<FusionApplicationPreview>;
30
+ /** Must repeat relevant checks immediately before a version-checked write. */
31
+ commit(expectedVersion: string): Promise<{
32
+ path: string;
33
+ version: string;
34
+ }>;
35
+ }
36
+ //#endregion
37
+ export { FusionApplicationAccess, FusionApplicationPreview, FusionWritingHost };
38
+ //# sourceMappingURL=host-contracts.d.ts.map
@@ -0,0 +1 @@
1
+ export {};
package/lib/index.d.ts ADDED
@@ -0,0 +1,134 @@
1
+ import { FUSION_PLUGIN, FUSION_PURPOSE, FUSION_RPC_CHANNEL, FUSION_TOOLS, FusionActor, FusionBrief, FusionCandidate, FusionCandidateAction, FusionNative, FusionPair, FusionPreview, FusionProfile, FusionReview, FusionState, FusionStatus, FusionStore, FusionTarget, FusionTask, Json, ModelRoute, RpcResult, TaskState, emptyFusionState, isWorking } from "./contracts.js";
2
+ import { FusionApplicationAccess, FusionApplicationPreview, FusionWritingHost } from "./host-contracts.js";
3
+ import { Context } from "@deepseek-ai/cordis";
4
+ import { Agent } from "@deepseek-ai/dsh-agent";
5
+ import { AiServices } from "@klarkxy/dsh-ai-services/contracts";
6
+ //#region src/service.d.ts
7
+ /** Business records only. The native continuation manager owns Agents and all message scheduling. */
8
+ declare class FusionService {
9
+ private state;
10
+ private pending;
11
+ private enabled;
12
+ private generation;
13
+ private storageFailed;
14
+ private readonly controller;
15
+ private readonly dispatches;
16
+ private readonly applications;
17
+ private readonly notifications;
18
+ private readonly inFlight;
19
+ private readonly ready;
20
+ private readonly store;
21
+ private readonly inspectAdmission?;
22
+ private readonly native;
23
+ private readonly now;
24
+ private readonly id;
25
+ constructor(input: {
26
+ store: FusionStore;
27
+ native: FusionNative;
28
+ inspectAdmission?: (pair: FusionPair, signal: AbortSignal) => Promise<'present' | 'absent'>;
29
+ now?: () => number;
30
+ id?: () => string;
31
+ });
32
+ get active(): boolean;
33
+ initialized(): Promise<void>;
34
+ snapshot(): FusionState;
35
+ pairFor(sessionId: string): FusionPair | undefined;
36
+ role(sessionId: string): 'lead' | 'sidekick' | undefined;
37
+ private persist;
38
+ private change;
39
+ private owned;
40
+ private task;
41
+ private isCurrent;
42
+ private track;
43
+ private abortNotifications;
44
+ delegate(actor: FusionActor, input: {
45
+ profile: FusionProfile;
46
+ route: ModelRoute;
47
+ brief: FusionBrief;
48
+ target?: FusionTarget;
49
+ signal: AbortSignal;
50
+ }): Promise<FusionTask>;
51
+ private roleIsChild;
52
+ private dispatch;
53
+ private prompt;
54
+ report(actor: FusionActor, input: {
55
+ taskId: string;
56
+ taskRevision: number;
57
+ reportId: string;
58
+ kind: 'candidate' | 'decision';
59
+ text: string;
60
+ report?: string;
61
+ signal: AbortSignal;
62
+ }): Promise<FusionTask>;
63
+ read(actor: FusionActor, taskId: string, candidateId?: string): {
64
+ task: FusionTask;
65
+ candidate?: FusionCandidate;
66
+ };
67
+ review(actor: FusionActor, input: {
68
+ taskId: string;
69
+ taskRevision: number;
70
+ candidateId: string;
71
+ hash: string;
72
+ verdict: 'accept' | 'revise' | 'reject';
73
+ feedback: string;
74
+ signal: AbortSignal;
75
+ }): Promise<FusionTask>;
76
+ decide(actor: FusionActor, input: {
77
+ taskId: string;
78
+ taskRevision: number;
79
+ feedback: string;
80
+ signal: AbortSignal;
81
+ }): Promise<FusionTask>;
82
+ cancel(actor: FusionActor, taskId: string, taskRevision: number, stopLead?: boolean): Promise<void>;
83
+ executionInterrupted(actor: FusionActor, reason: string, expected?: {
84
+ taskId: string;
85
+ revision: number;
86
+ }): Promise<void>;
87
+ /** Explicit recovery only: saved content is re-notified, never dispatched to the Writer. */
88
+ recover(actor: FusionActor, taskId: string, taskRevision: number, outerSignal: AbortSignal): Promise<FusionTask>;
89
+ private candidateAction;
90
+ /** Also used by status. An uncertain filesystem mutation is inspected, never replayed. */
91
+ reconcile(actor: FusionActor, host: FusionWritingHost, signal: AbortSignal): Promise<void>;
92
+ preview(actor: FusionActor, input: FusionCandidateAction, host: FusionWritingHost, signal: AbortSignal): Promise<FusionPreview>;
93
+ applyCandidate(actor: FusionActor, input: FusionCandidateAction & {
94
+ expectedVersion: string;
95
+ }, host: FusionWritingHost, outerSignal: AbortSignal): Promise<FusionTask>;
96
+ dismiss(actor: FusionActor, input: FusionCandidateAction): Promise<FusionTask>;
97
+ /** Domain Host only: never expose an RPC that lets a browser claim a file was applied. */
98
+ adoption(leadSessionId: string, taskId: string, candidateId: string, state: 'applied' | 'dismissed' | 'conflict'): Promise<void>;
99
+ /** Stops owned work only. Invalidate synchronously, then await admissions and cleanup. */
100
+ dispose(): Promise<void>;
101
+ }
102
+ //#endregion
103
+ //#region src/runtime.d.ts
104
+ declare class FusionRuntime {
105
+ readonly service: FusionService;
106
+ private readonly ctx;
107
+ private readonly ai;
108
+ private readonly disposers;
109
+ private readonly installed;
110
+ private readonly pendingNoticeClaims;
111
+ private closing?;
112
+ constructor(ctx: Context, store: FusionStore, ai: AiServices);
113
+ private inspectAdmission;
114
+ private checkRoute;
115
+ actor(agent: Agent): FusionActor;
116
+ private writing;
117
+ private profile;
118
+ private childTools;
119
+ start(): Promise<void>;
120
+ private install;
121
+ private uninstall;
122
+ delegate(agent: Agent, input: unknown, signal: AbortSignal): Promise<FusionTask>;
123
+ private rpcActor;
124
+ rpc(endpoint: string, payload: unknown, signal: AbortSignal): Promise<unknown>;
125
+ dispose(): Promise<void>;
126
+ }
127
+ //#endregion
128
+ //#region src/index.d.ts
129
+ declare const name = "@klarkxy/dsh-fusion";
130
+ declare const inject: readonly ["agents", "subagents", "tools", "systemPrompt", "sessions", "sessionQuery", "sessionProjections", "storageDomain", "aiServices", "connection", "webServer"];
131
+ declare function apply(ctx: Context): Promise<void>;
132
+ //#endregion
133
+ export { type FUSION_PLUGIN, type FUSION_PURPOSE, type FUSION_RPC_CHANNEL, type FUSION_TOOLS, type FusionActor, type FusionApplicationAccess, type FusionApplicationPreview, type FusionBrief, type FusionCandidate, type FusionCandidateAction, type FusionNative, type FusionPair, type FusionPreview, type FusionProfile, type FusionReview, FusionRuntime, type FusionState, type FusionStatus, type FusionStore, type FusionTarget, type FusionTask, type FusionWritingHost, type Json, type ModelRoute, type RpcResult, type TaskState, apply, type emptyFusionState, inject, type isWorking, name };
134
+ //# sourceMappingURL=index.d.ts.map