negotium 0.1.17 → 0.1.18

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 (133) hide show
  1. package/README.md +211 -3
  2. package/dist/agent-helpers.js +1764 -0
  3. package/dist/agent-helpers.js.map +36 -0
  4. package/dist/background-bash.js +413 -0
  5. package/dist/background-bash.js.map +16 -0
  6. package/dist/{chunk-38pf4yqx.js → chunk-7azk83mw.js} +56 -23
  7. package/dist/{chunk-38pf4yqx.js.map → chunk-7azk83mw.js.map} +8 -6
  8. package/dist/cron.js +1039 -607
  9. package/dist/cron.js.map +30 -24
  10. package/dist/hosted-agent.js +582 -259
  11. package/dist/hosted-agent.js.map +20 -13
  12. package/dist/main.js +1146 -1078
  13. package/dist/main.js.map +38 -34
  14. package/dist/mcp-catalog.js +36 -0
  15. package/dist/mcp-catalog.js.map +10 -0
  16. package/dist/mcp-factories.js +1998 -0
  17. package/dist/mcp-factories.js.map +33 -0
  18. package/dist/outbox.js +272 -0
  19. package/dist/outbox.js.map +14 -0
  20. package/dist/platform-runtime.js +73 -0
  21. package/dist/platform-runtime.js.map +12 -0
  22. package/dist/prompts.js +30 -18
  23. package/dist/prompts.js.map +6 -5
  24. package/dist/query-runtime.js +595 -0
  25. package/dist/query-runtime.js.map +17 -0
  26. package/dist/registry.js +1 -1
  27. package/dist/rollout.js +1 -1
  28. package/dist/runtime/src/agents/auth-check.ts +42 -18
  29. package/dist/runtime/src/agents/claude-provider.ts +11 -10
  30. package/dist/runtime/src/agents/claude-runtime-inspection.ts +43 -0
  31. package/dist/runtime/src/agents/codex-tree-kill.ts +35 -349
  32. package/dist/runtime/src/agents/codex-tree-manager.ts +230 -0
  33. package/dist/runtime/src/agents/fork.ts +49 -20
  34. package/dist/runtime/src/agents/hosted-agent.ts +15 -0
  35. package/dist/runtime/src/agents/mcp-tools/common.ts +5 -3
  36. package/dist/runtime/src/agents/public-helpers.ts +45 -0
  37. package/dist/runtime/src/agents/task-events.ts +17 -5
  38. package/dist/runtime/src/agents/vault-tool-policy.ts +35 -14
  39. package/dist/runtime/src/index.ts +10 -1
  40. package/dist/runtime/src/mcp/factories/index.ts +53 -0
  41. package/dist/runtime/src/mcp/factories/session-comm.ts +120 -0
  42. package/dist/runtime/src/mcp/factories/stdio-protection.ts +24 -0
  43. package/dist/runtime/src/mcp/factories/system-health.ts +157 -0
  44. package/dist/runtime/src/mcp/factories/task.ts +185 -0
  45. package/dist/runtime/src/mcp/factories/token-stats.ts +123 -0
  46. package/dist/runtime/src/mcp/factories/vault-host.ts +8 -0
  47. package/dist/runtime/src/mcp/factories/vault.ts +128 -0
  48. package/dist/runtime/src/mcp/mcp-helpers.ts +3 -3
  49. package/dist/runtime/src/mcp/session-comm/context.ts +47 -0
  50. package/dist/runtime/src/mcp/session-comm/runtime.ts +12 -17
  51. package/dist/runtime/src/mcp/stdio-protect.ts +6 -83
  52. package/dist/runtime/src/mcp/system-health-server.ts +3 -128
  53. package/dist/runtime/src/mcp/task-server.ts +8 -164
  54. package/dist/runtime/src/mcp/token-stats-server.ts +4 -92
  55. package/dist/runtime/src/mcp/vault-http.ts +31 -15
  56. package/dist/runtime/src/mcp/vault-run.ts +8 -7
  57. package/dist/runtime/src/mcp/vault-server.ts +18 -95
  58. package/dist/runtime/src/mcp/wiki-server.ts +149 -116
  59. package/dist/runtime/src/outbox/file-ops.ts +74 -16
  60. package/dist/runtime/src/outbox/index.ts +13 -1
  61. package/dist/runtime/src/outbox/utils.ts +63 -40
  62. package/dist/runtime/src/platform/background-bash/manager.ts +197 -197
  63. package/dist/runtime/src/platform/config-helpers.ts +33 -0
  64. package/dist/runtime/src/platform/config.ts +4 -11
  65. package/dist/runtime/src/platform/file-utils.ts +25 -6
  66. package/dist/runtime/src/platform/jsonl.ts +27 -0
  67. package/dist/runtime/src/platform/lifecycle.ts +136 -143
  68. package/dist/runtime/src/platform/logger.ts +19 -8
  69. package/dist/runtime/src/platform/mcp-catalog-policy.ts +51 -0
  70. package/dist/runtime/src/platform/mcp-config.ts +20 -39
  71. package/dist/runtime/src/platform/public-runtime.ts +18 -0
  72. package/dist/runtime/src/query/active-rooms.ts +25 -116
  73. package/dist/runtime/src/query/public-runtime.ts +19 -0
  74. package/dist/runtime/src/query/room-query-registry.ts +215 -0
  75. package/dist/runtime/src/runtime/context-warning.ts +131 -0
  76. package/dist/runtime/src/runtime/public-helpers.ts +57 -0
  77. package/dist/runtime/src/runtime/usage-alert.ts +9 -42
  78. package/dist/runtime/src/storage/runtime-turn-requests.ts +13 -12
  79. package/dist/runtime/src/version.ts +1 -1
  80. package/dist/runtime-helpers.js +521 -49
  81. package/dist/runtime-helpers.js.map +19 -6
  82. package/dist/sqlite.js +74 -0
  83. package/dist/sqlite.js.map +10 -0
  84. package/dist/storage.js +33 -20
  85. package/dist/storage.js.map +5 -5
  86. package/dist/types/packages/core/src/agents/auth-check.d.ts +16 -0
  87. package/dist/types/packages/core/src/agents/claude-runtime-inspection.d.ts +9 -0
  88. package/dist/types/packages/core/src/agents/codex-tree-kill.d.ts +9 -74
  89. package/dist/types/packages/core/src/agents/codex-tree-manager.d.ts +28 -0
  90. package/dist/types/packages/core/src/agents/fork.d.ts +49 -0
  91. package/dist/types/packages/core/src/agents/hosted-agent.d.ts +4 -0
  92. package/dist/types/packages/core/src/agents/mcp-tools/common.d.ts +14 -0
  93. package/dist/types/packages/core/src/agents/public-helpers.d.ts +5 -0
  94. package/dist/types/packages/core/src/agents/task-events.d.ts +19 -0
  95. package/dist/types/packages/core/src/agents/vault-tool-policy.d.ts +13 -3
  96. package/dist/types/packages/core/src/mcp/factories/index.d.ts +10 -0
  97. package/dist/types/packages/core/src/mcp/factories/session-comm.d.ts +30 -0
  98. package/dist/types/packages/core/src/mcp/factories/stdio-protection.d.ts +10 -0
  99. package/dist/types/packages/core/src/mcp/factories/system-health.d.ts +17 -0
  100. package/dist/types/packages/core/src/mcp/factories/task.d.ts +13 -0
  101. package/dist/types/packages/core/src/mcp/factories/token-stats.d.ts +18 -0
  102. package/dist/types/packages/core/src/mcp/factories/vault-host.d.ts +7 -0
  103. package/dist/types/packages/core/src/mcp/factories/vault.d.ts +17 -0
  104. package/dist/types/packages/core/src/mcp/mcp-helpers.d.ts +26 -0
  105. package/dist/types/packages/core/src/mcp/session-comm/context.d.ts +16 -0
  106. package/dist/types/packages/core/src/mcp/vault-http.d.ts +23 -0
  107. package/dist/types/packages/core/src/mcp/vault-run.d.ts +19 -0
  108. package/dist/types/packages/core/src/mcp/wiki-server.d.ts +24 -0
  109. package/dist/types/packages/core/src/outbox/file-ops.d.ts +79 -0
  110. package/dist/types/packages/core/src/outbox/index.d.ts +2 -0
  111. package/dist/types/packages/core/src/outbox/utils.d.ts +16 -0
  112. package/dist/types/packages/core/src/platform/background-bash/manager.d.ts +28 -10
  113. package/dist/types/packages/core/src/platform/config-helpers.d.ts +10 -0
  114. package/dist/types/packages/core/src/platform/file-utils.d.ts +10 -0
  115. package/dist/types/packages/core/src/platform/jsonl.d.ts +2 -0
  116. package/dist/types/packages/core/src/platform/lifecycle.d.ts +40 -0
  117. package/dist/types/packages/core/src/platform/logger.d.ts +6 -0
  118. package/dist/types/packages/core/src/platform/mcp-catalog-policy.d.ts +61 -0
  119. package/dist/types/packages/core/src/platform/mcp-config.d.ts +2 -2
  120. package/dist/types/packages/core/src/platform/public-runtime.d.ts +3 -0
  121. package/dist/types/packages/core/src/query/active-rooms.d.ts +207 -0
  122. package/dist/types/packages/core/src/query/public-runtime.d.ts +2 -0
  123. package/dist/types/packages/core/src/query/room-query-registry.d.ts +70 -0
  124. package/dist/types/packages/core/src/query/types.d.ts +64 -0
  125. package/dist/types/packages/core/src/runtime/context-warning.d.ts +46 -0
  126. package/dist/types/packages/core/src/runtime/public-helpers.d.ts +11 -0
  127. package/dist/types/packages/core/src/storage/runtime-leases.d.ts +27 -0
  128. package/dist/types/packages/core/src/storage/runtime-topic-state.d.ts +30 -0
  129. package/dist/types/packages/core/src/topics/links.d.ts +2 -0
  130. package/dist/types/packages/core/src/version.d.ts +1 -1
  131. package/dist/vault.js +30 -18
  132. package/dist/vault.js.map +6 -5
  133. package/package.json +41 -1
