@klarkxy/dsh-delegation 0.0.0-stage → 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 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/storage.ts","../src/service.ts","../src/prompts.ts","../src/policy.ts","../src/index.ts"],"sourcesContent":["import { defineDomain, domainTable } from '@deepseek-ai/dsh-storage-domain'\nimport { z } from 'zod'\nimport { defaultSettings, type DelegationSettings } from './contracts.ts'\n\nexport const SETTINGS_KEY = 'global'\n\nexport const settingsSchema = z.object({\n revision: z.number().int().nonnegative(),\n defaultEnabled: z.boolean(),\n}).strict()\n\nexport const sessionSchema = z.object({\n enabled: z.boolean(),\n revision: z.number().int().min(1),\n}).strict()\n\nexport interface SessionDelegation {\n readonly enabled: boolean\n readonly revision: number\n}\n\nexport const settingsUpdateSchema = z.object({\n defaultEnabled: z.boolean(),\n expectedRevision: z.number().int().nonnegative(),\n}).strict()\n\nexport const sessionStatusSchema = z.object({\n sessionId: z.string().min(1),\n}).strict()\n\nexport const sessionUpdateSchema = z.object({\n sessionId: z.string().min(1),\n enabled: z.boolean(),\n expectedRevision: z.number().int().nonnegative(),\n}).strict()\n\nexport const delegationDomain = defineDomain({\n name: 'dsh_delegation',\n version: 1,\n tables: {\n settings: domainTable<string, DelegationSettings>(settingsSchema),\n sessions: domainTable<string, SessionDelegation>(sessionSchema),\n },\n})\n\n/** A missing or unreadable settings row reads as the shipped defaults. */\nexport function parseSettings(value: unknown): DelegationSettings {\n const parsed = settingsSchema.safeParse(value)\n if (!parsed.success) return defaultSettings()\n return { revision: parsed.data.revision, defaultEnabled: parsed.data.defaultEnabled }\n}\n\n/** A missing or unreadable session row reads as \"no record\": off, revision 0. */\nexport function parseSession(value: unknown): SessionDelegation | undefined {\n const parsed = sessionSchema.safeParse(value)\n if (!parsed.success) return undefined\n return { enabled: parsed.data.enabled, revision: parsed.data.revision }\n}\n","import { isSubagentSession } from '@klarkxy/dsh-plugin-kit/contracts'\nimport {\n DELEGATION_TOOLS, type DelegationSessionStatus, type DelegationSettings,\n} from './contracts.ts'\nimport { parseSession, parseSettings, SETTINGS_KEY, type SessionDelegation } from './storage.ts'\nimport type { DelegationSessionLike } from './policy.ts'\n\nexport class DelegationError extends Error {\n readonly code: string\n constructor(code: string, message: string) {\n super(message)\n this.name = 'DelegationError'\n this.code = code\n }\n}\n\nexport interface DelegationTableLike<V> {\n get(key: string): V | undefined\n put(key: string, value: V): Promise<void>\n}\n\nexport interface DelegationAgentLike {\n readonly id: string\n readonly session?: DelegationSessionLike\n /** Claims the host's idle phase; waking input waits until this task settles. */\n runMaintenance?<T>(task: (signal: AbortSignal) => Promise<T>): Promise<T>\n}\n\n/** Cold-session read handle from the host's session query engine. */\nexport interface DelegationObservationLike {\n readonly header?: unknown\n [Symbol.dispose](): void\n}\n\nexport interface DelegationServiceDeps {\n /** Parsed global settings row (one key: 'global'). */\n readonly settings: DelegationTableLike<DelegationSettings>\n /** Parsed per-session rows (key: session id). */\n readonly records: DelegationTableLike<SessionDelegation>\n readonly sessionStore?: { get(id: string): DelegationSessionLike | undefined }\n readonly agents?: { get(id: string): DelegationAgentLike | undefined }\n readonly tools?: { get(name: string, scope?: unknown): unknown }\n /** Durable turn-boundary projection, including inherited and resumed turns. */\n readonly hasStarted?: (session: DelegationSessionLike) => boolean\n /** Reads persisted headers for sessions that are not live (cold sessions). */\n readonly sessionQuery?: {\n observeSession(id: string, options: { signal?: AbortSignal; projectionMode?: string }): Promise<DelegationObservationLike>\n }\n}\n\n/**\n * In-process CAS over the two domain tables. Table `get` is synchronous, so a\n * per-key promise chain serializes check-and-write: two concurrent updates can\n * never both pass the revision check, and a caller only hears success after\n * `put` resolves.\n */\nexport class DelegationService {\n private readonly deps: DelegationServiceDeps\n private readonly chains = new Map<string, Promise<void>>()\n\n constructor(deps: DelegationServiceDeps) {\n this.deps = deps\n }\n\n private enqueue<T>(key: string, work: () => Promise<T>): Promise<T> {\n const pending = this.chains.get(key) ?? Promise.resolve()\n const result = pending.then(work, work)\n this.chains.set(key, result.then(() => {}, () => {}))\n return result\n }\n\n getSettings(): DelegationSettings {\n return parseSettings(this.deps.settings.get(SETTINGS_KEY))\n }\n\n updateSettings(defaultEnabled: boolean, expectedRevision: number): Promise<DelegationSettings> {\n return this.enqueue('settings', async () => {\n const current = this.getSettings()\n if (current.revision !== expectedRevision) {\n throw new DelegationError('stale', 'dsh-delegation: settings changed; refresh and retry')\n }\n const next: DelegationSettings = { revision: current.revision + 1, defaultEnabled }\n await this.deps.settings.put(SETTINGS_KEY, next)\n return next\n })\n }\n\n /** The parsed session row; undefined means no record (off, revision 0). */\n record(sessionId: string): SessionDelegation | undefined {\n return parseSession(this.deps.records.get(sessionId))\n }\n\n private locked(session: DelegationSessionLike | undefined, agent: DelegationAgentLike | undefined): boolean {\n // A cold or incompletely composed session cannot safely race prompt admission.\n return !session || !agent?.runMaintenance || this.deps.hasStarted?.(session) !== false\n }\n\n /**\n * The session header: live sessions read the store snapshot; a cold session\n * is resolved through the query engine and the observation is always\n * disposed before returning. Unknown sessions throw `no-session`.\n */\n private async requireHeader(sessionId: string, signal?: AbortSignal): Promise<unknown> {\n const live = this.deps.sessionStore?.get(sessionId)\n if (live) return live.header\n const query = this.deps.sessionQuery\n if (!query) throw new DelegationError('no-session', `dsh-delegation: no live session ${sessionId}`)\n let observation: DelegationObservationLike\n try {\n observation = await query.observeSession(sessionId, { signal, projectionMode: 'none' })\n } catch {\n throw new DelegationError('no-session', `dsh-delegation: no session ${sessionId}`)\n }\n try {\n return observation.header\n } finally {\n observation[Symbol.dispose]()\n }\n }\n\n async sessionStatus(sessionId: string, signal?: AbortSignal): Promise<DelegationSessionStatus> {\n const session = this.deps.sessionStore?.get(sessionId)\n const header = session ? session.header : await this.requireHeader(sessionId, signal)\n const agent = session ? this.deps.agents?.get(sessionId) : undefined\n const capable = agent === undefined\n ? null\n : DELEGATION_TOOLS.some(name => this.deps.tools?.get(name, agent) !== undefined)\n const record = this.record(sessionId)\n return {\n sessionId,\n role: isSubagentSession({ header }) ? 'executor' : 'coordinator',\n enabled: record?.enabled ?? false,\n revision: record?.revision ?? 0,\n locked: this.locked(session, agent),\n capable,\n }\n }\n\n async updateSession(sessionId: string, enabled: boolean, expectedRevision: number, signal?: AbortSignal): Promise<DelegationSessionStatus> {\n const session = this.deps.sessionStore?.get(sessionId)\n const header = session ? session.header : await this.requireHeader(sessionId, signal)\n if (isSubagentSession({ header })) {\n throw new DelegationError('not-top-level', 'dsh-delegation: only a top-level session carries the switch')\n }\n await this.enqueue(`session:${sessionId}`, async () => {\n const live = this.deps.sessionStore?.get(sessionId)\n const agent = this.deps.agents?.get(sessionId)\n const requireEditable = () => {\n if (this.locked(live, agent)) {\n throw new DelegationError('session-locked', 'dsh-delegation: choose delegation before the session starts')\n }\n }\n requireEditable()\n let entered = false\n try {\n // The host holds first-turn input while storage commits. Without this\n // guard, a slow save could change the policy after the first assembly.\n await agent!.runMaintenance!(async maintenanceSignal => {\n entered = true\n requireEditable()\n maintenanceSignal.throwIfAborted()\n signal?.throwIfAborted()\n const current = this.record(sessionId)\n const revision = current?.revision ?? 0\n if (revision !== expectedRevision) {\n throw new DelegationError('stale', 'dsh-delegation: session state changed; refresh and retry')\n }\n await this.deps.records.put(sessionId, { enabled, revision: revision + 1 })\n })\n } catch (error) {\n if (!entered) throw new DelegationError('session-busy', 'dsh-delegation: session is busy; refresh and retry')\n throw error\n }\n })\n return this.sessionStatus(sessionId, signal)\n }\n\n /**\n * `agent/created` seeding. Only a fresh ('startup') non-subagent session gets\n * an initial row: a human fork inherits its parent's flag, every other new\n * top-level session takes the current `defaultEnabled`. Resumed, cleared and\n * compacted sessions keep whatever they already have — and stay off when\n * they predate the plugin.\n */\n async seedSession(agent: DelegationAgentLike, source: string): Promise<void> {\n if (source !== 'startup') return\n const session = agent.session\n if (!session || isSubagentSession(session)) return\n const id = session.id\n await this.enqueue(`session:${id}`, async () => {\n if (this.record(id)) return\n const parentId = typeof session.header?.parentSession === 'string' ? session.header.parentSession : undefined\n const inherited = parentId ? this.record(parentId) : undefined\n const enabled = inherited?.enabled ?? this.getSettings().defaultEnabled\n await this.deps.records.put(id, { enabled, revision: 1 })\n })\n }\n}\n","/**\n * System prompt text for delegation mode. Kept literal (the section registers\n * with `interpolate: false`), so no `{{variable}}` syntax may appear here.\n */\n\n/** Coordinator policy for a top-level session with delegation on. */\nexport function coordinatorPrompt(tools: readonly string[]): string {\n const names = tools.map(name => `\\`${name}\\``).join(' / ')\n return `## Delegation mode\n\nDelegation mode is on. You are the coordinator; ${names} are how you get substantive work done. You own the requirements, division of work, integration decisions, acceptance, and the final response.\n\nFor a task with multiple components or substantive implementation steps, dispatch a scoped subagent task BEFORE implementing it yourself. A todo list or a promise to delegate is not a delegation. Do not first design every function, read the entire project, or start writing the deliverable. If the split is unclear, delegate a focused discovery task and use its report to choose the next assignments.\n\n- Make a short plan that is sufficient to assign work, then call the delegation tool. Prefer a fresh subagent for a self-contained brief. A fork inherits completed turns, not the current in-flight user request: always include the current task and constraints explicitly.\n- Each brief must contain the goal, working directory, allowed files, shared interface/data contracts, acceptance criteria, and what to report. Give each file one active owner. Start independent assignments together; resolve shared contracts before dependent work starts.\n- Subagents read, implement, run commands, test, and fix their assigned work. You may do a brief targeted read or an acceptance check to make a coordination decision; do not use that exception to take over an implementation task.\n- Track the returned subagent ids. Use native completion notifications and send_message for questions, corrections, or follow-up work. Do not repeatedly poll or sleep. Do not claim completion while required work is still running.\n- Inspect the delivered files and verification evidence. Send concrete failures back to the responsible subagent; collect and check the correction. Finish with the usable result, the checks actually performed, and any remaining limitation.\n\nA simple question, short rewrite, or genuinely small self-contained task may be completed directly. This exception does not cover building an application or completing a multi-part feature. Keep user-facing updates in the user's language.`\n}\n\n/** Executor policy for a subagent whose top-level session has delegation on. */\nexport const EXECUTOR_PROMPT = `## Delegated task\n\nYou are a subagent carrying out a task delegated by a coordinating agent. Coordinator instructions that appear earlier in this conversation, for example ones inherited through a fork, do not apply to you.\n\n- Do the work yourself: read, search, edit, run commands, and verify as the task requires. Make concrete progress in the assigned files; do not stop at a design or a plan. Do not pass the task on to further subagents unless the brief asks for it or clearly independent parts justify running them in parallel.\n- Stay within the brief. If it is ambiguous, make a reasonable choice and state it; if you are blocked, stop and report what is missing.\n- Respect file ownership and agreed interfaces. Ask the coordinator before changing another worker's files or a shared contract.\n- Verify your result before reporting.\n- End with a concise report: the result, the files or locations changed, the evidence (commands run and their outcome), and unresolved issues. Do not paste full logs.`\n\n/** Stable operational reminder; the host persists it only when context changes. */\nexport function coordinatorReminder(tools: readonly string[]): string {\n return `Delegation mode: coordinator. For multi-part work, your next implementation action must be a scoped assignment through ${tools.map(name => `\\`${name}\\``).join(' / ')}, not doing that implementation yourself. Plan only far enough to dispatch; give workers file ownership and interface contracts, then collect and verify their results. Simple self-contained tasks may be answered directly. This mode remains fixed for this session.`\n}\n\nexport const EXECUTOR_REMINDER = 'Delegation mode: executor. Carry out the assigned work in your allowed files and verify it. Earlier coordinator reminders inherited from a parent do not assign you the coordinator role. Report concrete results and evidence to your parent.'\n","import { isSubagentSession } from '@klarkxy/dsh-plugin-kit/contracts'\nimport { DELEGATION_TOOLS } from './contracts.ts'\nimport { coordinatorPrompt, coordinatorReminder, EXECUTOR_PROMPT, EXECUTOR_REMINDER } from './prompts.ts'\n\nexport interface DelegationSessionLike {\n readonly id: string\n readonly header?: { readonly parentSession?: unknown }\n}\n\n/** The per-assembly lookups the policy needs; callers inject the live stores. */\nexport interface DelegationLookups {\n /** Parsed per-session record; undefined means no record. */\n record(sessionId: string): { readonly enabled: boolean } | undefined\n session(sessionId: string): DelegationSessionLike | undefined\n /** Whether a tool name resolves in this assembly's scope. */\n toolVisible(name: string, scope: unknown): boolean\n}\n\nexport interface DelegationAssembleContext {\n readonly agent?: { readonly session: DelegationSessionLike }\n readonly scope?: unknown\n}\n\n/** Ancestor walk bound: subagent chains deeper than this bail out as off. */\nconst MAX_PARENT_HOPS = 16\n\n/** First non-subagent ancestor reachable through `header.parentSession`. */\nfunction topLevelSession(\n session: DelegationSessionLike,\n sessions: DelegationLookups['session'],\n): DelegationSessionLike | undefined {\n const seen = new Set<string>([session.id])\n let current = session\n for (let hop = 0; hop < MAX_PARENT_HOPS && isSubagentSession(current); hop++) {\n const parentId = typeof current.header?.parentSession === 'string' ? current.header.parentSession : undefined\n if (!parentId || seen.has(parentId)) return undefined\n seen.add(parentId)\n const parent = sessions(parentId)\n if (!parent) return undefined\n current = parent\n }\n return isSubagentSession(current) ? undefined : current\n}\n\ntype Policy = { role: 'executor' } | { role: 'coordinator'; tools: readonly string[] }\n\n/** Both prompt surfaces must use the same role and capability decision. */\nfunction delegationPolicy(context: DelegationAssembleContext, lookups: DelegationLookups): Policy | undefined {\n const session = context.agent?.session\n if (!session) return undefined\n if (isSubagentSession(session)) {\n const root = topLevelSession(session, lookups.session)\n return root && lookups.record(root.id)?.enabled ? { role: 'executor' } : undefined\n }\n if (!lookups.record(session.id)?.enabled) return undefined\n const visible = DELEGATION_TOOLS.filter(name => lookups.toolVisible(name, context.scope))\n return visible.length ? { role: 'coordinator', tools: visible } : undefined\n}\n\n/** Static system guidance. No per-step counters or progress belong in this text. */\nexport function delegationSectionText(context: DelegationAssembleContext, lookups: DelegationLookups): string {\n const policy = delegationPolicy(context, lookups)\n if (!policy) return ''\n return policy.role === 'executor' ? EXECUTOR_PROMPT : coordinatorPrompt(policy.tools)\n}\n\n/** Stable user-role context snapshot, refreshed by the host after compaction. */\nexport function delegationReminderText(context: DelegationAssembleContext, lookups: DelegationLookups): string {\n const policy = delegationPolicy(context, lookups)\n if (!policy) return ''\n return policy.role === 'executor' ? EXECUTOR_REMINDER : coordinatorReminder(policy.tools)\n}\n","import type { Context } from '@deepseek-ai/cordis'\nimport type {} from '@deepseek-ai/dsh-agent'\nimport type { Session } from '@deepseek-ai/dsh-session'\nimport type {} from '@deepseek-ai/dsh-session-query'\nimport type {} from '@deepseek-ai/dsh-storage-domain'\nimport type {} from '@deepseek-ai/dsh-system-prompt'\nimport type {} from '@deepseek-ai/dsh-tools'\nimport { registerHostRpc, type HostRpcContext } from '@klarkxy/dsh-plugin-kit/host-rpc'\nimport {\n PLUGIN_NAME, RPC_CHANNEL,\n type DelegationSessionStatus, type DelegationSettings, type RpcResult,\n} from './contracts.ts'\nimport { delegationDomain,\n sessionStatusSchema, sessionUpdateSchema, settingsUpdateSchema } from './storage.ts'\nimport { DelegationError, DelegationService, type DelegationAgentLike, type DelegationServiceDeps } from './service.ts'\nimport { delegationSectionText, delegationReminderText, type DelegationLookups } from './policy.ts'\n\nexport const name = PLUGIN_NAME\nexport const inject = ['systemPrompt', 'storageDomain', 'sessions', 'agents', 'tools', 'sessionQuery', 'sessionProjections', 'connection', 'webServer'] as const\nexport { DelegationService, DelegationError } from './service.ts'\nexport { delegationSectionText } from './policy.ts'\nexport { coordinatorPrompt, EXECUTOR_PROMPT } from './prompts.ts'\n\ndeclare module '@deepseek-ai/cordis' {\n interface Context { delegation: DelegationService }\n}\n\nfunction fail(error: unknown): RpcResult<never> {\n if (error instanceof DelegationError) {\n return { ok: false, error: { code: error.code, message: error.message } }\n }\n const message = error instanceof Error ? error.message : String(error)\n return { ok: false, error: { code: 'internal', message } }\n}\n\nexport async function handleRpc(\n service: DelegationService,\n endpoint: string,\n payload: unknown,\n signal: AbortSignal,\n): Promise<RpcResult> {\n try {\n switch (endpoint) {\n case 'settings': {\n const value: DelegationSettings = service.getSettings()\n return { ok: true, value }\n }\n case 'settings.update': {\n const parsed = settingsUpdateSchema.safeParse(payload)\n if (!parsed.success) return { ok: false, error: { code: 'bad-request', message: 'settings update is invalid' } }\n const value: DelegationSettings = await service.updateSettings(parsed.data.defaultEnabled, parsed.data.expectedRevision)\n return { ok: true, value }\n }\n case 'session.status': {\n const parsed = sessionStatusSchema.safeParse(payload)\n if (!parsed.success) return { ok: false, error: { code: 'bad-request', message: 'sessionId is required' } }\n const value: DelegationSessionStatus = await service.sessionStatus(parsed.data.sessionId, signal)\n return { ok: true, value }\n }\n case 'session.update': {\n const parsed = sessionUpdateSchema.safeParse(payload)\n if (!parsed.success) return { ok: false, error: { code: 'bad-request', message: 'session update is invalid' } }\n const value: DelegationSessionStatus = await service.updateSession(\n parsed.data.sessionId, parsed.data.enabled, parsed.data.expectedRevision, signal)\n return { ok: true, value }\n }\n default:\n return { ok: false, error: { code: 'not-found', message: `unknown endpoint: ${endpoint}` } }\n }\n } catch (error) {\n return fail(error)\n }\n}\n\nexport async function apply(ctx: Context): Promise<void> {\n const host = ctx as Context & HostRpcContext\n const domain = await ctx.storageDomain.open(delegationDomain)\n const service = new DelegationService({\n settings: domain.table('settings'),\n records: domain.table('sessions'),\n sessionStore: ctx.sessions as unknown as DelegationServiceDeps['sessionStore'],\n agents: ctx.agents as unknown as DelegationServiceDeps['agents'],\n tools: ctx.tools as unknown as DelegationServiceDeps['tools'],\n sessionQuery: ctx.sessionQuery as unknown as DelegationServiceDeps['sessionQuery'],\n hasStarted: session => {\n const boundary = ctx.sessionProjections.stateOf(session as Session, 'turnBoundary')\n return boundary === undefined || boundary.openTurnStartSeq !== null || boundary.lastTurn > 0\n },\n })\n ctx.provide('delegation', service)\n ctx.effect(() => () => domain.close(), 'delegation.lifecycle')\n // Seeding listens on agent/created: serial and awaited before the agent's\n // queued work, so the row exists before the first prompt assembly. A throw\n // here would fail agent creation, so the listener never propagates one.\n ctx.effect(() => ctx.on('agent/created', async ({ agent, source }: { agent: DelegationAgentLike; source: string }) => {\n try {\n await service.seedSession(agent, source)\n } catch (error) {\n ctx.logger.warn('dsh-delegation: could not seed session state: %s', error instanceof Error ? error.message : String(error))\n }\n }), 'delegation.seed')\n // Read-only advisory text evaluated at every assembly; the choice is locked\n // before the first model step and stays stable across later turns. Covers\n // subagent sessions deliberately: the executor half IS their prompt.\n const sectionSessions = ctx.sessions as unknown as DelegationServiceDeps['sessionStore']\n const sectionTools = ctx.tools as unknown as DelegationServiceDeps['tools']\n const lookups: DelegationLookups = {\n record: sessionId => service.record(sessionId),\n session: id => sectionSessions?.get(id),\n toolVisible: (tool, scope) => sectionTools?.get(tool, scope) !== undefined,\n }\n ctx.effect(() => ctx.systemPrompt.section({\n name: 'delegation:policy',\n order: ctx.systemPrompt.getSectionOrder('TOOL_SUBAGENT') + 2,\n interpolate: false,\n text: context => delegationSectionText(context, lookups),\n }), 'delegation.section')\n // Native runtime context is durable and appended only when its snapshot\n // changes (or after compaction), not a new reminder injected at every step.\n // Include children deliberately: a fork must replace inherited coordinator\n // context with its own executor role. Neither contribution writes by itself.\n ctx.effect(() => ctx.systemPrompt.context({\n name: 'delegation:role',\n order: ctx.systemPrompt.getContextOrder('SUBAGENT_DELEGATION') + 2,\n required: true,\n interpolate: false,\n text: context => delegationReminderText(context, lookups),\n }), 'delegation.context')\n ctx.effect(() => registerHostRpc(host, RPC_CHANNEL,\n (endpoint, payload, signal) => handleRpc(service, endpoint, payload, signal)), 'delegation.rpc')\n}\n"],"mappings":";;;;;;AAIA,MAAa,eAAe;AAE5B,MAAa,iBAAiB,EAAE,OAAO;CACrC,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY;CACvC,gBAAgB,EAAE,QAAQ;AAC5B,CAAC,CAAC,CAAC,OAAO;AAEV,MAAa,gBAAgB,EAAE,OAAO;CACpC,SAAS,EAAE,QAAQ;CACnB,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC;AAClC,CAAC,CAAC,CAAC,OAAO;AAOV,MAAa,uBAAuB,EAAE,OAAO;CAC3C,gBAAgB,EAAE,QAAQ;CAC1B,kBAAkB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY;AACjD,CAAC,CAAC,CAAC,OAAO;AAEV,MAAa,sBAAsB,EAAE,OAAO,EAC1C,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,EAC7B,CAAC,CAAC,CAAC,OAAO;AAEV,MAAa,sBAAsB,EAAE,OA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CACxB,IAAI,aAAa,gBAAgB,MAAM,cACpC,UAAU,SAAS,WAAW,UAAU,SAAS,UAAU,SAAS,MAAM,CAAC,GAAG,gBAAgB;AACnG"}
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "Delegation Mode",
4
+ "description": "Per-session switch: the main agent plans, delegates, and reviews while subagents do the work."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "委派模式",
4
+ "description": "按会话开启:主代理负责拆解、委派和验收,具体工作交给子代理。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,153 @@
1
1
  {
2
2
  "name": "@klarkxy/dsh-delegation",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Delegation Mode: a per-session switch where the main agent plans, delegates, and reviews while subagents carry out the work.",
5
+ "icon": "./icon.svg",
6
+ "license": "SEE LICENSE IN LICENSE",
7
+ "type": "module",
8
+ "engines": {
9
+ "node": ">=22",
10
+ "dsh": ">=0.2.1-rc.1"
11
+ },
12
+ "main": "./lib/index.js",
13
+ "types": "./lib/index.d.ts",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./lib/index.d.ts",
17
+ "import": "./lib/index.js",
18
+ "default": "./lib/index.js"
19
+ },
20
+ "./contracts": {
21
+ "types": "./lib/contracts.d.ts",
22
+ "import": "./lib/contracts.js",
23
+ "default": "./lib/contracts.js"
24
+ },
25
+ "./client": {
26
+ "default": "./lib/client.js"
27
+ },
28
+ "./package.json": "./package.json",
29
+ "./locale/*.json": "./locale/*.json"
30
+ },
31
+ "files": [
32
+ "icon.svg",
33
+ "locale/*.json",
34
+ "lib",
35
+ "cordis.patch.yml",
36
+ "README.md",
37
+ "docs/README.zh-CN.md",
38
+ "LICENSE"
39
+ ],
40
+ "dsh": {
41
+ "bundle": {
42
+ "patch": "./cordis.patch.yml"
43
+ },
44
+ "client": {
45
+ "platform": "web",
46
+ "inject": [
47
+ "@deepseek-ai/dsh-client-connection",
48
+ "@deepseek-ai/dsh-api-remotes",
49
+ "@deepseek-ai/dsh-api-session-controller",
50
+ "@deepseek-ai/dsh-client-locale",
51
+ "@deepseek-ai/dsh-client-ui-slots",
52
+ "@deepseek-ai/dsh-client-ui-session",
53
+ "@deepseek-ai/dsh-client-ui-primitives"
54
+ ]
55
+ }
56
+ },
57
+ "dshEditor": {
58
+ "role": "feature",
59
+ "visibility": "public",
60
+ "wrapClient": true,
61
+ "entries": [
62
+ {
63
+ "id": "delegation",
64
+ "title": "委派模式",
65
+ "description": "按会话开启:主代理负责拆解、委派和验收,具体工作交给子代理",
66
+ "feature": "delegation",
67
+ "service": "delegation"
68
+ }
69
+ ]
70
+ },
71
+ "scripts": {
72
+ "build": "tsdown && node ../../scripts/editor-plugins/wrap-client.mjs @klarkxy/dsh-delegation",
73
+ "typecheck": "tsc --noEmit -p tsconfig.json",
74
+ "test": "vitest run --root ../.. --config vitest.editor-plugins.config.ts --maxWorkers=2 plugins/dsh-delegation/src"
75
+ },
76
+ "dependencies": {
77
+ "@klarkxy/dsh-plugin-kit": "0.5.0",
78
+ "zod": "^4.1.5"
79
+ },
80
+ "peerDependencies": {
81
+ "@deepseek-ai/cordis": ">=4.0.4",
82
+ "@deepseek-ai/dsh-agent": ">=0.2.1-rc.1",
83
+ "@deepseek-ai/dsh-session": ">=0.2.1-rc.1",
84
+ "@deepseek-ai/dsh-session-query": ">=0.2.0-rc.2",
85
+ "@deepseek-ai/dsh-storage-domain": ">=0.2.0-rc.2",
86
+ "@deepseek-ai/dsh-system-prompt": ">=0.2.0-rc.2",
87
+ "@deepseek-ai/dsh-tools": ">=0.2.0-rc.2"
88
+ },
89
+ "peerDependenciesMeta": {
90
+ "@deepseek-ai/cordis": {
91
+ "optional": true
92
+ },
93
+ "@deepseek-ai/dsh-agent": {
94
+ "optional": true
95
+ },
96
+ "@deepseek-ai/dsh-session": {
97
+ "optional": true
98
+ },
99
+ "@deepseek-ai/dsh-session-query": {
100
+ "optional": true
101
+ },
102
+ "@deepseek-ai/dsh-storage-domain": {
103
+ "optional": true
104
+ },
105
+ "@deepseek-ai/dsh-system-prompt": {
106
+ "optional": true
107
+ },
108
+ "@deepseek-ai/dsh-tools": {
109
+ "optional": true
110
+ }
111
+ },
112
+ "devDependencies": {
113
+ "@deepseek-ai/cordis": "4.0.5",
114
+ "@deepseek-ai/dsh-agent": "0.2.1-rc.1",
115
+ "@deepseek-ai/dsh-session": "0.2.1-rc.1",
116
+ "@deepseek-ai/dsh-session-query": "0.2.1-rc.1",
117
+ "@deepseek-ai/dsh-storage-domain": "0.2.1-rc.1",
118
+ "@deepseek-ai/dsh-system-prompt": "0.2.1-rc.1",
119
+ "@deepseek-ai/dsh-tools": "0.2.1-rc.1",
120
+ "@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.1",
121
+ "zod": "4.4.3",
122
+ "react": "^18.2.0",
123
+ "react-dom": "^18.2.0",
124
+ "@types/react": "18.3.31",
125
+ "@types/react-dom": "^18.3.0",
126
+ "jsdom": "29.1.1",
127
+ "@types/jsdom": "28.0.3"
128
+ },
129
+ "keywords": [
130
+ "dsh",
131
+ "dsh-plugin",
132
+ "dsh-plugins",
133
+ "deepseek-harness",
134
+ "delegation",
135
+ "subagent"
136
+ ],
137
+ "repository": {
138
+ "type": "git",
139
+ "url": "git+https://github.com/klarkxy/dsh-plugins.git",
140
+ "directory": "plugins/dsh-delegation"
141
+ },
142
+ "homepage": "https://klarkxy.github.io/dsh-plugins/plugins/delegation/",
143
+ "bugs": {
144
+ "url": "https://github.com/klarkxy/dsh-plugins/issues"
145
+ },
146
+ "publishConfig": {
147
+ "access": "public",
148
+ "registry": "https://registry.npmjs.org/"
149
+ },
150
+ "dshRelease": {
151
+ "contentHash": "b6e25d17ff56458138b414cf2c3946898cdfe4cd9fb70e677956ee5db8f183d9"
152
+ }
153
+ }