negotium 0.1.17 → 0.1.19
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.
- package/README.md +211 -3
- package/dist/agent-helpers.js +6245 -0
- package/dist/agent-helpers.js.map +81 -0
- package/dist/background-bash.js +413 -0
- package/dist/background-bash.js.map +16 -0
- package/dist/{chunk-38pf4yqx.js → chunk-7azk83mw.js} +56 -23
- package/dist/{chunk-38pf4yqx.js.map → chunk-7azk83mw.js.map} +8 -6
- package/dist/cron.js +1204 -636
- package/dist/cron.js.map +35 -29
- package/dist/hosted-agent.js +582 -259
- package/dist/hosted-agent.js.map +20 -13
- package/dist/main.js +1384 -1168
- package/dist/main.js.map +43 -39
- package/dist/mcp-catalog.js +36 -0
- package/dist/mcp-catalog.js.map +10 -0
- package/dist/mcp-factories.js +1998 -0
- package/dist/mcp-factories.js.map +33 -0
- package/dist/outbox.js +272 -0
- package/dist/outbox.js.map +14 -0
- package/dist/platform-runtime.js +73 -0
- package/dist/platform-runtime.js.map +12 -0
- package/dist/prompts.js +30 -18
- package/dist/prompts.js.map +6 -5
- package/dist/query-runtime.js +604 -0
- package/dist/query-runtime.js.map +18 -0
- package/dist/registry.js +1 -1
- package/dist/rollout.js +1 -1
- package/dist/runtime/src/agents/archiver.ts +12 -4
- package/dist/runtime/src/agents/auth-check.ts +42 -18
- package/dist/runtime/src/agents/claude-provider.ts +11 -10
- package/dist/runtime/src/agents/claude-runtime-inspection.ts +43 -0
- package/dist/runtime/src/agents/codex-tree-kill.ts +35 -349
- package/dist/runtime/src/agents/codex-tree-manager.ts +230 -0
- package/dist/runtime/src/agents/fork.ts +49 -20
- package/dist/runtime/src/agents/hosted-agent.ts +15 -0
- package/dist/runtime/src/agents/idle-archiver.ts +75 -28
- package/dist/runtime/src/agents/mcp-tools/common.ts +5 -3
- package/dist/runtime/src/agents/mcp-tools/visual-compat.ts +24 -0
- package/dist/runtime/src/agents/public-helpers.ts +61 -0
- package/dist/runtime/src/agents/task-events.ts +17 -5
- package/dist/runtime/src/agents/vault-tool-policy.ts +35 -14
- package/dist/runtime/src/index.ts +10 -1
- package/dist/runtime/src/mcp/factories/index.ts +53 -0
- package/dist/runtime/src/mcp/factories/session-comm.ts +120 -0
- package/dist/runtime/src/mcp/factories/stdio-protection.ts +24 -0
- package/dist/runtime/src/mcp/factories/system-health.ts +157 -0
- package/dist/runtime/src/mcp/factories/task.ts +185 -0
- package/dist/runtime/src/mcp/factories/token-stats.ts +123 -0
- package/dist/runtime/src/mcp/factories/vault-host.ts +8 -0
- package/dist/runtime/src/mcp/factories/vault.ts +128 -0
- package/dist/runtime/src/mcp/mcp-helpers.ts +3 -3
- package/dist/runtime/src/mcp/session-comm/context.ts +47 -0
- package/dist/runtime/src/mcp/session-comm/runtime.ts +12 -17
- package/dist/runtime/src/mcp/stdio-protect.ts +6 -83
- package/dist/runtime/src/mcp/system-health-server.ts +3 -128
- package/dist/runtime/src/mcp/task-server.ts +8 -164
- package/dist/runtime/src/mcp/token-stats-server.ts +4 -92
- package/dist/runtime/src/mcp/vault-http.ts +31 -15
- package/dist/runtime/src/mcp/vault-run.ts +8 -7
- package/dist/runtime/src/mcp/vault-server.ts +18 -95
- package/dist/runtime/src/mcp/wiki-server.ts +149 -116
- package/dist/runtime/src/outbox/file-ops.ts +74 -16
- package/dist/runtime/src/outbox/index.ts +13 -1
- package/dist/runtime/src/outbox/utils.ts +63 -40
- package/dist/runtime/src/platform/background-bash/manager.ts +197 -197
- package/dist/runtime/src/platform/config-helpers.ts +33 -0
- package/dist/runtime/src/platform/config.ts +4 -11
- package/dist/runtime/src/platform/file-utils.ts +25 -6
- package/dist/runtime/src/platform/jsonl.ts +27 -0
- package/dist/runtime/src/platform/lifecycle.ts +136 -143
- package/dist/runtime/src/platform/logger.ts +19 -8
- package/dist/runtime/src/platform/mcp-catalog-policy.ts +51 -0
- package/dist/runtime/src/platform/mcp-config.ts +20 -39
- package/dist/runtime/src/platform/public-runtime.ts +18 -0
- package/dist/runtime/src/query/active-rooms.ts +25 -116
- package/dist/runtime/src/query/public-runtime.ts +24 -0
- package/dist/runtime/src/query/room-query-registry.ts +215 -0
- package/dist/runtime/src/runtime/context-warning.ts +131 -0
- package/dist/runtime/src/runtime/public-helpers.ts +59 -0
- package/dist/runtime/src/runtime/usage-alert.ts +9 -42
- package/dist/runtime/src/storage/runtime-turn-requests.ts +13 -12
- package/dist/runtime/src/storage/topic-archive-state.ts +168 -4
- package/dist/runtime/src/storage/topic-archive.ts +16 -11
- package/dist/runtime/src/topics/session.ts +19 -3
- package/dist/runtime/src/version.ts +1 -1
- package/dist/runtime-helpers.js +542 -49
- package/dist/runtime-helpers.js.map +19 -6
- package/dist/sqlite.js +74 -0
- package/dist/sqlite.js.map +10 -0
- package/dist/storage.js +151 -32
- package/dist/storage.js.map +7 -7
- package/dist/types/packages/core/src/agents/archiver.d.ts +37 -0
- package/dist/types/packages/core/src/agents/auth-check.d.ts +16 -0
- package/dist/types/packages/core/src/agents/claude-runtime-inspection.d.ts +9 -0
- package/dist/types/packages/core/src/agents/codex-tree-kill.d.ts +9 -74
- package/dist/types/packages/core/src/agents/codex-tree-manager.d.ts +28 -0
- package/dist/types/packages/core/src/agents/fork.d.ts +49 -0
- package/dist/types/packages/core/src/agents/hosted-agent.d.ts +4 -0
- package/dist/types/packages/core/src/agents/idle-archiver.d.ts +28 -0
- package/dist/types/packages/core/src/agents/index.d.ts +3 -0
- package/dist/types/packages/core/src/agents/mcp-tools/common.d.ts +14 -0
- package/dist/types/packages/core/src/agents/mcp-tools/visual-compat.d.ts +64 -0
- package/dist/types/packages/core/src/agents/mcp-tools/visuals.d.ts +89 -0
- package/dist/types/packages/core/src/agents/public-helpers.d.ts +8 -0
- package/dist/types/packages/core/src/agents/task-events.d.ts +19 -0
- package/dist/types/packages/core/src/agents/tool-format.d.ts +18 -0
- package/dist/types/packages/core/src/agents/vault-tool-policy.d.ts +13 -3
- package/dist/types/packages/core/src/bus.d.ts +106 -0
- package/dist/types/packages/core/src/mcp/factories/index.d.ts +10 -0
- package/dist/types/packages/core/src/mcp/factories/session-comm.d.ts +30 -0
- package/dist/types/packages/core/src/mcp/factories/stdio-protection.d.ts +10 -0
- package/dist/types/packages/core/src/mcp/factories/system-health.d.ts +17 -0
- package/dist/types/packages/core/src/mcp/factories/task.d.ts +13 -0
- package/dist/types/packages/core/src/mcp/factories/token-stats.d.ts +18 -0
- package/dist/types/packages/core/src/mcp/factories/vault-host.d.ts +7 -0
- package/dist/types/packages/core/src/mcp/factories/vault.d.ts +17 -0
- package/dist/types/packages/core/src/mcp/mcp-helpers.d.ts +26 -0
- package/dist/types/packages/core/src/mcp/session-comm/context.d.ts +16 -0
- package/dist/types/packages/core/src/mcp/vault-http.d.ts +23 -0
- package/dist/types/packages/core/src/mcp/vault-run.d.ts +19 -0
- package/dist/types/packages/core/src/mcp/wiki-server.d.ts +24 -0
- package/dist/types/packages/core/src/outbox/file-ops.d.ts +79 -0
- package/dist/types/packages/core/src/outbox/index.d.ts +2 -0
- package/dist/types/packages/core/src/outbox/utils.d.ts +16 -0
- package/dist/types/packages/core/src/platform/background-bash/manager.d.ts +28 -10
- package/dist/types/packages/core/src/platform/config-helpers.d.ts +10 -0
- package/dist/types/packages/core/src/platform/file-utils.d.ts +10 -0
- package/dist/types/packages/core/src/platform/jsonl.d.ts +2 -0
- package/dist/types/packages/core/src/platform/lifecycle.d.ts +40 -0
- package/dist/types/packages/core/src/platform/logger.d.ts +6 -0
- package/dist/types/packages/core/src/platform/mcp-catalog-policy.d.ts +61 -0
- package/dist/types/packages/core/src/platform/mcp-config.d.ts +2 -2
- package/dist/types/packages/core/src/platform/public-runtime.d.ts +3 -0
- package/dist/types/packages/core/src/query/active-rooms.d.ts +207 -0
- package/dist/types/packages/core/src/query/public-runtime.d.ts +3 -0
- package/dist/types/packages/core/src/query/room-query-registry.d.ts +70 -0
- package/dist/types/packages/core/src/query/types.d.ts +64 -0
- package/dist/types/packages/core/src/runtime/context-warning.d.ts +46 -0
- package/dist/types/packages/core/src/runtime/public-helpers.d.ts +12 -0
- package/dist/types/packages/core/src/storage/runtime-events.d.ts +19 -0
- package/dist/types/packages/core/src/storage/runtime-leases.d.ts +27 -0
- package/dist/types/packages/core/src/storage/runtime-topic-state.d.ts +30 -0
- package/dist/types/packages/core/src/storage/topic-archive-state.d.ts +23 -0
- package/dist/types/packages/core/src/storage/topic-archive.d.ts +1 -1
- package/dist/types/packages/core/src/topics/links.d.ts +2 -0
- package/dist/types/packages/core/src/topics/personal-general.d.ts +13 -0
- package/dist/types/packages/core/src/version.d.ts +1 -1
- package/dist/vault.js +30 -18
- package/dist/vault.js.map +6 -5
- 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
|
|
18
|
-
negotium
|
|
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=0 --max-95=4 --max-80=14
|
|
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
|