package/README.md CHANGED
@@ -14,9 +14,8 @@ negotium status
14
14
  negotium stop
15
15
  negotium telegram
16
16
  negotium otium join <invite-code>
17
- negotium start terminal
18
- negotium start telegram # separate shell
19
- negotium start otium # separate shell
17
+ negotium serve otium # separate shell
18
+ negotium -v
20
19
  ```
21
20
 
22
21
  Authenticate Claude with `claude`, Codex with `codex login`, or Maestro with
@@ -47,6 +46,215 @@ import {
47
46
  These subpaths are the stable public boundary. Paths under `negotium/dist/` are package internals
48
47
  and may change between releases.
49
48
 
49
+ ## Context warning policy
50
+
51
+ Embedding hosts can share Negotium's provider-neutral 80% context warning policy while adapting
52
+ the command guidance to their own capabilities:
53
+
54
+ ```ts
55
+ import {
56
+ claudeRequestContextTokens,
57
+ createContextWarningState,
58
+ nextContextWarning,
59
+ } from "negotium/runtime-helpers";
60
+
61
+ const warningState = createContextWarningState(); // owned by this host/runtime
62
+ const contextTokens = claudeRequestContextTokens(claudeMessageUsage);
63
+ const alert = nextContextWarning(warningState, {
64
+ key: `${userId}:${topicId}`,
65
+ topicTitle,
66
+ usage: { contextTokens, contextWindow },
67
+ supportsCompact: false, // legacy Otium currently guides users to /new only
68
+ });
69
+ ```
70
+
71
+ Call `clearContextWarning(warningState, key)` when that consumer starts a fresh provider session.
72
+ The helper has no process-global dedupe state, so separate runtimes cannot suppress each other's
73
+ alerts.
74
+
75
+ ## Shared runtime utilities
76
+
77
+ Small provider-neutral helpers that otherwise tend to drift between embedding hosts are also
78
+ available from the same public boundary:
79
+
80
+ ```ts
81
+ import {
82
+ deepMapStrings,
83
+ delay,
84
+ errorResult,
85
+ errMsg,
86
+ isSensitivePath,
87
+ mcpError,
88
+ mcpOk,
89
+ parseUserIdArg,
90
+ sanitizeFileName,
91
+ sanitizeId,
92
+ sanitizeTopicName,
93
+ textResult,
94
+ topicAppLink,
95
+ topicMarkdownLink,
96
+ } from "negotium/runtime-helpers";
97
+ ```
98
+
99
+ These exports are stateless or caller-owned. Process singleton utilities such as logging,
100
+ configuration, SQLite ownership, and outbox watchers remain excluded. Lifecycle reuse is available
101
+ only through `createLifecycleManager({ logger, process })`, which keeps handlers and signal hooks
102
+ owned by the embedding host.
103
+
104
+ Maintainers can measure source overlap against an embedding host and fail on regressions with:
105
+
106
+ ```sh
107
+ bun run audit:runtime-overlap \
108
+ --source=packages/core/src \
109
+ --consumer=/path/to/otium/apps/runtime-api/src \
110
+ --max-exact=10 --max-95=31 --max-80=55
111
+ ```
112
+
113
+ The caps are upper bounds: removing wrappers makes the counts fall, while newly introduced copies
114
+ make the audit fail.
115
+
116
+ ## MCP server factories
117
+
118
+ Embedding hosts can reuse tool registration while retaining ownership of storage and process
119
+ lifecycle. Factories never connect to stdio or parse global CLI arguments:
120
+
121
+ ```ts
122
+ import { createTaskMcpServer } from "negotium/mcp-factories";
123
+
124
+ const taskServer = createTaskMcpServer(
125
+ { userId, topic: topicTitle, topicId },
126
+ {
127
+ readTasks: (userId, scopeKey) => hostTasks.read(userId, scopeKey),
128
+ writeTasks: (userId, scopeKey, tasks) =>
129
+ hostTasks.write(userId, scopeKey, tasks),
130
+ },
131
+ );
132
+ ```
133
+
134
+ `createTokenStatsMcpServer({ userId }, host)` and `createSystemHealthMcpServer(host)` provide the
135
+ same boundary for usage statistics and system probes. The standalone Negotium CLI remains a thin
136
+ stdio entrypoint over these factories. More common MCP servers will move behind this host-injection
137
+ boundary incrementally.
138
+
139
+ Vault consumers must inject credential operations explicitly, so two embedding hosts cannot share
140
+ process-global Vault state accidentally:
141
+
142
+ ```ts
143
+ import { createVaultMcpServer, protectMcpStdio } from "negotium/mcp-factories";
144
+
145
+ const vaultServer = createVaultMcpServer(
146
+ { userId, httpOnly: true },
147
+ {
148
+ list: (id) => vault.list(id),
149
+ substitute: (id, text) => vault.substitute(id, text),
150
+ redact: (id, text) => vault.redact(id, text),
151
+ },
152
+ );
153
+ ```
154
+
155
+ `protectMcpStdio({ env, console })` is an opt-in standalone-entrypoint helper and returns an
156
+ idempotent restore function. Embedded transports should normally avoid changing process-wide
157
+ console behavior.
158
+
159
+ Wiki hosts inject both the filesystem root and the optional topic-brief bridge. Importing the
160
+ factory does not parse `process.argv`, open SQLite, or connect stdio:
161
+
162
+ ```ts
163
+ import { createWikiMcpServer } from "negotium/mcp-factories";
164
+
165
+ const wikiServer = createWikiMcpServer(
166
+ { userId, topicId, surface: "wiki" },
167
+ {
168
+ wikiRoot: hostWikiRoot,
169
+ getTopicBrief: (id) => hostBriefs.get(id),
170
+ setTopicBrief: (id, patch) => hostBriefs.set(id, patch),
171
+ },
172
+ );
173
+ ```
174
+
175
+ Long-lived hosts can also own an isolated background process manager:
176
+
177
+ ```ts
178
+ import { createBackgroundBashManager } from "negotium/background-bash";
179
+
180
+ const backgroundBash = createBackgroundBashManager({
181
+ env: hostEnvironment,
182
+ basePort: 47_000,
183
+ maxPort: 47_099,
184
+ });
185
+ ```
186
+
187
+ Each manager owns its capability, server identity, reserved ports, process handles, and known
188
+ contexts. The root exports remain compatibility wrappers over Negotium's default manager.
189
+
190
+ ## Agent host helpers
191
+
192
+ Embedding hosts can reuse pre-flight authentication, fork lifecycle, and task snapshot behavior
193
+ without copying provider files:
194
+
195
+ ```ts
196
+ import {
197
+ acquireCodexSpawnLock,
198
+ checkAgentAuth,
199
+ forkAgentSession,
200
+ killCodexTrees,
201
+ resolveTaskEventScope,
202
+ withTaskSnapshots,
203
+ } from "negotium/agent-helpers";
204
+
205
+ const auth = checkAgentAuth("codex", hostAuth);
206
+ const scope = resolveTaskEventScope(queryOptions, hostTasks);
207
+ ```
208
+
209
+ The host arguments own credential paths, environment checks, and task storage. Provider execution
210
+ itself remains available through `negotium/hosted-agent`.
211
+
212
+ Process-tree helpers are also exported from this subpath so an embedding runtime does not need a
213
+ copied `codex-tree-kill.ts`. Their ownership Set is process-local; use them only for Codex children
214
+ spawned by the current runtime process.
215
+
216
+ ## Agent helper embedding API
217
+
218
+ Agent switching, task-stream snapshots, and session forks are available from one stable subpath:
219
+
220
+ ```ts
221
+ import {
222
+ checkAgentAuth,
223
+ forkAgentSession,
224
+ resolveTaskEventScope,
225
+ withTaskSnapshots,
226
+ } from "negotium/agent-helpers";
227
+
228
+ const auth = checkAgentAuth("codex", hostAuth);
229
+ const scope = resolveTaskEventScope(queryOptions, hostTasks);
230
+ const events = scope ? withTaskSnapshots(providerEvents, scope, hostTasks) : providerEvents;
231
+ ```
232
+
233
+ Supplying `AgentAuthHost` and `TaskEventHost` keeps auth paths, environment state, and task stores
234
+ owned by the embedding process. The default host remains available only as a convenience for the
235
+ standalone Negotium runtime.
236
+
237
+ ## MCP catalog policy
238
+
239
+ `negotium/mcp-catalog` exposes transport-independent required/optional classification. Embedding
240
+ hosts can merge host-only capabilities without duplicating Negotium's built-in list:
241
+
242
+ ```ts
243
+ import {
244
+ classifyForumMcpServers,
245
+ COMMON_RUNTIME_MCP_POLICY,
246
+ } from "negotium/mcp-catalog";
247
+
248
+ const policy = {
249
+ ...COMMON_RUNTIME_MCP_POLICY,
250
+ "cron-manager": { scopes: ["forum", "manager"], forumRequired: true },
251
+ };
252
+ const { required, optional } = classifyForumMcpServers(policy);
253
+ ```
254
+
255
+ Playwright and background Bash are canonical required forum capabilities, so topic settings should
256
+ not present them as optional toggles. Host-only entries choose their own `forumRequired` policy.
257
+
50
258
  ## Storage embedding API
51
259
 
52
260
  Embedding hosts can reuse Negotium's SQLite and filesystem stores without importing package