@operad-io/bot 0.2.0 → 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.
- package/package.json +6 -5
- package/src/follow-up.ts +313 -0
- package/src/index.ts +99 -28
- package/src/proposals.ts +37 -4
- package/src/schedule.ts +252 -27
- package/src/setup-dev.ts +37 -9
- package/src/setup-git.ts +323 -0
- package/src/tidy.ts +4 -1
package/src/index.ts
CHANGED
|
@@ -14,8 +14,8 @@ import pkg from "../package.json" with { type: "json" };
|
|
|
14
14
|
import { mkdirSync } from "node:fs";
|
|
15
15
|
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
16
16
|
import { fileURLToPath } from "node:url";
|
|
17
|
-
import { CHAT_TYPE, MESSAGE_EVENT, agentConditionals, type AgentChoices, type ScheduledChat, chatData, createChat, sendMessage, startingEffort, startingModel, titleFromMessage } from "@operad-io/chat";
|
|
18
|
-
import { definePlugin, isRecord, modelIds, type ActionArgSchema, type ActionArgsSchema, type ActionTypeDefinition, type HarnessModelInfo, type HarnessModels, type JsonValue, type ObjectRow, type ObjectStore, type ObjectViews, type PluginStepResult, type SectionContent, type StepContext, type StoredObject } from "@operad-io/engine";
|
|
17
|
+
import { CHAT_TYPE, MESSAGE_EVENT, levelRefusal, agentConditionals, type AgentChoices, type ScheduledChat, chatData, createChat, sendMessage, startingEffort, startingModel, titleFromMessage } from "@operad-io/chat";
|
|
18
|
+
import { definePlugin, isRecord, modelIds, type ActionArgSchema, type ActionArgsSchema, type ActionTypeDefinition, type HarnessCapabilities, type HarnessModelInfo, type HarnessModels, type JsonValue, type ObjectRow, type ObjectStore, type ObjectViews, type PluginStepResult, type SectionContent, type StepContext, type StoredObject } from "@operad-io/engine";
|
|
19
19
|
import {
|
|
20
20
|
BOT_SETTINGS,
|
|
21
21
|
DEFAULT_BOT,
|
|
@@ -46,6 +46,7 @@ import {
|
|
|
46
46
|
runSettingCommand,
|
|
47
47
|
runScheduleCommand,
|
|
48
48
|
runSetupDev,
|
|
49
|
+
runSetupGit,
|
|
49
50
|
runSkillCommand,
|
|
50
51
|
} from "./proposals.ts";
|
|
51
52
|
import {
|
|
@@ -53,10 +54,14 @@ import {
|
|
|
53
54
|
scheduleActions,
|
|
54
55
|
scheduledChatContext,
|
|
55
56
|
scheduledData,
|
|
57
|
+
scheduledInstructionFor,
|
|
58
|
+
markdownCode,
|
|
59
|
+
markdownText,
|
|
56
60
|
scheduledMarkdown,
|
|
57
61
|
scheduledPrompts,
|
|
58
62
|
startScheduled,
|
|
59
63
|
} from "./schedule.ts";
|
|
64
|
+
import { followUpActions, followUpData, followUpMarkdown, followUps, runFollowUpCommand, runFollowUpsCommand } from "./follow-up.ts";
|
|
60
65
|
import {
|
|
61
66
|
TIDY_TYPE,
|
|
62
67
|
startTidy,
|
|
@@ -80,6 +85,7 @@ function rowOf(bot: ResolvedBot): Record<string, JsonValue> {
|
|
|
80
85
|
skills: [...bot.skills],
|
|
81
86
|
speaker: bot.speaker,
|
|
82
87
|
writeWiki: bot.writeWiki,
|
|
88
|
+
accessLevel: bot.accessLevel,
|
|
83
89
|
access: bot.access,
|
|
84
90
|
mcpServers: Object.keys(bot.mcpServers),
|
|
85
91
|
};
|
|
@@ -165,6 +171,10 @@ export async function syncBots(
|
|
|
165
171
|
if (Array.isArray(current?.data.scheduled)) {
|
|
166
172
|
data.scheduled = current.data.scheduled as JsonValue[];
|
|
167
173
|
}
|
|
174
|
+
// So are its follow-ups (ADR 0030 D16).
|
|
175
|
+
if (Array.isArray(current?.data.followUps)) {
|
|
176
|
+
data.followUps = current.data.followUps as JsonValue[];
|
|
177
|
+
}
|
|
168
178
|
if (current === undefined || JSON.stringify(current.data) !== JSON.stringify(data)) {
|
|
169
179
|
await store.put(BOT_TYPE, name, data, "bot");
|
|
170
180
|
}
|
|
@@ -187,6 +197,8 @@ export interface OpenChat {
|
|
|
187
197
|
readonly home: string;
|
|
188
198
|
readonly settings: Readonly<Record<string, JsonValue>>;
|
|
189
199
|
readonly harnesses: readonly string[];
|
|
200
|
+
/** What each loaded agent can do; the level a chat starts at must be one its agent carries. */
|
|
201
|
+
readonly capabilities?: Readonly<Record<string, HarnessCapabilities>> | undefined;
|
|
190
202
|
readonly bot: string;
|
|
191
203
|
readonly models?: Readonly<Record<string, HarnessModels>> | undefined;
|
|
192
204
|
readonly efforts?: Readonly<Record<string, { readonly list: readonly string[]; readonly default: string | null }>> | undefined;
|
|
@@ -201,6 +213,19 @@ export interface OpenChat {
|
|
|
201
213
|
readonly cause: string;
|
|
202
214
|
}
|
|
203
215
|
|
|
216
|
+
/**
|
|
217
|
+
* The agent a chat gets when nothing names one: the first loaded agent that can
|
|
218
|
+
* carry the level, else the first loaded one (a refusal then names the levels).
|
|
219
|
+
*/
|
|
220
|
+
export function defaultAgent(
|
|
221
|
+
harnesses: readonly string[],
|
|
222
|
+
capabilities: Readonly<Record<string, HarnessCapabilities>> | undefined,
|
|
223
|
+
level: string,
|
|
224
|
+
): string | undefined {
|
|
225
|
+
if (capabilities === undefined) return harnesses[0];
|
|
226
|
+
return harnesses.find((name) => (capabilities[name]?.accessLevels ?? []).includes(level)) ?? harnesses[0];
|
|
227
|
+
}
|
|
228
|
+
|
|
204
229
|
/** Opens a chat on a bot and returns its id. Refuses with a plain message. */
|
|
205
230
|
export async function openChat(input: OpenChat): Promise<string> {
|
|
206
231
|
const written = readBots(input.home, input.settings);
|
|
@@ -208,7 +233,12 @@ export async function openChat(input: OpenChat): Promise<string> {
|
|
|
208
233
|
const settings = written[input.bot];
|
|
209
234
|
if (settings === undefined) throw new BotError(`there is no bot "${input.bot}"`);
|
|
210
235
|
const bot = resolveBot(input.home, input.bot, settings, await repositoryPaths(input.store));
|
|
211
|
-
|
|
236
|
+
// A scheduled prompt runs at full access (ADR 0030 D10); a chat a person
|
|
237
|
+
// opens starts at the bot's level (ADR 0026 D15). A person may still change
|
|
238
|
+
// the level with `/access` afterwards.
|
|
239
|
+
const startingLevel = input.scheduled === undefined ? bot.accessLevel : "full";
|
|
240
|
+
const harness =
|
|
241
|
+
input.harness ?? bot.harness ?? defaultAgent(input.harnesses, input.capabilities, startingLevel);
|
|
212
242
|
if (harness === undefined) {
|
|
213
243
|
throw new BotError("no agent is loaded; load one to chat with the bot");
|
|
214
244
|
}
|
|
@@ -227,10 +257,9 @@ export async function openChat(input: OpenChat): Promise<string> {
|
|
|
227
257
|
throw new BotError(messageOf(error));
|
|
228
258
|
}
|
|
229
259
|
const effortDefault = input.efforts?.[harness]?.default ?? undefined;
|
|
230
|
-
//
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const startingLevel = input.scheduled === undefined ? bot.accessLevel : "full";
|
|
260
|
+
// An agent that cannot carry the level is refused here, not at the first reply.
|
|
261
|
+
const refusal = levelRefusal(harness, startingLevel, input.capabilities);
|
|
262
|
+
if (refusal !== undefined) throw new BotError(refusal);
|
|
234
263
|
mkdirSync(bot.cwd, { recursive: true });
|
|
235
264
|
ensureBotMemory(bot.cwd, input.home);
|
|
236
265
|
return createChat(
|
|
@@ -263,8 +292,10 @@ function chatArgs(
|
|
|
263
292
|
efforts: readonly string[] = [],
|
|
264
293
|
agents: readonly AgentChoices[] = [],
|
|
265
294
|
info?: Readonly<Record<string, HarnessModelInfo>> | undefined,
|
|
295
|
+
capabilities?: Readonly<Record<string, HarnessCapabilities>> | undefined,
|
|
296
|
+
level = "ask",
|
|
266
297
|
): ActionArgsSchema {
|
|
267
|
-
const first = harnesses
|
|
298
|
+
const first = defaultAgent(harnesses, capabilities, level);
|
|
268
299
|
const fallback = typeof botHarness === "string" && harnesses.includes(botHarness) ? botHarness : first;
|
|
269
300
|
return {
|
|
270
301
|
type: "object",
|
|
@@ -336,10 +367,11 @@ function createArgs(
|
|
|
336
367
|
efforts: readonly string[],
|
|
337
368
|
agents: readonly AgentChoices[],
|
|
338
369
|
info?: Readonly<Record<string, HarnessModelInfo>> | undefined,
|
|
370
|
+
capabilities?: Readonly<Record<string, HarnessCapabilities>> | undefined,
|
|
339
371
|
): ActionArgsSchema {
|
|
340
372
|
const skills = home === undefined ? [] : knownSkills(home);
|
|
341
373
|
const servers = home === undefined ? [] : knownMcpServers(home);
|
|
342
|
-
const first = harnesses
|
|
374
|
+
const first = defaultAgent(harnesses, capabilities, "ask");
|
|
343
375
|
return {
|
|
344
376
|
type: "object",
|
|
345
377
|
description: "Creates a bot with exactly the skills and MCP servers chosen for it.",
|
|
@@ -412,6 +444,7 @@ const createAction: ActionTypeDefinition = {
|
|
|
412
444
|
preferredEffort: null,
|
|
413
445
|
})),
|
|
414
446
|
Object.keys(info).length === 0 ? undefined : info,
|
|
447
|
+
env.capabilities,
|
|
415
448
|
);
|
|
416
449
|
},
|
|
417
450
|
when: (state, env) => state.removed !== true && (env.harnesses ?? []).length > 0,
|
|
@@ -490,6 +523,8 @@ const chatAction: ActionTypeDefinition = {
|
|
|
490
523
|
preferredEffort: typeof object.data.effort === "string" ? object.data.effort : null,
|
|
491
524
|
})),
|
|
492
525
|
Object.keys(info).length === 0 ? undefined : info,
|
|
526
|
+
env.capabilities,
|
|
527
|
+
typeof object.data.accessLevel === "string" ? object.data.accessLevel : "ask",
|
|
493
528
|
);
|
|
494
529
|
},
|
|
495
530
|
when: (state, env) => state.removed !== true && typeof state.problem !== "string" && (env.harnesses ?? []).length > 0,
|
|
@@ -517,6 +552,7 @@ const chatAction: ActionTypeDefinition = {
|
|
|
517
552
|
home: ctx.home,
|
|
518
553
|
settings: ctx.settings,
|
|
519
554
|
harnesses: ctx.harnesses,
|
|
555
|
+
capabilities: ctx.capabilities,
|
|
520
556
|
models: ctx.models,
|
|
521
557
|
efforts: ctx.efforts,
|
|
522
558
|
bot: ctx.object.id,
|
|
@@ -535,14 +571,18 @@ const chatAction: ActionTypeDefinition = {
|
|
|
535
571
|
ctx.actor.via === SCHEDULE_SOURCE ? { ...ctx, source: SCHEDULE_SOURCE } : ctx,
|
|
536
572
|
id,
|
|
537
573
|
input.message,
|
|
574
|
+
undefined,
|
|
575
|
+
[],
|
|
576
|
+
scheduled === undefined ? undefined : scheduledInstructionFor(ctx.object.data, scheduled.entry),
|
|
538
577
|
);
|
|
539
578
|
return { text: `opened chat ${id}${sent === undefined ? "" : `; ${sent}`}`, opens: `chat:${id}` };
|
|
540
579
|
},
|
|
541
580
|
};
|
|
542
581
|
|
|
543
|
-
// Setup Dev (ADR 0030 D15): opens a chat on the bot whose first message
|
|
544
|
-
//
|
|
545
|
-
// agent proposes is a
|
|
582
|
+
// Setup Dev (ADR 0030 D15): opens a chat on the bot whose first message shows
|
|
583
|
+
// the chat's title and carries the prepared prompt for one repository as a
|
|
584
|
+
// hidden instruction. The chat is an ordinary one; what the agent proposes is a
|
|
585
|
+
// pending item.
|
|
546
586
|
const setupDevAction: ActionTypeDefinition = {
|
|
547
587
|
name: "setup-dev",
|
|
548
588
|
on: BOT_TYPE,
|
|
@@ -554,7 +594,7 @@ const setupDevAction: ActionTypeDefinition = {
|
|
|
554
594
|
path: {
|
|
555
595
|
type: "string",
|
|
556
596
|
minLength: 1,
|
|
557
|
-
description: "The directory of the repository:
|
|
597
|
+
description: "The directory of the repository or folder: any folder, with or without git, but not a subfolder of a git repository.",
|
|
558
598
|
},
|
|
559
599
|
},
|
|
560
600
|
required: ["path"],
|
|
@@ -570,24 +610,28 @@ const setupDevAction: ActionTypeDefinition = {
|
|
|
570
610
|
const repo = (args as { readonly path: string }).path.trim();
|
|
571
611
|
if (repo.length === 0) throw new BotError("setup-dev needs the repository's directory");
|
|
572
612
|
const where = isAbsolute(repo) ? repo : resolve(ctx.cwd, repo);
|
|
613
|
+
const title = `Setup Dev (${basename(where)})`;
|
|
573
614
|
const id = await openChat({
|
|
574
615
|
store: ctx.store,
|
|
575
616
|
home: ctx.home,
|
|
576
617
|
settings: ctx.settings,
|
|
577
618
|
harnesses: ctx.harnesses,
|
|
619
|
+
capabilities: ctx.capabilities,
|
|
578
620
|
models: ctx.models,
|
|
579
621
|
efforts: ctx.efforts,
|
|
580
622
|
bot: ctx.object.id,
|
|
581
|
-
title
|
|
623
|
+
title,
|
|
582
624
|
cause: "action:bot/setup-dev",
|
|
583
625
|
});
|
|
584
|
-
|
|
626
|
+
// The person sees the chat's title; the prompt is the agent's hidden instruction.
|
|
627
|
+
const sent = await sendMessage(ctx, id, title, undefined, [], await setupDevPrompt(ctx.setup, ctx.object.id, where));
|
|
585
628
|
return { text: `opened chat ${id}; ${sent}`, opens: `chat:${id}` };
|
|
586
629
|
},
|
|
587
630
|
};
|
|
588
631
|
|
|
589
|
-
// Setup <plugin> (ADR 0010 D7): opens a chat on the bot whose first message
|
|
590
|
-
// the plugin's guide, with what its check finds
|
|
632
|
+
// Setup <plugin> (ADR 0010 D7): opens a chat on the bot whose first message shows
|
|
633
|
+
// the chat's title and carries the plugin's guide, with what its check finds
|
|
634
|
+
// missing, as a hidden instruction.
|
|
591
635
|
const setupAction: ActionTypeDefinition = {
|
|
592
636
|
name: "setup",
|
|
593
637
|
on: BOT_TYPE,
|
|
@@ -612,18 +656,20 @@ const setupAction: ActionTypeDefinition = {
|
|
|
612
656
|
const target = given.target?.trim() ?? "";
|
|
613
657
|
const where = target.length === 0 ? "" : isAbsolute(target) ? target : resolve(ctx.cwd, target);
|
|
614
658
|
const prompt = await setupPrompt(ctx.setup, ctx.object.id, plugin, where);
|
|
659
|
+
const title = `${setupTitle(plugin)}${where.length === 0 ? "" : ` (${basename(where)})`}`;
|
|
615
660
|
const id = await openChat({
|
|
616
661
|
store: ctx.store,
|
|
617
662
|
home: ctx.home,
|
|
618
663
|
settings: ctx.settings,
|
|
619
664
|
harnesses: ctx.harnesses,
|
|
665
|
+
capabilities: ctx.capabilities,
|
|
620
666
|
models: ctx.models,
|
|
621
667
|
efforts: ctx.efforts,
|
|
622
668
|
bot: ctx.object.id,
|
|
623
|
-
title
|
|
669
|
+
title,
|
|
624
670
|
cause: "action:bot/setup",
|
|
625
671
|
});
|
|
626
|
-
const sent = await sendMessage(ctx, id, prompt);
|
|
672
|
+
const sent = await sendMessage(ctx, id, title, undefined, [], prompt);
|
|
627
673
|
return { text: `opened chat ${id}; ${sent}`, opens: `chat:${id}` };
|
|
628
674
|
},
|
|
629
675
|
};
|
|
@@ -675,7 +721,7 @@ export async function runSettings(ctx: StepContext, params: unknown): Promise<Pl
|
|
|
675
721
|
notes: memoryNotes(join(bot.cwd, "memory")) as unknown as JsonValue,
|
|
676
722
|
// The memory plugin records what this reply wrote, once the round ends.
|
|
677
723
|
...(ctx.stepLoaded !== undefined && ctx.stepLoaded(MEMORY_COMMIT_STEP) ? { after: MEMORY_COMMIT_STEP } : {}),
|
|
678
|
-
context: scheduledChatContext(),
|
|
724
|
+
context: scheduledChatContext(stored.id),
|
|
679
725
|
},
|
|
680
726
|
};
|
|
681
727
|
} catch (error) {
|
|
@@ -686,26 +732,32 @@ export async function runSettings(ctx: StepContext, params: unknown): Promise<Pl
|
|
|
686
732
|
function botMarkdown(object: StoredObject): string {
|
|
687
733
|
const data = object.data;
|
|
688
734
|
const lines = [`**${object.id}**`];
|
|
689
|
-
if (typeof data.problem === "string") lines.push(`Cannot be used: ${data.problem}`);
|
|
690
|
-
if (typeof data.cwd === "string") lines.push(`Working directory: ${data.cwd}`);
|
|
691
|
-
if (typeof data.harness === "string") lines.push(`Default agent: ${data.harness}`);
|
|
692
|
-
if (typeof data.speaker === "string") lines.push(`Speaker: ${data.speaker}`);
|
|
735
|
+
if (typeof data.problem === "string") lines.push(`Cannot be used: ${markdownText(data.problem)}`);
|
|
736
|
+
if (typeof data.cwd === "string") lines.push(`Working directory: ${markdownCode(data.cwd)}`);
|
|
737
|
+
if (typeof data.harness === "string") lines.push(`Default agent: ${markdownText(data.harness)}`);
|
|
738
|
+
if (typeof data.speaker === "string") lines.push(`Speaker: ${markdownText(data.speaker)}`);
|
|
693
739
|
const skills = Array.isArray(data.skills)
|
|
694
740
|
? data.skills.filter((path): path is string => typeof path === "string")
|
|
695
741
|
: [];
|
|
696
|
-
lines.push(skills.length === 0 ? "No skills." : `Skills: ${skills.map(skillName).join(", ")}`);
|
|
742
|
+
lines.push(skills.length === 0 ? "No skills." : `Skills: ${skills.map((path) => markdownText(skillName(path))).join(", ")}`);
|
|
697
743
|
lines.push(data.writeWiki === true ? "Wiki: read and write." : "Wiki: read only.");
|
|
698
744
|
const servers = Array.isArray(data.mcpServers) ? data.mcpServers : [];
|
|
699
745
|
if (servers.length > 0) {
|
|
700
746
|
lines.push(
|
|
701
|
-
`MCP servers: ${servers.join(", ")}`,
|
|
747
|
+
`MCP servers: ${servers.map((name) => markdownText(String(name))).join(", ")}`,
|
|
702
748
|
`They are mounted in chats on ${MCP_HARNESSES.join(" and ")}. A chat on pi does not mount them: pi takes no MCP servers yet, so it cannot use ${servers.join(", ")}.`,
|
|
703
749
|
);
|
|
704
750
|
}
|
|
705
751
|
lines.push(scheduledMarkdown(scheduledPrompts(data), Date.now()).join("\n"));
|
|
752
|
+
lines.push(followUpMarkdown(followUps(data)).join("\n"));
|
|
706
753
|
return lines.join("\n\n");
|
|
707
754
|
}
|
|
708
755
|
|
|
756
|
+
/** The server's IANA time zone, the one cron expressions run in; read at each call so `TZ` can be set. */
|
|
757
|
+
export function serverTimeZone(): string {
|
|
758
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
759
|
+
}
|
|
760
|
+
|
|
709
761
|
/** How a bot shows in a list and on its page. */
|
|
710
762
|
export const botViews: ObjectViews = {
|
|
711
763
|
row: (object): ObjectRow => ({
|
|
@@ -714,6 +766,8 @@ export const botViews: ObjectViews = {
|
|
|
714
766
|
state: object.data.removed === true ? "removed" : "open",
|
|
715
767
|
data: {
|
|
716
768
|
scheduled: scheduledData(scheduledPrompts(object.data), Date.now()) as unknown as JsonValue,
|
|
769
|
+
timeZone: serverTimeZone(),
|
|
770
|
+
followUps: followUpData(followUps(object.data)) as unknown as JsonValue,
|
|
717
771
|
},
|
|
718
772
|
}),
|
|
719
773
|
sections: () => [{ id: "bot", title: "Bot" }],
|
|
@@ -728,7 +782,7 @@ export function createBotPlugin() {
|
|
|
728
782
|
// The version comes from package.json so the two cannot drift apart.
|
|
729
783
|
version: pkg.version,
|
|
730
784
|
// Patch releases of chat only: a new minor may change what bot relies on.
|
|
731
|
-
requires: { plugins: { chat: "~0.
|
|
785
|
+
requires: { plugins: { chat: "~0.3.0" } },
|
|
732
786
|
settings: BOT_SETTINGS,
|
|
733
787
|
// A bot page is that bot's settings page; bots live under settings, not in a tab.
|
|
734
788
|
objectsUnderSettings: true,
|
|
@@ -777,7 +831,7 @@ export function createBotPlugin() {
|
|
|
777
831
|
mode: "auto" as const,
|
|
778
832
|
},
|
|
779
833
|
],
|
|
780
|
-
actions: [chatAction, setupDevAction, setupAction, chatSetupAction, createAction, loginAction, ...proposalActions, ...scheduleActions, ...tidyActions],
|
|
834
|
+
actions: [chatAction, setupDevAction, setupAction, chatSetupAction, createAction, loginAction, ...proposalActions, ...scheduleActions, ...followUpActions, ...tidyActions],
|
|
781
835
|
commands: [
|
|
782
836
|
{
|
|
783
837
|
name: "skill",
|
|
@@ -799,6 +853,11 @@ export function createBotPlugin() {
|
|
|
799
853
|
args: "<bot> <repository directory> [< dev.json]",
|
|
800
854
|
run: runSetupDev,
|
|
801
855
|
},
|
|
856
|
+
{
|
|
857
|
+
name: "setup-git",
|
|
858
|
+
args: "<bot> <folder> [< {gitignore, identity}]",
|
|
859
|
+
run: runSetupGit,
|
|
860
|
+
},
|
|
802
861
|
{
|
|
803
862
|
name: "setup",
|
|
804
863
|
args: "<bot> <plugin> [target]",
|
|
@@ -809,6 +868,16 @@ export function createBotPlugin() {
|
|
|
809
868
|
args: "<bot> add|edit|remove <name> [--words <text>] [--schedule <cron>] [--prompt <text>] [--model <model>] [--effort <effort>]",
|
|
810
869
|
run: runScheduleCommand,
|
|
811
870
|
},
|
|
871
|
+
{
|
|
872
|
+
name: "follow-up",
|
|
873
|
+
args: "<chat> --at <time> --do <one sentence>",
|
|
874
|
+
run: runFollowUpCommand,
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
name: "follow-ups",
|
|
878
|
+
args: "<chat> [--cancel <id>]",
|
|
879
|
+
run: runFollowUpsCommand,
|
|
880
|
+
},
|
|
812
881
|
],
|
|
813
882
|
// A proposal waits for no run; each one is a pending item of its bot.
|
|
814
883
|
standing: async (ctx) => {
|
|
@@ -841,8 +910,10 @@ export * from "./create.ts";
|
|
|
841
910
|
export * from "./login.ts";
|
|
842
911
|
export * from "./proposals.ts";
|
|
843
912
|
export * from "./setup-dev.ts";
|
|
913
|
+
export * from "./setup-git.ts";
|
|
844
914
|
export * from "./setup.ts";
|
|
845
915
|
export * from "./schedule.ts";
|
|
916
|
+
export * from "./follow-up.ts";
|
|
846
917
|
export * from "./tidy.ts";
|
|
847
918
|
export * from "./mcp.ts";
|
|
848
919
|
export * from "./mcp-proposals.ts";
|
package/src/proposals.ts
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
type McpServerSettings,
|
|
45
45
|
} from "./bot.ts";
|
|
46
46
|
import { applyDev, devChangeOf, devReview, runSetupDevCommand, type DevChange, type PipedInput } from "./setup-dev.ts";
|
|
47
|
+
import { applyGit, gitChangeOf, gitPrompt, gitReview, runSetupGitCommand, SETUP_GIT_TITLE, type GitChange } from "./setup-git.ts";
|
|
47
48
|
import { commandLine, compareTools, differenceLines, secretName, storedTools } from "./mcp.ts";
|
|
48
49
|
import {
|
|
49
50
|
applyScheduleChange,
|
|
@@ -88,7 +89,7 @@ export interface SettingsChange {
|
|
|
88
89
|
export interface ProposalData {
|
|
89
90
|
readonly [key: string]: unknown;
|
|
90
91
|
readonly bot: string;
|
|
91
|
-
readonly kind: "skill" | "settings" | "mcp" | "schedule" | "dev";
|
|
92
|
+
readonly kind: "skill" | "settings" | "mcp" | "schedule" | "dev" | "git";
|
|
92
93
|
readonly title: string;
|
|
93
94
|
readonly state: ProposalState;
|
|
94
95
|
readonly createdAt: number;
|
|
@@ -101,6 +102,7 @@ export interface ProposalData {
|
|
|
101
102
|
readonly mcp?: McpChange | undefined;
|
|
102
103
|
readonly schedule?: ScheduleChange | undefined;
|
|
103
104
|
readonly dev?: DevChange | undefined;
|
|
105
|
+
readonly git?: GitChange | undefined;
|
|
104
106
|
}
|
|
105
107
|
|
|
106
108
|
/** A local MCP server a proposal registers, upgrades or lets through after a change of its tools. */
|
|
@@ -122,7 +124,8 @@ function dataOf(object: StoredObject): ProposalData {
|
|
|
122
124
|
data.kind !== "settings" &&
|
|
123
125
|
data.kind !== "mcp" &&
|
|
124
126
|
data.kind !== "schedule" &&
|
|
125
|
-
data.kind !== "dev"
|
|
127
|
+
data.kind !== "dev" &&
|
|
128
|
+
data.kind !== "git") ||
|
|
126
129
|
typeof data.title !== "string" ||
|
|
127
130
|
(data.state !== "pending" && data.state !== "applied" && data.state !== "rejected") ||
|
|
128
131
|
typeof data.createdAt !== "number"
|
|
@@ -546,6 +549,10 @@ export function proposalReview(object: StoredObject): string {
|
|
|
546
549
|
const change = devChangeOf(data.dev);
|
|
547
550
|
return change === undefined ? "No repository is recorded for this proposal." : devReview(data.bot, change);
|
|
548
551
|
}
|
|
552
|
+
if (data.kind === "git") {
|
|
553
|
+
const change = gitChangeOf(data.git);
|
|
554
|
+
return change === undefined ? "No folder is recorded for this proposal." : gitReview(data.bot, change);
|
|
555
|
+
}
|
|
549
556
|
if (data.kind === "schedule") {
|
|
550
557
|
const change = scheduleChangeOf(data.schedule);
|
|
551
558
|
return change === undefined
|
|
@@ -927,6 +934,10 @@ export async function applyProposal(
|
|
|
927
934
|
const change = devChangeOf(data.dev);
|
|
928
935
|
if (change === undefined) throw new BotError(`proposal ${id} has no repository to set up`);
|
|
929
936
|
await applyDev(home, change);
|
|
937
|
+
} else if (data.kind === "git") {
|
|
938
|
+
const change = gitChangeOf(data.git);
|
|
939
|
+
if (change === undefined) throw new BotError(`proposal ${id} has no folder to set up git in`);
|
|
940
|
+
applyGit(home, change);
|
|
930
941
|
} else if (data.kind === "schedule") {
|
|
931
942
|
const change = scheduleChangeOf(data.schedule);
|
|
932
943
|
if (change === undefined) throw new BotError(`proposal ${id} has no scheduled prompt to apply`);
|
|
@@ -1004,7 +1015,7 @@ export async function proposalItems(
|
|
|
1004
1015
|
const data = dataOf(object);
|
|
1005
1016
|
return {
|
|
1006
1017
|
id: object.id,
|
|
1007
|
-
prompt: `${data.title} for bot ${data.bot} is waiting for your review`,
|
|
1018
|
+
prompt: data.kind === "git" ? gitPrompt(data.bot, gitChangeOf(data.git)) : data.kind === "dev" ? `${data.title} (proposed by bot ${data.bot}) is waiting for your review` : `${data.title} for bot ${data.bot} is waiting for your review`,
|
|
1008
1019
|
object: { type: PROPOSAL_TYPE, id: object.id },
|
|
1009
1020
|
};
|
|
1010
1021
|
});
|
|
@@ -1061,7 +1072,7 @@ export async function runSetupDev(ctx: CommandContext, argv: readonly string[],
|
|
|
1061
1072
|
const data: ProposalData = {
|
|
1062
1073
|
bot,
|
|
1063
1074
|
kind: "dev",
|
|
1064
|
-
title: `Setup Dev
|
|
1075
|
+
title: `Setup Dev: ${basename(change.repo)}`,
|
|
1065
1076
|
state: "pending",
|
|
1066
1077
|
createdAt: Date.now(),
|
|
1067
1078
|
dev: change,
|
|
@@ -1072,6 +1083,28 @@ export async function runSetupDev(ctx: CommandContext, argv: readonly string[],
|
|
|
1072
1083
|
}, piped);
|
|
1073
1084
|
}
|
|
1074
1085
|
|
|
1086
|
+
/** The `bot setup-git` command: the steps for the agent, or with the `.gitignore` and identity on stdin the "Set up git here" proposal (ADR 0039 D8). */
|
|
1087
|
+
export async function runSetupGit(ctx: CommandContext, argv: readonly string[], piped?: PipedInput): Promise<string> {
|
|
1088
|
+
return runSetupGitCommand(
|
|
1089
|
+
ctx,
|
|
1090
|
+
argv,
|
|
1091
|
+
async (bot, change) => {
|
|
1092
|
+
const data: ProposalData = {
|
|
1093
|
+
bot,
|
|
1094
|
+
kind: "git",
|
|
1095
|
+
title: SETUP_GIT_TITLE,
|
|
1096
|
+
state: "pending",
|
|
1097
|
+
createdAt: Date.now(),
|
|
1098
|
+
git: change,
|
|
1099
|
+
};
|
|
1100
|
+
const id = `p-${randomUUID()}`;
|
|
1101
|
+
await ctx.store.put(PROPOSAL_TYPE, id, data as unknown as Record<string, JsonValue>, "command:bot/setup-git");
|
|
1102
|
+
return `proposed ${SETUP_GIT_TITLE} for ${change.repo}; review it in pending`;
|
|
1103
|
+
},
|
|
1104
|
+
piped,
|
|
1105
|
+
);
|
|
1106
|
+
}
|
|
1107
|
+
|
|
1075
1108
|
/** The usage line shared by the parser's refusals. */
|
|
1076
1109
|
const SCHEDULE_USAGE =
|
|
1077
1110
|
"usage: operad bot schedule <bot> add|edit|remove <name> [--words <text>] [--schedule <cron>] [--prompt <text>] [--model <model>] [--effort <effort>]";
|