@jini-ai/daemon 0.2.1 → 0.3.1

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 (77) hide show
  1. package/README.md +92 -0
  2. package/dist/agent-executor.d.ts +864 -42
  3. package/dist/agent-executor.d.ts.map +1 -1
  4. package/dist/agent-executor.js +1672 -351
  5. package/dist/agent-executor.js.map +1 -1
  6. package/dist/continuation/index.d.ts +1 -0
  7. package/dist/continuation/index.d.ts.map +1 -1
  8. package/dist/continuation/index.js +1 -0
  9. package/dist/continuation/index.js.map +1 -1
  10. package/dist/continuation/run-scoped-context-store.d.ts +79 -0
  11. package/dist/continuation/run-scoped-context-store.d.ts.map +1 -0
  12. package/dist/continuation/run-scoped-context-store.js +56 -0
  13. package/dist/continuation/run-scoped-context-store.js.map +1 -0
  14. package/dist/continuation/run-start-handler.d.ts +39 -9
  15. package/dist/continuation/run-start-handler.d.ts.map +1 -1
  16. package/dist/continuation/run-start-handler.js +12 -2
  17. package/dist/continuation/run-start-handler.js.map +1 -1
  18. package/dist/delegated-tool-bridge.d.ts +8 -0
  19. package/dist/delegated-tool-bridge.d.ts.map +1 -1
  20. package/dist/delegated-tool-bridge.js +117 -1
  21. package/dist/delegated-tool-bridge.js.map +1 -1
  22. package/dist/event-log.d.ts +18 -105
  23. package/dist/event-log.d.ts.map +1 -1
  24. package/dist/event-log.js +0 -17
  25. package/dist/event-log.js.map +1 -1
  26. package/dist/frontend-capability-tools.d.ts +1 -1
  27. package/dist/frontend-capability-tools.js +1 -1
  28. package/dist/frontend-session-registry.d.ts.map +1 -1
  29. package/dist/frontend-session-registry.js +26 -10
  30. package/dist/frontend-session-registry.js.map +1 -1
  31. package/dist/image-prompt-delivery.d.ts +56 -0
  32. package/dist/image-prompt-delivery.d.ts.map +1 -0
  33. package/dist/image-prompt-delivery.js +104 -0
  34. package/dist/image-prompt-delivery.js.map +1 -0
  35. package/dist/index.d.ts +2 -1
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +2 -1
  38. package/dist/index.js.map +1 -1
  39. package/dist/remote-tool-bridge.d.ts +45 -0
  40. package/dist/remote-tool-bridge.d.ts.map +1 -0
  41. package/dist/remote-tool-bridge.js +23 -0
  42. package/dist/remote-tool-bridge.js.map +1 -0
  43. package/dist/routines/routine-store.js +1 -1
  44. package/dist/routines/schedule.d.ts +0 -8
  45. package/dist/routines/schedule.d.ts.map +1 -1
  46. package/dist/routines/schedule.js +71 -44
  47. package/dist/routines/schedule.js.map +1 -1
  48. package/dist/routines/scheduler.d.ts +43 -0
  49. package/dist/routines/scheduler.d.ts.map +1 -1
  50. package/dist/routines/scheduler.js +160 -120
  51. package/dist/routines/scheduler.js.map +1 -1
  52. package/dist/run/core/retry.d.ts.map +1 -1
  53. package/dist/run/core/retry.js +47 -35
  54. package/dist/run/core/retry.js.map +1 -1
  55. package/dist/run/diagnostics/diagnostics.d.ts.map +1 -1
  56. package/dist/run/diagnostics/diagnostics.js +149 -91
  57. package/dist/run/diagnostics/diagnostics.js.map +1 -1
  58. package/dist/run-lifecycle.d.ts +84 -4
  59. package/dist/run-lifecycle.d.ts.map +1 -1
  60. package/dist/run-lifecycle.js +378 -116
  61. package/dist/run-lifecycle.js.map +1 -1
  62. package/dist/terminal-session.d.ts +1 -1
  63. package/dist/terminal-session.d.ts.map +1 -1
  64. package/dist/terminal-session.js +1 -1
  65. package/dist/tool-executor.d.ts +26 -6
  66. package/dist/tool-executor.d.ts.map +1 -1
  67. package/dist/tool-executor.js +220 -55
  68. package/dist/tool-executor.js.map +1 -1
  69. package/dist/tool-result-media.d.ts +79 -0
  70. package/dist/tool-result-media.d.ts.map +1 -0
  71. package/dist/tool-result-media.js +80 -0
  72. package/dist/tool-result-media.js.map +1 -0
  73. package/dist/tool-result-surfaces.d.ts +78 -0
  74. package/dist/tool-result-surfaces.d.ts.map +1 -0
  75. package/dist/tool-result-surfaces.js +92 -0
  76. package/dist/tool-result-surfaces.js.map +1 -0
  77. package/package.json +18 -9
