negotium 0.1.37 → 0.1.39

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 (64) hide show
  1. package/README.md +19 -0
  2. package/dist/agent-helpers.js +15637 -5674
  3. package/dist/agent-helpers.js.map +85 -37
  4. package/dist/browser-runtime.js +1600 -0
  5. package/dist/browser-runtime.js.map +28 -0
  6. package/dist/hosted-agent.js +8 -8
  7. package/dist/hosted-agent.js.map +6 -5
  8. package/dist/main.js +3790 -3113
  9. package/dist/main.js.map +33 -29
  10. package/dist/mcp-factories.js +15141 -301
  11. package/dist/mcp-factories.js.map +100 -7
  12. package/dist/prompts.js +117 -49
  13. package/dist/prompts.js.map +3 -3
  14. package/dist/query-runtime.js +310 -1
  15. package/dist/query-runtime.js.map +10 -5
  16. package/dist/runtime/src/agents/archiver.ts +407 -296
  17. package/dist/runtime/src/agents/mcp-tools/ask-user.ts +440 -274
  18. package/dist/runtime/src/agents/mcp-tools/self-config.ts +139 -65
  19. package/dist/runtime/src/agents/mcp-tools/spawn-subagent.ts +1037 -816
  20. package/dist/runtime/src/agents/public-helpers.ts +82 -0
  21. package/dist/runtime/src/agents/self-config-core.ts +574 -278
  22. package/dist/runtime/src/agents/topic-cleanup.ts +167 -129
  23. package/dist/runtime/src/index.ts +4 -1
  24. package/dist/runtime/src/mcp/factories/index.ts +9 -0
  25. package/dist/runtime/src/mcp/session-comm/topic-catalog.ts +132 -0
  26. package/dist/runtime/src/mcp/session-comm/topics.ts +23 -57
  27. package/dist/runtime/src/platform/mcp-config.ts +2 -4
  28. package/dist/runtime/src/platform/playwright/browser-processes.ts +3 -2
  29. package/dist/runtime/src/platform/playwright/capability.ts +5 -0
  30. package/dist/runtime/src/platform/playwright/manager.ts +380 -66
  31. package/dist/runtime/src/platform/playwright/public-runtime.ts +45 -0
  32. package/dist/runtime/src/platform/playwright/transport-probe.ts +89 -0
  33. package/dist/runtime/src/prompts/builders.ts +192 -51
  34. package/dist/runtime/src/query/active-rooms.ts +2 -0
  35. package/dist/runtime/src/query/public-runtime.ts +8 -0
  36. package/dist/runtime/src/query/state.ts +69 -33
  37. package/dist/runtime/src/query/types.ts +1 -0
  38. package/dist/runtime/src/runtime/playwright-turn-abort.ts +59 -0
  39. package/dist/runtime/src/runtime/turn-event-stream.ts +23 -6
  40. package/dist/runtime/src/runtime/turn-runner.ts +6 -1
  41. package/dist/runtime/src/version.ts +1 -1
  42. package/dist/types/packages/core/src/agents/api-topic-agent-switch.d.ts +38 -0
  43. package/dist/types/packages/core/src/agents/archiver.d.ts +52 -16
  44. package/dist/types/packages/core/src/agents/mcp-tools/ask-user.d.ts +75 -4
  45. package/dist/types/packages/core/src/agents/mcp-tools/self-config.d.ts +17 -0
  46. package/dist/types/packages/core/src/agents/mcp-tools/spawn-subagent.d.ts +112 -25
  47. package/dist/types/packages/core/src/agents/public-helpers.d.ts +7 -0
  48. package/dist/types/packages/core/src/agents/self-config-core.d.ts +185 -0
  49. package/dist/types/packages/core/src/agents/topic-cleanup.d.ts +30 -24
  50. package/dist/types/packages/core/src/mcp/factories/index.d.ts +1 -0
  51. package/dist/types/packages/core/src/mcp/session-comm/topic-catalog.d.ts +46 -0
  52. package/dist/types/packages/core/src/platform/mcp-config.d.ts +2 -1
  53. package/dist/types/packages/core/src/platform/playwright/capability.d.ts +1 -0
  54. package/dist/types/packages/core/src/platform/playwright/manager.d.ts +65 -5
  55. package/dist/types/packages/core/src/platform/playwright/public-runtime.d.ts +4 -0
  56. package/dist/types/packages/core/src/platform/playwright/transport-probe.d.ts +13 -0
  57. package/dist/types/packages/core/src/prompts/builders.d.ts +29 -3
  58. package/dist/types/packages/core/src/query/active-rooms.d.ts +2 -0
  59. package/dist/types/packages/core/src/query/public-runtime.d.ts +1 -0
  60. package/dist/types/packages/core/src/query/state.d.ts +13 -0
  61. package/dist/types/packages/core/src/query/types.d.ts +2 -1
  62. package/dist/types/packages/core/src/runtime/playwright-turn-abort.d.ts +12 -0
  63. package/dist/types/packages/core/src/version.d.ts +1 -1
  64. package/package.json +6 -1
