@hy-sde-org/dsh-graph-stream

中文文档
0.2.1-rc.5发布于 2026/11/01MITTypeScriptES Module零依赖

Agent Graph stream layer: pure derivations (records, trace, readiness, handoff, schedule reconcile) and the process-local coordinator.

原始使用文档
文档目录11 节
  1. Summary
  2. Table of Contents
  3. Use this package
  4. Understand the implementation
  5. Deterministic identities and ordering
  6. Projections
  7. Reconciliation and the coordinator
  8. Executor seam
  9. Further Exploration
  10. Model Experience
  11. Known Limitations and Deferred Work

@hy-sde-org/dsh-graph-stream

English | 中文

Summary

dsh-graph-stream is the derivation layer of the Agent Graph. It layers on top of @hy-sde-org/dsh-graph-control (the durable decision store) and owns everything that can be recomputed from committed rows: work-status projection, record folding, trace/route derivation, readiness intents, input handoffs, and the single-flight reconciliation driver (AgentGraphCoordinator) that walks Maka's authored drive loop (provision → supervise → select → render → execute) against that store.

The split follows Maka's one hard rule: the store is the authority, the stream layer never writes anything except through the store's own commit/claim/provision methods. Every projection here is deterministic and pure — recomputing it never starts work; admission and execution are store-sealed (claim with preallocated turn/run identity at the schedule revision it observed).

Ids are deterministic sha256 cut to 32 hex chars (graph_intent_…, graph_operator_…, graph_edge_…, graph_route_…, graph_record_…, graph_claim_…), so replays are idempotent by construction. Identity comparison uses UTF-16 code-unit order (compareAgentGraphIdentity), not locale comparison.

This package contributes no tool, prompt, or plugin row — the executor adapter and the supervisor tools consume it.

Table of Contents

Use this package

import Storage, { storageBackendServiceKey } from '@deepseek-ai/dsh-storage'
import { GraphControlStore } from '@hy-sde-org/dsh-graph-control'
import { AgentGraphCoordinator } from '@hy-sde-org/dsh-graph-stream'

const backend = await ctx[storageBackendServiceKey('sqlite')]
const unit = await backend.kv.open(GraphControlStore.descriptor)
const store = await GraphControlStore.open(unit)

const coordinator = new AgentGraphCoordinator(graphId, {
  store,
  executor: { provisionOperator, runClaimedAgentGraphIntent, stopSession },
  recordSource,
  newId,
})

await coordinator.scheduleUpdate({ graphId, addWork: [work] }) // commits, then wakes the drive
const result = await coordinator.reconcileAndWait()             // runs one drive to idle

Understand the implementation

Deterministic identities and ordering

stableHash(value) = sha256: + hex of canonical JSON (sorted object keys, undefined/function/symbol → "[undefined]", bigint → numeric string, required/enum arrays sorted with localeCompare, Date → ISO). All ids use the first 32 hex chars. compareAgentGraphIdentity is UTF-16 code-unit order — stable across processes, unlike localeCompare.

Projections

  • Schedule projection (projectAgentGraphSchedule): folds the append-only update log into the model-visible work view; validates contiguity (revisions from 1), no updates after a finish, no repeated work ids, wrong graph ids rejected. stopped wins over superseded.
  • Record fold (readCommittedAgentGraphProjection): derives reference-only records from committed events per (operator, session); partial events skipped; at most one terminal record per activation; deterministic order.
  • Trace (validateAgentGraphTraceTopology, buildAgentGraphTraceSnapshot): validates the DAG (duplicate ids/endpoints, self-loops, unknown operators, cycles via Kahn) and derives one route per (record × outgoing edge).
  • Readiness (buildAgentGraphReadinessSnapshot): map policy — one intent per route received through a declared incoming edge, sealed against exactly the triggering records (policyFingerprint, readinessContextFingerprint, graph_intent_… via stable hashes).
  • Handoff (hydrateAgentGraphInputHandoffs, renderAgentGraphScheduledWorkPrompt): resolves bounded conclusion text (16 KiB/record, 48 KiB total, … ellipsis, binary search over code points) and renders the operator prompt: instruction + GRAPH_OPERATOR_HANDOFF_PROTOCOL + <agent_graph_input_handoffs> with < escaped as \u003c. Records stay reference-only; text is resolved only at render time.

