heyio 0.5.0 → 0.8.0
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/dist/api/server.js +121 -2
- package/dist/config.js +3 -0
- package/dist/copilot/agents.js +172 -12
- package/dist/copilot/io-scheduler.js +26 -3
- package/dist/copilot/orchestrator.js +30 -3
- package/dist/copilot/scheduler.js +24 -2
- package/dist/copilot/session-timeout.js +112 -0
- package/dist/copilot/session-timeout.test.js +372 -0
- package/dist/copilot/skills.js +78 -4
- package/dist/copilot/system-message.js +12 -8
- package/dist/copilot/tools.js +316 -20
- package/dist/daemon.js +35 -2
- package/dist/notify.js +105 -0
- package/dist/notify.test.js +232 -0
- package/dist/store/db.js +47 -2
- package/dist/store/notifications.js +79 -0
- package/dist/store/notifications.test.js +197 -0
- package/dist/store/schedule-runs.js +46 -0
- package/dist/store/squads.js +10 -0
- package/dist/store/tasks.js +122 -0
- package/dist/telegram/bot.js +14 -0
- package/dist/tui/index.js +73 -0
- package/package.json +3 -2
- package/web-dist/assets/index-CUwy4ylb.js +74 -0
- package/web-dist/assets/index-oSVFpNBp.css +1 -0
- package/web-dist/index.html +2 -2
- package/web-dist/assets/index-BYoiwmlj.js +0 -74
- package/web-dist/assets/index-DMKRXYjX.css +0 -1
package/dist/api/server.js
CHANGED
|
@@ -3,7 +3,7 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import express from "express";
|
|
5
5
|
import { config } from "../config.js";
|
|
6
|
-
import { listSkills } from "../copilot/skills.js";
|
|
6
|
+
import { listSkills, installSkill } from "../copilot/skills.js";
|
|
7
7
|
import { listSquads, createSquad, listSquadAgents } from "../store/squads.js";
|
|
8
8
|
import { getAgentInfo, cancelAgentTask, getTaskEvents, subscribeToTaskEvents } from "../copilot/agents.js";
|
|
9
9
|
import { summarize, summarizeEvent } from "../copilot/event-summary.js";
|
|
@@ -15,6 +15,7 @@ import { listSchedules, getSchedule, deleteSchedule, setScheduleEnabled } from "
|
|
|
15
15
|
import { listIoSchedules, getIoSchedule, deleteIoSchedule, setIoScheduleEnabled } from "../store/io-schedules.js";
|
|
16
16
|
import { runScheduleNow } from "../copilot/scheduler.js";
|
|
17
17
|
import { runIoScheduleNow } from "../copilot/io-scheduler.js";
|
|
18
|
+
import { listRecentNotifications, listUnreadNotifications, countUnreadNotifications, markNotificationRead, markAllNotificationsRead, } from "../store/notifications.js";
|
|
18
19
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
20
|
const WEB_DIST = path.resolve(__dirname, "../../web-dist");
|
|
20
21
|
let messageHandler;
|
|
@@ -28,6 +29,12 @@ export function broadcastToSSE(text) {
|
|
|
28
29
|
res.write(`data: ${payload}\n\n`);
|
|
29
30
|
}
|
|
30
31
|
}
|
|
32
|
+
export function broadcastNotificationToSSE(payload) {
|
|
33
|
+
const data = JSON.stringify({ type: "notification", ...payload });
|
|
34
|
+
for (const res of sseConnections) {
|
|
35
|
+
res.write(`data: ${data}\n\n`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
31
38
|
export async function startApiServer() {
|
|
32
39
|
const app = express();
|
|
33
40
|
app.use(express.json());
|
|
@@ -67,6 +74,36 @@ export async function startApiServer() {
|
|
|
67
74
|
res.status(500).json({ error: "Failed to list skills" });
|
|
68
75
|
}
|
|
69
76
|
});
|
|
77
|
+
// Install a skill from a git repo URL (mirrors the skill_install tool)
|
|
78
|
+
api.post("/skills", async (req, res) => {
|
|
79
|
+
const { repoUrl } = req.body;
|
|
80
|
+
if (repoUrl === undefined || repoUrl === null || typeof repoUrl !== "string") {
|
|
81
|
+
res.status(400).json({ error: "Missing required field: repoUrl" });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (repoUrl.trim() === "") {
|
|
85
|
+
res.status(400).json({ error: "repoUrl must not be empty" });
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const trimmed = repoUrl.trim();
|
|
89
|
+
const looksLikeGitUrl = trimmed.startsWith("http://") ||
|
|
90
|
+
trimmed.startsWith("https://") ||
|
|
91
|
+
trimmed.startsWith("git@") ||
|
|
92
|
+
trimmed.startsWith("git://") ||
|
|
93
|
+
trimmed.endsWith(".git");
|
|
94
|
+
if (!looksLikeGitUrl) {
|
|
95
|
+
res.status(400).json({ error: "repoUrl does not look like a git repository URL" });
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const skill = await installSkill(trimmed);
|
|
100
|
+
res.status(201).json({ skill });
|
|
101
|
+
}
|
|
102
|
+
catch (e) {
|
|
103
|
+
console.error("Error installing skill:", e);
|
|
104
|
+
res.status(500).json({ error: e instanceof Error ? e.message : String(e) });
|
|
105
|
+
}
|
|
106
|
+
});
|
|
70
107
|
// Squads endpoints
|
|
71
108
|
api.get("/squads", (_req, res) => {
|
|
72
109
|
try {
|
|
@@ -162,7 +199,26 @@ export async function startApiServer() {
|
|
|
162
199
|
const taskId = Array.isArray(req.params.taskId) ? req.params.taskId[0] : req.params.taskId;
|
|
163
200
|
try {
|
|
164
201
|
const events = getTaskEvents(taskId);
|
|
165
|
-
|
|
202
|
+
let activity = summarize(events);
|
|
203
|
+
// Fallback: when in-memory events are gone (e.g. daemon restart),
|
|
204
|
+
// build a minimal entry from the persisted task result so the UI
|
|
205
|
+
// doesn't show "no activity" for tasks that actually ran. (#66)
|
|
206
|
+
if (activity.length === 0) {
|
|
207
|
+
const task = getTask(taskId);
|
|
208
|
+
if (task?.result) {
|
|
209
|
+
activity = [{
|
|
210
|
+
ts: task.completed_at ? new Date(task.completed_at).getTime() : Date.now(),
|
|
211
|
+
kind: "outcome",
|
|
212
|
+
icon: task.status === "failed" ? "\u274c" : task.status === "done" ? "\u2705" : "\ud83d\udccb",
|
|
213
|
+
summary: task.status === "failed"
|
|
214
|
+
? "Task failed (activity log unavailable after restart)"
|
|
215
|
+
: "Task completed (activity log unavailable after restart)",
|
|
216
|
+
rawType: "task.result.fallback",
|
|
217
|
+
detail: task.result,
|
|
218
|
+
raw: { result: task.result, status: task.status },
|
|
219
|
+
}];
|
|
220
|
+
}
|
|
221
|
+
}
|
|
166
222
|
res.json({ taskId, activity });
|
|
167
223
|
}
|
|
168
224
|
catch (e) {
|
|
@@ -396,6 +452,69 @@ export async function startApiServer() {
|
|
|
396
452
|
res.status(500).json({ error: (e instanceof Error ? e.message : String(e)) });
|
|
397
453
|
}
|
|
398
454
|
});
|
|
455
|
+
// Notifications endpoints
|
|
456
|
+
api.get("/notifications", (_req, res) => {
|
|
457
|
+
try {
|
|
458
|
+
const unreadOnly = _req.query.unread === "true";
|
|
459
|
+
const rows = unreadOnly
|
|
460
|
+
? listUnreadNotifications()
|
|
461
|
+
: (() => {
|
|
462
|
+
const rawLimit = _req.query.limit;
|
|
463
|
+
const parsed = typeof rawLimit === "string" ? Number.parseInt(rawLimit, 10) : NaN;
|
|
464
|
+
const limit = Number.isFinite(parsed) && parsed > 0 ? Math.min(parsed, 200) : 50;
|
|
465
|
+
return listRecentNotifications(limit);
|
|
466
|
+
})();
|
|
467
|
+
const unreadCount = countUnreadNotifications();
|
|
468
|
+
const notifications = rows.map(({ id, title, text, created_at, read_at, source_type, source_ref }) => {
|
|
469
|
+
let source = { type: source_type };
|
|
470
|
+
if (source_ref) {
|
|
471
|
+
try {
|
|
472
|
+
const parsed = JSON.parse(source_ref);
|
|
473
|
+
source = { type: source_type, ...parsed };
|
|
474
|
+
}
|
|
475
|
+
catch {
|
|
476
|
+
// source_ref is not valid JSON — fall back to type-only
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
return { id, title, text, created_at, read_at, source };
|
|
480
|
+
});
|
|
481
|
+
res.json({ notifications, unreadCount });
|
|
482
|
+
}
|
|
483
|
+
catch (e) {
|
|
484
|
+
console.error("Error listing notifications:", e);
|
|
485
|
+
res.status(500).json({ error: "Failed to list notifications" });
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
api.post("/notifications/read-all", (_req, res) => {
|
|
489
|
+
try {
|
|
490
|
+
const marked = markAllNotificationsRead();
|
|
491
|
+
res.json({ marked });
|
|
492
|
+
}
|
|
493
|
+
catch (e) {
|
|
494
|
+
console.error("Error marking all notifications read:", e);
|
|
495
|
+
res.status(500).json({ error: "Failed to mark notifications read" });
|
|
496
|
+
}
|
|
497
|
+
});
|
|
498
|
+
api.post("/notifications/:id/read", (req, res) => {
|
|
499
|
+
try {
|
|
500
|
+
const rawId = Array.isArray(req.params.id) ? req.params.id[0] : req.params.id;
|
|
501
|
+
const id = Number.parseInt(rawId, 10);
|
|
502
|
+
if (Number.isNaN(id)) {
|
|
503
|
+
res.status(400).json({ error: "invalid id" });
|
|
504
|
+
return;
|
|
505
|
+
}
|
|
506
|
+
const found = markNotificationRead(id);
|
|
507
|
+
if (!found) {
|
|
508
|
+
res.status(404).json({ error: "notification not found" });
|
|
509
|
+
return;
|
|
510
|
+
}
|
|
511
|
+
res.json({ ok: true });
|
|
512
|
+
}
|
|
513
|
+
catch (e) {
|
|
514
|
+
console.error("Error marking notification read:", e);
|
|
515
|
+
res.status(500).json({ error: "Failed to mark notification read" });
|
|
516
|
+
}
|
|
517
|
+
});
|
|
399
518
|
// Chat endpoints
|
|
400
519
|
api.post("/message", async (req, res) => {
|
|
401
520
|
const { text } = req.body;
|
package/dist/config.js
CHANGED
|
@@ -4,6 +4,9 @@ const DEFAULT_CONFIG = {
|
|
|
4
4
|
telegramEnabled: false,
|
|
5
5
|
selfEditEnabled: false,
|
|
6
6
|
port: 3170,
|
|
7
|
+
backgroundNotifyMode: "meaningful",
|
|
8
|
+
backgroundNotifyTelegram: true,
|
|
9
|
+
backgroundNotifyTui: true,
|
|
7
10
|
};
|
|
8
11
|
function loadConfig() {
|
|
9
12
|
mkdirSync(IO_HOME, { recursive: true });
|
package/dist/copilot/agents.js
CHANGED
|
@@ -7,8 +7,9 @@ import { homedir } from "os";
|
|
|
7
7
|
import { defineTool, approveAll } from "@github/copilot-sdk";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
import { getClient } from "./client.js";
|
|
10
|
+
import { sendWithIdleTimeout } from "./session-timeout.js";
|
|
10
11
|
import { getModelForTask, getModelForTier, classifyComplexity } from "./model-router.js";
|
|
11
|
-
import { getSquad, updateSquadSession, updateSquadStatus, getDecisionsSummary, logDecision, listSquadAgents, getSquadAgent, getSquadLead, updateAgentSession, updateAgentStatus, } from "../store/squads.js";
|
|
12
|
+
import { getSquad, updateSquadSession, updateSquadStatus, getDecisions, getDecisionsSummary, logDecision, listSquadAgents, getSquadAgent, getSquadLead, updateAgentSession, updateAgentStatus, } from "../store/squads.js";
|
|
12
13
|
import { createTask, completeTask, createReview, failTask, getActiveTasks, getTask, cancelTask, } from "../store/tasks.js";
|
|
13
14
|
import { SESSIONS_DIR } from "../paths.js";
|
|
14
15
|
import { getUniverse } from "./universes.js";
|
|
@@ -18,6 +19,16 @@ const agentSessionModels = new Map();
|
|
|
18
19
|
function agentSessionKey(squadSlug, characterName) {
|
|
19
20
|
return characterName ? `${squadSlug}:${characterName}` : squadSlug;
|
|
20
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Drop the in-memory cached Copilot session (and model) for an agent so the
|
|
24
|
+
* next task creates a fresh one. Pairs with `clearAgentSession` in the
|
|
25
|
+
* store, which nulls the persisted copilot_session_id.
|
|
26
|
+
*/
|
|
27
|
+
export function clearAgentInMemorySession(squadSlug, characterName) {
|
|
28
|
+
const key = agentSessionKey(squadSlug, characterName);
|
|
29
|
+
agentSessions.delete(key);
|
|
30
|
+
agentSessionModels.delete(key);
|
|
31
|
+
}
|
|
21
32
|
export function getAgentInfo() {
|
|
22
33
|
const activeTasks = getActiveTasks();
|
|
23
34
|
const tasksByAgent = new Map();
|
|
@@ -104,6 +115,49 @@ export function subscribeToTaskEvents(taskId, listener) {
|
|
|
104
115
|
taskEventEmitter.on(taskId, listener);
|
|
105
116
|
return () => taskEventEmitter.off(taskId, listener);
|
|
106
117
|
}
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
// Task prompt envelope (issue #54)
|
|
120
|
+
//
|
|
121
|
+
// Before sending a task to an agent we prepend a short "Recent squad
|
|
122
|
+
// decisions" preamble and append a tail that asks the agent to call
|
|
123
|
+
// squad_log_decision if their work involved a non-trivial architectural
|
|
124
|
+
// choice. This is the lowest-friction nudge we can give: agents see what
|
|
125
|
+
// they're augmenting AND a reminder to capture institutional knowledge.
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
const RECENT_DECISIONS_LIMIT = 5;
|
|
128
|
+
function buildTaskPromptEnvelope(squadSlug, task) {
|
|
129
|
+
const recent = getDecisions(squadSlug, RECENT_DECISIONS_LIMIT);
|
|
130
|
+
const preamble = recent.length === 0
|
|
131
|
+
? `## Recent squad decisions
|
|
132
|
+
_(None recorded yet — be the first to log one with \`squad_log_decision\` if your work involves a real architectural choice.)_`
|
|
133
|
+
: `## Recent squad decisions (last ${recent.length})
|
|
134
|
+
You should treat these as load-bearing context. Reverse them only with a clear reason and a new \`squad_log_decision\` entry.
|
|
135
|
+
|
|
136
|
+
${recent
|
|
137
|
+
.slice()
|
|
138
|
+
.reverse()
|
|
139
|
+
.map((d) => {
|
|
140
|
+
const ctx = d.context ? ` — _${d.context}_` : "";
|
|
141
|
+
return `- [${d.created_at}] **${d.decision}**${ctx}`;
|
|
142
|
+
})
|
|
143
|
+
.join("\n")}`;
|
|
144
|
+
const tail = `## Capturing institutional knowledge
|
|
145
|
+
When you finish this task, if your work involved a non-trivial architectural choice (a strategy, a tradeoff, an interface decision, a workaround with a clear reason), call \`squad_log_decision\` with **one sentence** summarizing the choice and **a short context** explaining why. Examples:
|
|
146
|
+
- decision: "Use idle-reset timeout instead of wall-clock for agent tasks" / context: "Wall-clock killed 2/3 long-running tasks mid-progress (#42, #45)."
|
|
147
|
+
- decision: "Veto power expanded to lead + QA + test engineers" / context: "Single-reviewer veto was too narrow when test engineer wasn't designated QA."
|
|
148
|
+
|
|
149
|
+
If your work was a routine implementation that didn't make a real choice (e.g. small docs edit, mechanical refactor, one-line fix), skip the call — don't log noise.`;
|
|
150
|
+
return `${preamble}
|
|
151
|
+
|
|
152
|
+
---
|
|
153
|
+
|
|
154
|
+
## Task
|
|
155
|
+
${task}
|
|
156
|
+
|
|
157
|
+
---
|
|
158
|
+
|
|
159
|
+
${tail}`;
|
|
160
|
+
}
|
|
107
161
|
export async function delegateToAgent(squadSlug, task, onComplete, targetAgent) {
|
|
108
162
|
const squad = getSquad(squadSlug);
|
|
109
163
|
if (!squad) {
|
|
@@ -131,13 +185,26 @@ export async function delegateToAgent(squadSlug, task, onComplete, targetAgent)
|
|
|
131
185
|
}
|
|
132
186
|
}
|
|
133
187
|
}
|
|
188
|
+
const agentKey = agent
|
|
189
|
+
? agentSessionKey(squadSlug, agent.character_name)
|
|
190
|
+
: squadSlug;
|
|
191
|
+
// Idempotency: if an identical task is already running on this agent_slug,
|
|
192
|
+
// join the existing task instead of racing a second instance. (Issue #53)
|
|
193
|
+
const normalizedTask = task.trim();
|
|
194
|
+
const duplicate = getActiveTasks().find((t) => t.agent_slug === agentKey && t.description.trim() === normalizedTask);
|
|
195
|
+
if (duplicate) {
|
|
196
|
+
console.error(`[io] Dedup: task with identical description already running on ${agentKey} (taskId=${duplicate.task_id}); returning existing taskId.`);
|
|
197
|
+
recordTaskEvent(duplicate.task_id, {
|
|
198
|
+
ts: Date.now(),
|
|
199
|
+
type: "task.dedup_joined",
|
|
200
|
+
data: { agentKey, description: normalizedTask },
|
|
201
|
+
});
|
|
202
|
+
return duplicate.task_id;
|
|
203
|
+
}
|
|
134
204
|
const session = agent
|
|
135
205
|
? await getOrCreateAgentSession(squadSlug, agent, task)
|
|
136
206
|
: await getOrCreateSession(squadSlug, task);
|
|
137
207
|
const taskId = randomUUID();
|
|
138
|
-
const agentKey = agent
|
|
139
|
-
? agentSessionKey(squadSlug, agent.character_name)
|
|
140
|
-
: squadSlug;
|
|
141
208
|
createTask(taskId, agentKey, task);
|
|
142
209
|
updateSquadStatus(squadSlug, "working");
|
|
143
210
|
if (agent)
|
|
@@ -161,8 +228,40 @@ export async function delegateToAgent(squadSlug, task, onComplete, targetAgent)
|
|
|
161
228
|
// Run the task in the background — return taskId immediately
|
|
162
229
|
void (async () => {
|
|
163
230
|
try {
|
|
164
|
-
const
|
|
165
|
-
const
|
|
231
|
+
const envelopedTask = buildTaskPromptEnvelope(squadSlug, task);
|
|
232
|
+
const sendResult = await sendWithIdleTimeout(session, envelopedTask, {
|
|
233
|
+
// Reset on every progress event; only abort if the agent goes
|
|
234
|
+
// genuinely silent for this long. 10 minutes covers the longest
|
|
235
|
+
// realistic tool call (npm install, full build, large file edits)
|
|
236
|
+
// while still catching truly stuck sessions. (Issue #53)
|
|
237
|
+
idleMs: 10 * 60_000,
|
|
238
|
+
// Absolute upper bound — 60 minutes. Anything longer is almost
|
|
239
|
+
// certainly a runaway loop; cap it.
|
|
240
|
+
hardCapMs: 60 * 60_000,
|
|
241
|
+
onIdleTimeout: ({ lastEventType, idleMs }) => {
|
|
242
|
+
console.error(`[io] Agent task ${taskId} idle for ${Math.round(idleMs / 1000)}s (last event: ${lastEventType ?? "none"}) — aborting session.`);
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
if (sendResult.timedOut) {
|
|
246
|
+
const partial = sendResult.content;
|
|
247
|
+
recordTaskEvent(taskId, {
|
|
248
|
+
ts: Date.now(),
|
|
249
|
+
type: "task.timeout",
|
|
250
|
+
data: {
|
|
251
|
+
reason: sendResult.timeoutReason,
|
|
252
|
+
lastEventType: sendResult.lastEventType,
|
|
253
|
+
partial,
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
const stamped = `[task timed out — ${sendResult.timeoutReason === "idle" ? "idle reset" : "hard cap"}; last event: ${sendResult.lastEventType ?? "none"}]\n\n${partial}`;
|
|
257
|
+
failTask(taskId, stamped);
|
|
258
|
+
updateSquadStatus(squadSlug, "idle");
|
|
259
|
+
if (agent)
|
|
260
|
+
updateAgentStatus(squadSlug, agent.character_name, "idle");
|
|
261
|
+
onComplete(taskId, stamped);
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
const result = sendResult.content || "Task completed (no output)";
|
|
166
265
|
completeTask(taskId, result);
|
|
167
266
|
updateSquadStatus(squadSlug, "idle");
|
|
168
267
|
if (agent)
|
|
@@ -300,10 +399,26 @@ async function getOrCreateAgentSession(squadSlug, agent, taskDescription) {
|
|
|
300
399
|
leadSection = `
|
|
301
400
|
|
|
302
401
|
## Team Lead Role
|
|
303
|
-
You are the team lead for this squad.
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
402
|
+
You are the team lead for this squad. **Your sole job is coordination — you do NOT write code, own any domain, or implement features yourself.** Every incoming task must be analyzed, decomposed, and assigned to the appropriate domain specialist via the \`delegate_to_teammate\` tool. The only work you perform directly is breaking tasks down, delegating, and synthesizing results.
|
|
403
|
+
|
|
404
|
+
### Fan-out planning (REQUIRED before any work begins)
|
|
405
|
+
When a task arrives, BEFORE touching code or shell, you MUST:
|
|
406
|
+
|
|
407
|
+
1. **List every distinct work-area** the task touches (e.g. "API endpoint", "DB migration", "frontend component", "tests", "docs"). One bullet per area.
|
|
408
|
+
2. **Score each teammate's charter** against each area — for every area, name the teammate whose charter most closely matches and quote the keyword/phrase from their charter that justifies the assignment.
|
|
409
|
+
3. **Produce a fan-out plan** as a short markdown list: \`- <area> → <teammate> — <one-sentence subtask>\`.
|
|
410
|
+
4. **Delegate each subtask in the plan via \`delegate_to_teammate\`** — in parallel where the subtasks are independent. Do NOT shell, edit, or write code yourself between steps 1–3 and the first \`delegate_to_teammate\` call.
|
|
411
|
+
|
|
412
|
+
### When you may implement directly
|
|
413
|
+
Only if **all** of the following are true:
|
|
414
|
+
- The task is genuinely trivial (a one-line change, a typo fix, a single-file rename) AND fits no teammate's charter better than yours.
|
|
415
|
+
- No teammate's charter covers the work-area at all.
|
|
416
|
+
- A prior \`delegate_to_teammate\` attempt for this exact subtask failed twice with a clear, unrecoverable error.
|
|
417
|
+
|
|
418
|
+
If you find yourself reaching for the shell or file_ops on a normal feature/bug task, **stop** — that's a signal you skipped the fan-out plan. Go back and delegate.
|
|
419
|
+
|
|
420
|
+
### Reviewing teammate output
|
|
421
|
+
After every \`delegate_to_teammate\` call returns, read the result, decide whether it satisfies the subtask, and either accept it (move on to the next subtask) or send a follow-up \`delegate_to_teammate\` to the same teammate with the specific gap to address. Synthesize the final summary only after every subtask is accepted.
|
|
307
422
|
|
|
308
423
|
## Your Team
|
|
309
424
|
${roster}`;
|
|
@@ -324,6 +439,17 @@ ${agent.charter ?? "General-purpose agent. Handle tasks as they come."}
|
|
|
324
439
|
## Past Decisions
|
|
325
440
|
${decisions}${leadSection}
|
|
326
441
|
|
|
442
|
+
## Repository Hygiene
|
|
443
|
+
Before you make ANY code changes, you MUST sync your working copy with the remote default branch and work from a fresh feature branch. This prevents the merge conflicts the team hit on PRs like #45.
|
|
444
|
+
|
|
445
|
+
1. \`cd\` to the project path above.
|
|
446
|
+
2. \`git fetch origin\` — pick up everything that has merged since your last task.
|
|
447
|
+
3. \`git checkout main && git pull origin main\` — fast-forward your local main.
|
|
448
|
+
4. \`git checkout -b <your-handle>/<short-slug>\` — create a fresh branch from the updated main. Never commit directly to main, and never reuse a stale branch from a prior task.
|
|
449
|
+
5. Only THEN start editing files, running tools, or delegating subtasks.
|
|
450
|
+
|
|
451
|
+
If the project's default branch is not \`main\` (e.g. \`master\`, \`develop\`), substitute it everywhere above. If you are not in a git repository, skip this section and proceed normally.
|
|
452
|
+
|
|
327
453
|
## Instructions
|
|
328
454
|
You are a coding agent. Use the shell tool to run commands and file_ops to read/write files.
|
|
329
455
|
Log important decisions with squad_log_decision so they persist.
|
|
@@ -380,6 +506,17 @@ async function getOrCreateSession(squadSlug, taskDescription) {
|
|
|
380
506
|
## Past Decisions
|
|
381
507
|
${decisions}
|
|
382
508
|
|
|
509
|
+
## Repository Hygiene
|
|
510
|
+
Before you make ANY code changes, you MUST sync your working copy with the remote default branch and work from a fresh feature branch. This prevents the merge conflicts the team hit on PRs like #45.
|
|
511
|
+
|
|
512
|
+
1. \`cd\` to the project path above.
|
|
513
|
+
2. \`git fetch origin\` — pick up everything that has merged since your last task.
|
|
514
|
+
3. \`git checkout main && git pull origin main\` — fast-forward your local main.
|
|
515
|
+
4. \`git checkout -b <your-handle>/<short-slug>\` — create a fresh branch from the updated main. Never commit directly to main, and never reuse a stale branch from a prior task.
|
|
516
|
+
5. Only THEN start editing files, running tools, or delegating subtasks.
|
|
517
|
+
|
|
518
|
+
If the project's default branch is not \`main\` (e.g. \`master\`, \`develop\`), substitute it everywhere above. If you are not in a git repository, skip this section and proceed normally.
|
|
519
|
+
|
|
383
520
|
## Your Role
|
|
384
521
|
You are a coding agent. Use the shell tool to run commands and file_ops to read/write files.
|
|
385
522
|
Log important decisions with squad_log_decision so they persist.`,
|
|
@@ -549,17 +686,40 @@ function buildAgentTools(squadSlug, isLead = false) {
|
|
|
549
686
|
if (teammateAgent.is_lead === 1) {
|
|
550
687
|
return `Error: "${teammate}" is the team lead. Delegate to a non-lead teammate.`;
|
|
551
688
|
}
|
|
689
|
+
// Record this sub-delegation as a first-class task so the squad's
|
|
690
|
+
// work-distribution stats reflect real fan-out (issue #51).
|
|
691
|
+
const childTaskId = randomUUID();
|
|
692
|
+
const childAgentKey = agentSessionKey(squadSlug, teammateAgent.character_name);
|
|
693
|
+
createTask(childTaskId, childAgentKey, task, "delegate_to_teammate");
|
|
552
694
|
updateAgentStatus(squadSlug, teammateAgent.character_name, "working");
|
|
553
695
|
try {
|
|
554
696
|
const session = await getOrCreateAgentSession(squadSlug, teammateAgent, task);
|
|
555
|
-
const
|
|
556
|
-
|
|
697
|
+
const envelopedTask = buildTaskPromptEnvelope(squadSlug, task);
|
|
698
|
+
// Idle-reset timeout: 10min between progress events, 30min
|
|
699
|
+
// hard cap. (Issue #53 — replaces #51's 30min wall-clock cap
|
|
700
|
+
// that still killed agents mid-tool-call when they had
|
|
701
|
+
// long-running shell work between assistant messages.)
|
|
702
|
+
const sendResult = await sendWithIdleTimeout(session, envelopedTask, {
|
|
703
|
+
idleMs: 10 * 60_000,
|
|
704
|
+
hardCapMs: 30 * 60_000,
|
|
705
|
+
onIdleTimeout: ({ lastEventType }) => {
|
|
706
|
+
console.error(`[io] Teammate ${teammateAgent.character_name} idle (last event: ${lastEventType ?? "none"}) — aborting.`);
|
|
707
|
+
},
|
|
708
|
+
});
|
|
709
|
+
const result = sendResult.content || "(teammate returned no output)";
|
|
557
710
|
updateAgentStatus(squadSlug, teammateAgent.character_name, "idle");
|
|
711
|
+
if (sendResult.timedOut) {
|
|
712
|
+
const stamped = `[teammate timed out — ${sendResult.timeoutReason === "idle" ? "idle reset" : "hard cap"}; last event: ${sendResult.lastEventType ?? "none"}]\n\n${result}`;
|
|
713
|
+
failTask(childTaskId, stamped);
|
|
714
|
+
return stamped;
|
|
715
|
+
}
|
|
716
|
+
completeTask(childTaskId, result);
|
|
558
717
|
return result;
|
|
559
718
|
}
|
|
560
719
|
catch (err) {
|
|
561
720
|
updateAgentStatus(squadSlug, teammateAgent.character_name, "error");
|
|
562
721
|
const message = err instanceof Error ? err.message : String(err);
|
|
722
|
+
failTask(childTaskId, message);
|
|
563
723
|
return `Error from teammate "${teammate}": ${message}`;
|
|
564
724
|
}
|
|
565
725
|
}
|
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
import { listIoSchedules, listDueIoSchedules, recordIoScheduleRun, setIoScheduleTimestamps, updateIoScheduleNextRun, } from "../store/io-schedules.js";
|
|
7
7
|
import { sendToOrchestrator } from "./orchestrator.js";
|
|
8
8
|
import { nextRun } from "./cron.js";
|
|
9
|
+
import { notifyBackground } from "../notify.js";
|
|
10
|
+
import { startScheduleRun, completeScheduleRun, failScheduleRun } from "../store/schedule-runs.js";
|
|
9
11
|
const TICK_MS = 30_000;
|
|
10
12
|
let timer;
|
|
11
13
|
const inFlight = new Set();
|
|
@@ -30,13 +32,34 @@ async function fireSchedule(schedule) {
|
|
|
30
32
|
}
|
|
31
33
|
recordIoScheduleRun(schedule.id, ranAt, nextIso);
|
|
32
34
|
console.log(`[io] io-scheduler: firing schedule "${schedule.name}" (next run: ${nextIso ?? "never"})`);
|
|
35
|
+
const run = startScheduleRun({
|
|
36
|
+
schedule_type: "io",
|
|
37
|
+
schedule_id: schedule.id,
|
|
38
|
+
schedule_name: schedule.name,
|
|
39
|
+
});
|
|
33
40
|
try {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
let buffer = "";
|
|
42
|
+
await sendToOrchestrator(buildPrompt(schedule), { type: "background" }, (text, done) => {
|
|
43
|
+
buffer += text;
|
|
44
|
+
if (done) {
|
|
45
|
+
void notifyBackground({
|
|
46
|
+
source: {
|
|
47
|
+
type: "io-schedule",
|
|
48
|
+
scheduleId: schedule.id,
|
|
49
|
+
scheduleName: schedule.name,
|
|
50
|
+
},
|
|
51
|
+
title: `IO schedule: ${schedule.name}`,
|
|
52
|
+
text: buffer.trim(),
|
|
53
|
+
}).then((notifyResult) => {
|
|
54
|
+
completeScheduleRun(run.id, notifyResult.id);
|
|
55
|
+
}).catch((err) => {
|
|
56
|
+
failScheduleRun(run.id, err instanceof Error ? err.message : String(err));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
37
59
|
});
|
|
38
60
|
}
|
|
39
61
|
catch (err) {
|
|
62
|
+
failScheduleRun(run.id, err instanceof Error ? err.message : String(err));
|
|
40
63
|
console.error(`[io] io-scheduler: failed to dispatch schedule ${schedule.id}:`, err instanceof Error ? err.message : err);
|
|
41
64
|
}
|
|
42
65
|
finally {
|
|
@@ -3,8 +3,8 @@ import { approveAll, } from "@github/copilot-sdk";
|
|
|
3
3
|
import { config } from "../config.js";
|
|
4
4
|
import { SESSIONS_DIR, IO_VERSION } from "../paths.js";
|
|
5
5
|
import { getState, setState, deleteState, logConversation } from "../store/db.js";
|
|
6
|
-
import { clearStaleTasks, getTask, getTaskReviews } from "../store/tasks.js";
|
|
7
|
-
import { getSquad, listSquads, createSquad, deleteSquad, logDecision, getDecisionsSummary, updateSquadStatus, addSquadAgent, listSquadAgents, removeSquadAgent, setSquadLead, getSquadLead, setSquadQA, } from "../store/squads.js";
|
|
6
|
+
import { clearStaleTasks, getAgentTaskStats, getSquadWorkDistribution, getStalestSpecialist, getTask, getTaskReviews } from "../store/tasks.js";
|
|
7
|
+
import { getSquad, listSquads, createSquad, deleteSquad, logDecision, getDecisions, getDecisionsSummary, updateSquadStatus, addSquadAgent, listSquadAgents, removeSquadAgent, updateAgentStatus, clearAgentSession, setSquadLead, getSquadLead, setSquadQA, } from "../store/squads.js";
|
|
8
8
|
import { readPage, writePage, assertPagePath, deletePage, listPages } from "../wiki/fs.js";
|
|
9
9
|
import { resolveModelTiers } from "./model-router.js";
|
|
10
10
|
import { searchWiki, getWikiSummary } from "../wiki/search.js";
|
|
@@ -12,7 +12,7 @@ import { getOrchestratorSystemMessage } from "./system-message.js";
|
|
|
12
12
|
import { createTools } from "./tools.js";
|
|
13
13
|
import { getSkillDirectories, listSkills, installSkill, removeSkill, searchSkillsRegistry } from "./skills.js";
|
|
14
14
|
import { resetClient } from "./client.js";
|
|
15
|
-
import { delegateToAgent, getActiveAgentTasks } from "./agents.js";
|
|
15
|
+
import { delegateToAgent, getActiveAgentTasks, clearAgentInMemorySession } from "./agents.js";
|
|
16
16
|
import { saveConfig } from "../config.js";
|
|
17
17
|
import { checkForUpdate } from "../update.js";
|
|
18
18
|
// ---------------------------------------------------------------------------
|
|
@@ -56,6 +56,11 @@ function getToolDeps() {
|
|
|
56
56
|
deleteSquad,
|
|
57
57
|
logDecision,
|
|
58
58
|
getDecisionsSummary,
|
|
59
|
+
getRecentDecisions: (slug, limit) => getDecisions(slug, limit ?? 5).map((d) => ({
|
|
60
|
+
decision: d.decision,
|
|
61
|
+
context: d.context,
|
|
62
|
+
created_at: d.created_at,
|
|
63
|
+
})),
|
|
59
64
|
updateSquadStatus,
|
|
60
65
|
delegateToAgent,
|
|
61
66
|
getTask,
|
|
@@ -77,6 +82,25 @@ function getToolDeps() {
|
|
|
77
82
|
is_qa: a.is_qa,
|
|
78
83
|
})),
|
|
79
84
|
removeSquadAgent,
|
|
85
|
+
resetSquadAgent: (squadSlug, characterName) => {
|
|
86
|
+
const agents = listSquadAgents(squadSlug);
|
|
87
|
+
const target = agents.find((a) => a.character_name === characterName);
|
|
88
|
+
if (!target) {
|
|
89
|
+
return { found: false, previousStatus: "", agent: null };
|
|
90
|
+
}
|
|
91
|
+
const previousStatus = target.status;
|
|
92
|
+
updateAgentStatus(squadSlug, characterName, "idle");
|
|
93
|
+
clearAgentSession(squadSlug, characterName);
|
|
94
|
+
clearAgentInMemorySession(squadSlug, characterName);
|
|
95
|
+
return {
|
|
96
|
+
found: true,
|
|
97
|
+
previousStatus,
|
|
98
|
+
agent: {
|
|
99
|
+
character_name: target.character_name,
|
|
100
|
+
role_title: target.role_title,
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
},
|
|
80
104
|
setSquadLead,
|
|
81
105
|
getSquadLead: (slug) => {
|
|
82
106
|
const lead = getSquadLead(slug);
|
|
@@ -91,6 +115,9 @@ function getToolDeps() {
|
|
|
91
115
|
comments: r.comments,
|
|
92
116
|
squad_slug: r.squad_slug,
|
|
93
117
|
})),
|
|
118
|
+
getSquadWorkDistribution: (slug, limit) => getSquadWorkDistribution(slug, limit),
|
|
119
|
+
getAgentTaskStats: (squadSlug, characterNames) => getAgentTaskStats(squadSlug, characterNames),
|
|
120
|
+
getStalestSpecialist: (squadSlug, characterNames, options) => getStalestSpecialist(squadSlug, characterNames, options),
|
|
94
121
|
listSkills,
|
|
95
122
|
installSkill,
|
|
96
123
|
removeSkill,
|
|
@@ -14,6 +14,8 @@ import { listSchedules, listDueSchedules, recordScheduleRun, setScheduleTimestam
|
|
|
14
14
|
import { getSquad } from "../store/squads.js";
|
|
15
15
|
import { delegateToAgent } from "./agents.js";
|
|
16
16
|
import { nextRun } from "./cron.js";
|
|
17
|
+
import { notifyBackground } from "../notify.js";
|
|
18
|
+
import { startScheduleRun, completeScheduleRun, failScheduleRun } from "../store/schedule-runs.js";
|
|
17
19
|
const TICK_MS = 30_000;
|
|
18
20
|
const AGENDA_BLOCKS = {
|
|
19
21
|
triage: `**Triage**
|
|
@@ -70,12 +72,32 @@ async function fireSchedule(schedule) {
|
|
|
70
72
|
recordScheduleRun(schedule.id, ranAt, nextIso);
|
|
71
73
|
const prompt = buildStandupPrompt({ name: squad.name, slug: squad.slug, project_path: squad.project_path }, schedule);
|
|
72
74
|
console.log(`[io] scheduler: firing schedule "${schedule.name}" for squad "${squad.slug}" (next run: ${nextIso ?? "never"})`);
|
|
75
|
+
const run = startScheduleRun({
|
|
76
|
+
schedule_type: "squad",
|
|
77
|
+
schedule_id: schedule.id,
|
|
78
|
+
schedule_name: schedule.name,
|
|
79
|
+
squad_slug: squad.slug,
|
|
80
|
+
});
|
|
73
81
|
try {
|
|
74
|
-
await delegateToAgent(squad.slug, prompt, () => {
|
|
75
|
-
|
|
82
|
+
await delegateToAgent(squad.slug, prompt, (_taskId, result) => {
|
|
83
|
+
void notifyBackground({
|
|
84
|
+
source: {
|
|
85
|
+
type: "squad-schedule",
|
|
86
|
+
scheduleId: schedule.id,
|
|
87
|
+
squadSlug: squad.slug,
|
|
88
|
+
scheduleName: schedule.name,
|
|
89
|
+
},
|
|
90
|
+
title: `${squad.name}: ${schedule.name}`,
|
|
91
|
+
text: result,
|
|
92
|
+
}).then((notifyResult) => {
|
|
93
|
+
completeScheduleRun(run.id, notifyResult.id);
|
|
94
|
+
}).catch((err) => {
|
|
95
|
+
failScheduleRun(run.id, err instanceof Error ? err.message : String(err));
|
|
96
|
+
});
|
|
76
97
|
});
|
|
77
98
|
}
|
|
78
99
|
catch (err) {
|
|
100
|
+
failScheduleRun(run.id, err instanceof Error ? err.message : String(err));
|
|
79
101
|
console.error(`[io] scheduler: failed to delegate stand-up for schedule ${schedule.id}:`, err instanceof Error ? err.message : err);
|
|
80
102
|
}
|
|
81
103
|
finally {
|