@@ -1,23 +1,14 @@
1
1
  import { z } from "zod";
2
2
  import { type SharedMcpTool, textResult } from "#agents/mcp-tools/common";
3
3
  import {
4
- cancelSelfConfigSchedule,
5
- forkSelfConfigTopic,
6
- getSelfConfigAgent,
7
- getSelfConfigEffort,
8
- getSelfConfigModel,
9
- getSelfConfigSchedule,
4
+ createSelfConfigCore,
5
+ defaultSelfConfigCore,
10
6
  SELF_CONFIG_MCP_KEY,
11
- SELF_SCHEDULE_MAX_DELAY_SECONDS,
12
- SELF_SCHEDULE_MAX_MESSAGE_LENGTH,
13
7
  type SelfConfigContext,
8
+ type SelfConfigCore,
9
+ type SelfConfigHost,
10
+ type SelfConfigProductConfig,
14
11
  type SelfConfigResult,
15
- scheduleSelfConfigContinue,
16
- setSelfConfigAgent,
17
- setSelfConfigEffort,
18
- setSelfConfigModel,
19
- spawnSelfConfigTopic,
20
- updateSelfConfigSchedule,
21
12
  } from "#agents/self-config-core";
22
13
  import { type AgentKind, EFFORT_VALUES, type EffortLevel, SUPPORTED_AGENTS } from "#types";
23
14
 
@@ -27,6 +18,17 @@ export { SELF_CONFIG_MCP_KEY };
27
18
  const AGENT_VALUES = SUPPORTED_AGENTS as readonly AgentKind[];
28
19
  export const SELF_CONFIG_DERIVED_TOPIC_LIMIT = 5;
29
20
 