package/README.md ADDED
@@ -0,0 +1,92 @@
1
+ # `@jini-ai/daemon`
2
+
3
+ The stateful agent daemon runtime: run lifecycle, the durable event-log reference implementation,
4
+ the tool-execution boundary, the agent executor that drives real coding-agent subprocesses,
5
+ interactive terminal sessions, a routine scheduler, and run-orchestration helpers. This is the
6
+ largest, most stateful package in the engine — where `@jini-ai/core` defines the composition
7
+ kernel and `@jini-ai/protocol` defines the wire types, `@jini-ai/daemon` is where those become a
8
+ running process: a `RunLifecycle` you can `start`/`emit`/`cancel`/`resume`/`stream`, a
9
+ `ToolExecutor` that is the *only* thing allowed to invoke a registered tool's handler, and an
10
+ `AgentExecutor` that spawns and streams a real agent CLI into that lifecycle.
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm install @jini-ai/daemon
16
+ ```
17
+
18
+ `node-pty` is an **optional peer dependency** — the package boots and every other capability
19
+ (run lifecycle, tool executor, agent executor, routines) works without it. Only
20
+ `createTerminalSessionManager`'s real (non-test) `PtySpawn` — an actual interactive terminal/PTY
21
+ spawn — needs `node-pty` installed; everything else has no native-addon dependency at all.
22
+
23
+ ## What you get
24
+
25
+ - **Run lifecycle** — `createRunLifecycle`, the `RunLifecycle` interface
26
+ (`start`/`get`/`list`/`cancel`/`onCancelRequested`/`emit`/`finish`/`resume`/`waitForTerminal`/
27
+ `stream`/`rehydrate`), keyed on an opaque `contextRef`, backed by an injected `EventLog`.
28
+ - **Event log** — `createInMemoryEventLog`, the reference `EventLog` implementation (the port
29
+ types themselves live in `@jini-ai/protocol` so a storage adapter like `@jini-ai/sqlite` can
30
+ implement them without depending on this package).
31
+ - **Tool-execution boundary** — `createToolExecutor`, the `ToolExecutor` interface
32
+ (`execute`/`resumeConfirmation`/`cancel`/`getAuditRecord`). It is the sole caller of
33
+ `@jini-ai/core/internal`'s `authorizeToolInvocation` — routes and agents only ever see
34
+ `ToolRegistry` descriptors, never a handler, and this is the one path that can run one, gated by
35
+ an injected `ExecutionDelegate` (authorize/confirm) with a resumable confirmation flow.
36
+ - **Agent executor** — `createAgentExecutor`, `AgentExecutorError` — wires
37
+ `@jini-ai/agent-runtime`'s registry/launch/stream-parsers into a real `node:child_process` spawn
38
+ that drives `RunLifecycle.emit()`/`finish()`.
39
+ - **Delegated & remote tool bridges** — `createDelegatedToolBridge` (an agent's own protocol
40
+ asking Jini to run a registered tool on its behalf, through `ToolExecutor`) and
41
+ `createRemoteToolEventRecorder` (lets a tool that executed in a different process still record
42
+ its `tool_use`/`tool_result` events into a run's log).
43
+ - **Frontend capability routing** — `createFrontendSessionRegistry` (addresses a run's attached
44
+ browser surface) and `createFrontendCapabilityRegistrations` (projects a frontend capability
45
+ manifest into `ToolRegistry` registrations — the only door into it).
46
+ - **Terminal sessions** — `createTerminalSessionManager`, `createTerminalToolRegistrations` — a
47
+ `node-pty`-backed session manager built on `@jini-ai/platform`'s generic ring-buffer engine, plus
48
+ session-token gating.
49
+ - **Routines** — `RoutineService`, `createInMemoryRoutineStore` (`routines/`) — a DST-safe
50
+ wall-clock scheduler plus CRUD + run-history store port.
51
+ - **Run-orchestration helpers** (`run/`) — `runResultFromStatus`, `deriveRunErrorCode`,
52
+ `decideSafeRunRetry`, `classifyProcessExitFailure`, `resumableFromProcessExit`, and the
53
+ `SAFE_RUN_RETRY_STRATEGY`/backoff constants — product-neutral retry/failure classification.
54
+ - **Continuation** (`continuation/`) — `createRunByteJournal`, `createDefaultRunStartHandler`, and
55
+ the continuation-transport types that support session resume across reconnects.
56
+ - **Legacy data migration** — a one-shot, idempotent data-root migrator
57
+ (`legacy-data-migration.ts`) for moving a daemon's data directory at startup.
58
+
59
+ ## Usage
60
+
61
+ ```ts
62
+ import { createToolRegistry } from '@jini-ai/core';
63
+ import { createInMemoryEventLog, createRunLifecycle, createToolExecutor } from '@jini-ai/daemon';
64
+
65
+ const eventLog = createInMemoryEventLog();
66
+ const lifecycle = createRunLifecycle({ eventLog });
67
+ const registry = createToolRegistry();
68
+ const executor = createToolExecutor({ registry });
69
+
70
+ const { run } = await lifecycle.start({ contextRef: 'workspace-42' });
71
+ await lifecycle.emit(run.id, { event: 'stdout', data: { chunk: 'hello' } });
72
+ await lifecycle.finish({ runId: run.id, status: 'succeeded', code: 0, signal: null });
73
+ ```
74
+
75
+ ## What's swappable
76
+
77
+ `EventLog` and `RunLifecycle` are consumed as ports — this package ships the reference in-memory
78
+ implementations, but a host wires `@jini-ai/sqlite`'s durable `EventLog` for persistence, or its
79
+ own `RunLifecycle`, as long as it satisfies the same `@jini-ai/protocol`/interface shapes.
80
+ `ExecutionDelegate` (authorize/confirm UI) is a transport-supplied seam on `createToolExecutor` —
81
+ omit it for a headless caller. `PtySpawn` (terminal sessions) and `RoutineStore` (routine
82
+ persistence) are likewise ports with one reference implementation each. The state-machine logic
83
+ itself (run transitions, the tool-execution audit trail, retry classification) is fixed.
84
+
85
+ ## Runtime
86
+
87
+ Node-only.
88
+ ESM only — ships `"type": "module"` with no CommonJS `require` build.
89
+
90
+ ## Provenance
91
+
92
+ See [source-map.md](./source-map.md) for per-file provenance and scope decisions. Apache-2.0.