Reconciliation and the coordinator

reconcileAgentGraphSchedule walks Maka's phases: A provision operators → B derive supervisor intents → C select (existing claims always; new capped by maxNewActivations, excess → activation_limit) → D render (all-or-fail) → E execute (claim at revision → run with admitExecution = begin-execution at revision). Statuses: reconciled | waiting | limit_reached | failed | cancelled | stale. applyScheduleStops replaces (status: 'superseded'), cancels claims, and stops sessions in batches.

AgentGraphCoordinator is the process-local single-flight driver: scheduleUpdate commits a row then wakes the drive; reconcileAndWait joins exactly one drive; recover resumes graphs with a non-empty schedule after restart; stop/wake/isClosed surface the same lifecycle. A drive re-runs while work or stopped targets remain, and observes existing claims as already-dispatched (executor dedupes by claim id).

Executor seam

export interface AgentGraphExecutor {
  provisionOperator(request: AgentGraphOperatorProvisionRequest): Promise<AgentGraphOperatorProvisionResult | undefined>
  runClaimedAgentGraphIntent(input: AgentGraphRunClaimedIntentInput): Promise<void>
  stopSession(sessionId: string, opts?: { reason?: string }): Promise<void>
}

The coordinator never calls a provider directly — the executor package supplies the subagent/worktree-backed implementation.

Further Exploration

  • @hy-sde-org/dsh-graph-control: the durable rows this layer folds.
  • src/reconcile.ts / src/coordinator.ts: the drive loop and status derivation.
  • src/hash.ts / src/identity.ts: the canonicalization and ordering primitives every id and fingerprint depends on.
  • tests/graph-stream.spec.ts / tests/reconcile.spec.ts: projection, validation, handoff, and end-to-end drive scenarios against a real sqlite-backed store.

Model Experience

The package is pure TypeScript with narrow, single-responsibility modules and no ambient state. Types are explicit; results are plain data (no class instances crossing module boundaries except the coordinator). Errors carry reason codes for validation failures and the store's conflict errors propagate unchanged.

Known Limitations and Deferred Work

  • Readiness policy kinds: map only — all_settled and supervisor-readiness kinds are deferred to the supervisor tool layer.
  • No client projection/checkpointing (onCheckpoint) yet; no tool-view pagination; residency is a no-op.
  • Map-policy intents are derived but not auto-dispatched by reconcile — they surface for the supervisor tools.
  • Record shape is copy-with-provenance (slim), a deliberate deviation from Maka's 18-facet full record; the stream layer never mutates stored records.
  • The coordinator is process-local: another process holding the same graph store will not wake this driver automatically (wake delivery is dsh-graph-wakes).

版本与发布记录

@hy-sde-org/dsh-graph-stream 共发布 9 个版本,首次发布于 2026/09/10;过去 12 个月发布了 9 个版本。

版本发布日期距今
0.2.1-rc.5latest2026/11/012 天前
0.2.1-rc.32026/10/259 天前
0.2.1-alpha.42026/10/1618 天前
0.2.1-alpha.22026/10/1321 天前
0.2.0-rc.22026/10/031 个月前
0.1.7-rc.22026/09/291 个月前

关于 @hy-sde-org/dsh-graph-stream 的常见问题

@hy-sde-org/dsh-graph-stream 是什么?

代理图流层:纯派生(记录、跟踪、准备、移交、调度协调)和流程本地协调器。

如何安装 @hy-sde-org/dsh-graph-stream?

在项目目录运行 npm install @hy-sde-org/dsh-graph-stream,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@hy-sde-org/dsh-graph-control(^0.2.1-rc.5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@hy-sde-org/dsh-graph-stream 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@hy-sde-org/dsh-graph-stream 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@hy-sde-org/dsh-graph-stream 可以商用吗?

@hy-sde-org/dsh-graph-stream 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@hy-sde-org/dsh-graph-stream 还在维护吗?

最新版本 0.2.1-rc.5 发布于 2026/11/01(2 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/09/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。