21
+ export interface SelfConfigRuntime {
22
+ readonly core: SelfConfigCore;
23
+ readonly mcpKey: string;
24
+ createToolDefinitions(ctx: SelfConfigContext | (() => SelfConfigContext)): SharedMcpTool[];
25
+ }
26
+
27
+ export interface SelfConfigRuntimeOptions {
28
+ host: SelfConfigHost;
29
+ product?: Partial<SelfConfigProductConfig>;
30
+ }
31
+
30
32
  function mcpResult(result: SelfConfigResult) {
31
33
  return {
32
34
  ...textResult(result.text),
@@ -38,117 +40,169 @@ function contextGetter(ctx: SelfConfigContext | (() => SelfConfigContext)) {
38
40
  return typeof ctx === "function" ? ctx : () => ctx;
39
41
  }
40
42
 
41
- export function createSelfConfigToolDefinitions(
43
+ function toolDescription(core: SelfConfigCore, name: string, fallback: string): string {
44
+ return core.product.toolDescriptions[name] ?? fallback;
45
+ }
46
+
47
+ export function createSelfConfigRuntime(options: SelfConfigRuntimeOptions): SelfConfigRuntime {
48
+ const core = createSelfConfigCore(options.host, options.product);
49
+ const runtime: SelfConfigRuntime = {
50
+ core,
51
+ mcpKey: core.product.mcpKey,
52
+ createToolDefinitions: (ctx) => createSelfConfigToolDefinitionsForCore(core, ctx),
53
+ };
54
+ return Object.freeze(runtime);
55
+ }
56
+
57
+ export function createSelfConfigToolDefinitionsForCore(
58
+ core: SelfConfigCore,
42
59
  ctx: SelfConfigContext | (() => SelfConfigContext),
43
60
  ): SharedMcpTool[] {
44
61
  const getCtx = contextGetter(ctx);
45
62
  let derivedCount = 0;
46
63
 
47
- return [
64
+ const tools: SharedMcpTool[] = [
48
65
  {
49
66
  name: "set_model",
50
- description:
67
+ description: toolDescription(
68
+ core,
69
+ "set_model",
51
70
  "Set the model for THIS topic; it persists and applies from the NEXT turn. Use a model from the system prompt's same-agent catalog. Cross-agent changes require an explicit user-requested set_agent first. Fails if the user locked this setting. NEVER use 'fable' unless explicitly requested.",
71
+ ),
52
72
  schema: { model: z.string().describe("Model id valid for the topic's current agent.") },
53
73
  async handler({ model }: { model: string }) {
54
- return mcpResult(setSelfConfigModel(getCtx(), model));
74
+ return mcpResult(core.setModel(getCtx(), model));
55
75
  },
56
76
  },
57
77
  {
58
78
  name: "get_model",
59
- description:
79
+ description: toolDescription(
80
+ core,
81
+ "get_model",
60
82
  "Get the current model setting for THIS topic and whether it is locked by the user.",
83
+ ),
61
84
  schema: {},
62
85
  async handler() {
63
- return mcpResult(getSelfConfigModel(getCtx()));
86
+ return mcpResult(core.getModel(getCtx()));
64
87
  },
65
88
  },
66
89
  {
67
90
  name: "set_agent",
68
- description:
91
+ description: toolDescription(
92
+ core,
93
+ "set_agent",
69
94
  "Switch the agent backend for THIS topic between 'claude', 'codex', and 'maestro'. Clears the topic's model/effort override so the new agent starts at its defaults. Fails if the user locked this setting. Use only when the user explicitly asks to switch the runtime itself.",
95
+ ),
70
96
  schema: { agent: z.enum(AGENT_VALUES as unknown as [AgentKind, ...AgentKind[]]) },
71
97
  async handler({ agent }: { agent: AgentKind }) {
72
- return mcpResult(setSelfConfigAgent(getCtx(), agent));
98
+ return mcpResult(core.setAgent(getCtx(), agent));
73
99
  },
74
100
  },
75
101
  {
76
102
  name: "get_agent",
77
- description: "Get the current agent backend ('claude' / 'codex' / 'maestro') for THIS topic.",
103
+ description: toolDescription(
104
+ core,
105
+ "get_agent",
106
+ "Get the current agent backend ('claude' / 'codex' / 'maestro') for THIS topic.",
107
+ ),
78
108
  schema: {},
79
109
  async handler() {
80
- return mcpResult(getSelfConfigAgent(getCtx()));
110
+ return mcpResult(core.getAgent(getCtx()));
81
111
  },
82
112
  },
83
113
  {
84
114
  name: "set_effort",
85
- description:
115
+ description: toolDescription(
116
+ core,
117
+ "set_effort",
86
118
  "Set the reasoning effort for THIS topic. Claude: low/medium/high/xhigh/max. Codex: low/medium/high/xhigh. Maestro: low/medium/high/xhigh/max. Higher effort costs more and is slower. Fails if the user locked this setting.",
119
+ ),
87
120
  schema: {
88
121
  effort: z
89
122
  .enum(EFFORT_VALUES)
90
123
  .describe("Reasoning effort level valid for the topic's current agent."),
91
124
  },
92
125
  async handler({ effort }: { effort: EffortLevel }) {
93
- return mcpResult(setSelfConfigEffort(getCtx(), effort));
126
+ return mcpResult(core.setEffort(getCtx(), effort));
94
127
  },
95
128
  },
96
129
  {
97
130
  name: "get_effort",
98
- description:
131
+ description: toolDescription(
132
+ core,
133
+ "get_effort",
99
134
  "Get the current reasoning effort setting for THIS topic and whether it is locked by the user.",
135
+ ),
100
136
  schema: {},
101
137
  async handler() {
102
- return mcpResult(getSelfConfigEffort(getCtx()));
138
+ return mcpResult(core.getEffort(getCtx()));
103
139
  },
104
140
  },
105
- {
141
+ ];
142
+
143
+ if (core.host.schedules) {
144
+ tools.push({
106
145
  name: "schedule_self",
107
- description:
146
+ description: toolDescription(
147
+ core,
148
+ "schedule_self",
108
149
  "Create the one pending durable delayed continuation allowed for THIS topic without blocking the current turn. Use it to check a long-running operation or resume work later. The future message must be self-contained. If one already exists, use get_self_schedule then update_self_schedule or cancel_self_schedule. For recurring or longer-lived schedules, use cron-manager instead.",
150
+ ),
109
151
  schema: {
110
152
  delay_seconds: z
111
153
  .number()
112
154
  .int()
113
155
  .min(1)
114
- .max(SELF_SCHEDULE_MAX_DELAY_SECONDS)
115
- .describe("Seconds before this topic resumes, from 1 through 86400 (24 hours)."),
156
+ .max(core.product.scheduleMaxDelaySeconds)
157
+ .describe(
158
+ `Seconds before this topic resumes, from 1 through ${core.product.scheduleMaxDelaySeconds}${
159
+ core.product.scheduleMaxDelaySeconds === 86_400 ? " (24 hours)" : ""
160
+ }.`,
161
+ ),
116
162
  message: z
117
163
  .string()
118
164
  .min(1)
119
- .max(SELF_SCHEDULE_MAX_MESSAGE_LENGTH)
165
+ .max(core.product.scheduleMaxMessageLength)
120
166
  .describe("Self-contained instruction delivered to your future turn."),
121
167
  },
122
168
  async handler({ delay_seconds, message }: { delay_seconds: number; message: string }) {
123
- return mcpResult(scheduleSelfConfigContinue(getCtx(), delay_seconds, message));
169
+ return mcpResult(core.scheduleContinue(getCtx(), delay_seconds, message));
124
170
  },
125
- },
126
- {
171
+ });
172
+ tools.push({
127
173
  name: "get_self_schedule",
128
- description:
174
+ description: toolDescription(
175
+ core,
176
+ "get_self_schedule",
129
177
  "Inspect THIS topic's pending one-shot delayed continuation, including its schedule ID, delivery time, and message.",
178
+ ),
130
179
  schema: {},
131
180
  async handler() {
132
- return mcpResult(getSelfConfigSchedule(getCtx()));
181
+ return mcpResult(core.getSchedule(getCtx()));
133
182
  },
134
- },
135
- {
183
+ });
184
+ tools.push({
136
185
  name: "update_self_schedule",
137
- description:
186
+ description: toolDescription(
187
+ core,
188
+ "update_self_schedule",
138
189
  "Edit THIS topic's pending self-schedule. Provide its schedule_id from schedule_self/get_self_schedule and change delay_seconds, message, or both. delay_seconds is measured from this update. A schedule that already started cannot be edited.",
190
+ ),
139
191
  schema: {
140
192
  schedule_id: z.string().min(1).describe("Exact ID of the pending self-schedule."),
141
193
  delay_seconds: z
142
194
  .number()
143
195
  .int()
144
196
  .min(1)
145
- .max(SELF_SCHEDULE_MAX_DELAY_SECONDS)
197
+ .max(core.product.scheduleMaxDelaySeconds)
146
198
  .optional()
147
- .describe("New delay from now, from 1 through 86400 seconds."),
199
+ .describe(
200
+ `New delay from now, from 1 through ${core.product.scheduleMaxDelaySeconds} seconds.`,
201
+ ),
148
202
  message: z
149
203
  .string()
150
204
  .min(1)
151
- .max(SELF_SCHEDULE_MAX_MESSAGE_LENGTH)
205
+ .max(core.product.scheduleMaxMessageLength)
152
206
  .optional()
153
207
  .describe("Replacement self-contained future instruction."),
154
208
  },
@@ -162,59 +216,79 @@ export function createSelfConfigToolDefinitions(
162
216
  message?: string;
163
217
  }) {
164
218
  return mcpResult(
165
- updateSelfConfigSchedule(getCtx(), schedule_id, {
219
+ core.updateSchedule(getCtx(), schedule_id, {
166
220
  delaySeconds: delay_seconds,
167
221
  message,
168
222
  }),
169
223
  );
170
224
  },
171
- },
172
- {
225
+ });
226
+ tools.push({
173
227
  name: "cancel_self_schedule",
174
- description:
228
+ description: toolDescription(
229
+ core,
230
+ "cancel_self_schedule",
175
231
  "Cancel THIS topic's pending self-schedule by its exact schedule_id. A schedule that already started cannot be cancelled with this tool.",
232
+ ),
176
233
  schema: {
177
234
  schedule_id: z.string().min(1).describe("Exact ID of the pending self-schedule."),
178
235
  },
179
236
  async handler({ schedule_id }: { schedule_id: string }) {
180
- return mcpResult(cancelSelfConfigSchedule(getCtx(), schedule_id));
237
+ return mcpResult(core.cancelSchedule(getCtx(), schedule_id));
181
238
  },
182
- },
183
- {
239
+ });
240
+ }
241
+
242
+ if (core.host.derivedTopics) {
243
+ tools.push({
184
244
  name: "spawn_topic",
185
- description:
186
- "Create a new forum topic that inherits all settings from THIS topic but starts with a fresh session. Limited to 5 calls per conversation turn.",
245
+ description: toolDescription(
246
+ core,
247
+ "spawn_topic",
248
+ `Create a new forum topic that inherits all settings from THIS topic but starts with a fresh session. Limited to ${core.product.derivedTopicLimit} calls per conversation turn.`,
249
+ ),
187
250
  schema: {
188
251
  name: z.string().optional().describe("New topic name. Auto-generated if omitted."),
189
252
  },
190
253
  async handler({ name }: { name?: string }) {
191
- if (derivedCount >= SELF_CONFIG_DERIVED_TOPIC_LIMIT) {
254
+ if (derivedCount >= core.product.derivedTopicLimit) {
192
255
  return mcpResult({
193
- text: `Limit reached: only ${SELF_CONFIG_DERIVED_TOPIC_LIMIT} spawn/fork calls per conversation turn.`,
256
+ text: `Limit reached: only ${core.product.derivedTopicLimit} spawn/fork calls per conversation turn.`,
194
257
  isError: true,
195
258
  });
196
259
  }
197
260
  derivedCount++;
198
- return mcpResult(await spawnSelfConfigTopic(getCtx(), name));
261
+ return mcpResult(await core.spawnTopic(getCtx(), name));
199
262
  },
200
- },
201
- {
263
+ });
264
+ tools.push({
202
265
  name: "fork_topic",
203
- description:
204
- "Fork THIS topic by creating a new topic that inherits both settings AND conversation history. Limited to 5 calls per conversation turn.",
266
+ description: toolDescription(
267
+ core,
268
+ "fork_topic",
269
+ `Fork THIS topic by creating a new topic that inherits both settings AND conversation history. Limited to ${core.product.derivedTopicLimit} calls per conversation turn.`,
270
+ ),
205
271
  schema: {
206
272
  name: z.string().optional().describe("New topic name. Auto-generated if omitted."),
207
273
  },
208
274
  async handler({ name }: { name?: string }) {
209
- if (derivedCount >= SELF_CONFIG_DERIVED_TOPIC_LIMIT) {
275
+ if (derivedCount >= core.product.derivedTopicLimit) {
210
276
  return mcpResult({
211
- text: `Limit reached: only ${SELF_CONFIG_DERIVED_TOPIC_LIMIT} spawn/fork calls per conversation turn.`,
277
+ text: `Limit reached: only ${core.product.derivedTopicLimit} spawn/fork calls per conversation turn.`,
212
278
  isError: true,
213
279
  });
214
280
  }
215
281
  derivedCount++;
216
- return mcpResult(await forkSelfConfigTopic(getCtx(), name));
282
+ return mcpResult(await core.forkTopic(getCtx(), name));
217
283
  },
218
- },
219
- ];
284
+ });
285
+ }
286
+
287
+ return tools;
288
+ }
289
+
290
+ export function createSelfConfigToolDefinitions(
291
+ ctx: SelfConfigContext | (() => SelfConfigContext),
292
+ ): SharedMcpTool[] {
293
+ return createSelfConfigToolDefinitionsForCore(defaultSelfConfigCore, ctx);
220
294
  }