@agentuity/opencode 1.0.18 → 1.0.20
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/agents/expert-backend.d.ts +1 -1
- package/dist/agents/expert-backend.d.ts.map +1 -1
- package/dist/agents/expert-backend.js +0 -17
- package/dist/agents/expert-backend.js.map +1 -1
- package/dist/agents/expert.d.ts +1 -1
- package/dist/agents/expert.d.ts.map +1 -1
- package/dist/agents/expert.js +1 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +0 -2
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/lead.d.ts +1 -1
- package/dist/agents/lead.d.ts.map +1 -1
- package/dist/agents/lead.js +25 -145
- package/dist/agents/lead.js.map +1 -1
- package/dist/agents/scout.d.ts +1 -1
- package/dist/agents/scout.d.ts.map +1 -1
- package/dist/agents/scout.js +16 -0
- package/dist/agents/scout.js.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +1 -33
- package/dist/config/loader.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/plugin/hooks/cadence.d.ts +1 -2
- package/dist/plugin/hooks/cadence.d.ts.map +1 -1
- package/dist/plugin/hooks/cadence.js +7 -33
- package/dist/plugin/hooks/cadence.js.map +1 -1
- package/dist/plugin/hooks/compaction-utils.d.ts.map +1 -1
- package/dist/plugin/hooks/compaction-utils.js +6 -13
- package/dist/plugin/hooks/compaction-utils.js.map +1 -1
- package/dist/plugin/hooks/completion.d.ts.map +1 -1
- package/dist/plugin/hooks/completion.js +2 -3
- package/dist/plugin/hooks/completion.js.map +1 -1
- package/dist/plugin/hooks/params.d.ts.map +1 -1
- package/dist/plugin/hooks/params.js +0 -1
- package/dist/plugin/hooks/params.js.map +1 -1
- package/dist/plugin/hooks/session-memory.d.ts +1 -2
- package/dist/plugin/hooks/session-memory.d.ts.map +1 -1
- package/dist/plugin/hooks/session-memory.js +6 -29
- package/dist/plugin/hooks/session-memory.js.map +1 -1
- package/dist/plugin/plugin.d.ts.map +1 -1
- package/dist/plugin/plugin.js +8 -222
- package/dist/plugin/plugin.js.map +1 -1
- package/dist/sqlite/types.d.ts +0 -6
- package/dist/sqlite/types.d.ts.map +1 -1
- package/dist/tmux/manager.d.ts +4 -4
- package/dist/tmux/manager.js +4 -4
- package/dist/tmux/types.d.ts +1 -1
- package/dist/tools/index.d.ts +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/types.d.ts +2 -20
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +0 -9
- package/dist/types.js.map +1 -1
- package/package.json +3 -3
- package/src/agents/expert-backend.ts +0 -17
- package/src/agents/expert.ts +1 -1
- package/src/agents/index.ts +0 -2
- package/src/agents/lead.ts +25 -145
- package/src/agents/scout.ts +16 -0
- package/src/config/loader.ts +1 -45
- package/src/index.ts +0 -1
- package/src/plugin/hooks/cadence.ts +6 -39
- package/src/plugin/hooks/compaction-utils.ts +6 -12
- package/src/plugin/hooks/completion.ts +2 -4
- package/src/plugin/hooks/params.ts +0 -3
- package/src/plugin/hooks/session-memory.ts +5 -35
- package/src/plugin/plugin.ts +7 -257
- package/src/sqlite/types.ts +0 -2
- package/src/tmux/manager.ts +4 -4
- package/src/tmux/types.ts +2 -2
- package/src/tools/index.ts +2 -9
- package/src/types.ts +0 -13
- package/dist/agents/monitor.d.ts +0 -4
- package/dist/agents/monitor.d.ts.map +0 -1
- package/dist/agents/monitor.js +0 -159
- package/dist/agents/monitor.js.map +0 -1
- package/dist/background/concurrency.d.ts +0 -36
- package/dist/background/concurrency.d.ts.map +0 -1
- package/dist/background/concurrency.js +0 -92
- package/dist/background/concurrency.js.map +0 -1
- package/dist/background/index.d.ts +0 -5
- package/dist/background/index.d.ts.map +0 -1
- package/dist/background/index.js +0 -4
- package/dist/background/index.js.map +0 -1
- package/dist/background/manager.d.ts +0 -123
- package/dist/background/manager.d.ts.map +0 -1
- package/dist/background/manager.js +0 -1081
- package/dist/background/manager.js.map +0 -1
- package/dist/background/types.d.ts +0 -90
- package/dist/background/types.d.ts.map +0 -1
- package/dist/background/types.js +0 -2
- package/dist/background/types.js.map +0 -1
- package/dist/tools/background.d.ts +0 -67
- package/dist/tools/background.d.ts.map +0 -1
- package/dist/tools/background.js +0 -95
- package/dist/tools/background.js.map +0 -1
- package/src/agents/monitor.ts +0 -161
- package/src/background/concurrency.ts +0 -116
- package/src/background/index.ts +0 -4
- package/src/background/manager.ts +0 -1226
- package/src/background/types.ts +0 -82
- package/src/tools/background.ts +0 -179
package/dist/agents/monitor.js
DELETED
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
export const MONITOR_SYSTEM_PROMPT = `# BackgroundMonitor Agent
|
|
2
|
-
|
|
3
|
-
You are an auto-launched background task monitor. You were spawned automatically when Lead started background tasks. Your ONLY job is to watch those tasks and push a consolidated completion report back to Lead when they are all done.
|
|
4
|
-
|
|
5
|
-
**Lead is not polling. Lead is not watching. You are the eyes. Lead trusts you to report.**
|
|
6
|
-
|
|
7
|
-
## How You Discover Tasks
|
|
8
|
-
|
|
9
|
-
You receive a parent session ID in your prompt. Use it to discover all sibling tasks:
|
|
10
|
-
|
|
11
|
-
\`\`\`
|
|
12
|
-
agentuity_session_dashboard({ session_id: "<parentSessionId>" })
|
|
13
|
-
\`\`\`
|
|
14
|
-
|
|
15
|
-
This is scoped to child sessions of that parent only — it does not expose unrelated sessions.
|
|
16
|
-
From the dashboard, extract the task IDs (bg_xxx format) from session titles.
|
|
17
|
-
Then use \`agentuity_background_output({ task_id: "bg_xxx" })\` to get status + progress for each.
|
|
18
|
-
|
|
19
|
-
Ignore sessions that are other Monitor instances — their \`displayTitle\` will be "Monitor background tasks". Filter these out when processing the dashboard results.
|
|
20
|
-
|
|
21
|
-
## Progress Signal
|
|
22
|
-
|
|
23
|
-
\`agentuity_background_output\` now returns a \`progress\` object on running tasks:
|
|
24
|
-
|
|
25
|
-
\`\`\`json
|
|
26
|
-
{
|
|
27
|
-
"status": "running",
|
|
28
|
-
"progress": {
|
|
29
|
-
"toolCalls": 21,
|
|
30
|
-
"lastTool": "read",
|
|
31
|
-
"lastToolSec": 12,
|
|
32
|
-
"activeTools": 1
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
\`\`\`
|
|
36
|
-
|
|
37
|
-
- \`toolCalls\`: total tool calls completed — growing means active work
|
|
38
|
-
- \`lastTool\`: name of the most recently completed tool
|
|
39
|
-
- \`lastToolSec\`: seconds since last tool activity — <300 with growth means healthy
|
|
40
|
-
- \`activeTools\`: tool calls currently in-flight
|
|
41
|
-
|
|
42
|
-
A task is **stuck** only if \`lastToolSec > 300\` AND \`activeTools === 0\` AND \`toolCalls\` has not grown between checks.
|
|
43
|
-
|
|
44
|
-
## Check Cadence — CRITICAL
|
|
45
|
-
|
|
46
|
-
**You MUST wait at least 20 seconds between each check cycle.** This is a hard requirement, not a suggestion.
|
|
47
|
-
|
|
48
|
-
- Minimum 20 seconds between checks — count them, do not rush
|
|
49
|
-
- Maximum 10 check cycles total (covers ~3-4 minutes of typical work)
|
|
50
|
-
- After EACH check, output: "⏳ Waiting 20 seconds before next check..." — this helps you pace yourself
|
|
51
|
-
- Scout tasks typically take 3–8 minutes — be patient, checking faster does NOT make them complete faster
|
|
52
|
-
- Excessive polling wastes tokens and provides no benefit
|
|
53
|
-
|
|
54
|
-
For each poll cycle (track cycle number starting at 1):
|
|
55
|
-
1. Check each task ID with \`agentuity_background_output({ task_id: "bg_xxx" })\`
|
|
56
|
-
2. Track the status of each task
|
|
57
|
-
3. If any task is still "pending" or "running" **and cycle < 10**, wait 20 seconds and poll again
|
|
58
|
-
4. When all tasks are "completed" or "error" **OR cycle reaches 10**, generate the final report
|
|
59
|
-
|
|
60
|
-
## When Tasks Are Stuck
|
|
61
|
-
|
|
62
|
-
If a task shows \`lastToolSec > 300\` AND \`activeTools === 0\`:
|
|
63
|
-
1. Call \`agentuity_background_inspect({ task_id: "bg_xxx" })\` for a full view
|
|
64
|
-
2. Include what you found in your final report under "Stuck Tasks"
|
|
65
|
-
3. Do NOT cancel the task — report it to Lead for a decision
|
|
66
|
-
|
|
67
|
-
## Completion Condition
|
|
68
|
-
|
|
69
|
-
All work tasks are done when every non-monitor task is \`completed\`, \`error\`, or \`cancelled\`.
|
|
70
|
-
|
|
71
|
-
## Final Report Format
|
|
72
|
-
|
|
73
|
-
When all tasks are done (or after 20 cycles), output exactly this:
|
|
74
|
-
|
|
75
|
-
\`\`\`markdown
|
|
76
|
-
## [ALL BACKGROUND TASKS COMPLETE]
|
|
77
|
-
|
|
78
|
-
- **bg_xxx** (completed): [first 100 chars of result]
|
|
79
|
-
- **bg_yyy** (error): [error message]
|
|
80
|
-
- **bg_zzz** (completed): [first 100 chars of result]
|
|
81
|
-
|
|
82
|
-
### Results
|
|
83
|
-
|
|
84
|
-
**bg_xxx:**
|
|
85
|
-
[full result text]
|
|
86
|
-
|
|
87
|
-
**bg_yyy (error):**
|
|
88
|
-
[error]
|
|
89
|
-
\`\`\`
|
|
90
|
-
|
|
91
|
-
If tasks are still running after 10 cycles, use "## [BACKGROUND TASKS STILL RUNNING]" as the header and list the stuck ones with their last known progress.
|
|
92
|
-
|
|
93
|
-
## Timeout Errors
|
|
94
|
-
|
|
95
|
-
- **Timeout errors** ("Background task timed out (no activity).") often occur when the model is
|
|
96
|
-
generating a long text response without making tool calls. These are server-side inactivity
|
|
97
|
-
timeouts, not true failures — the model was still working but appeared idle to the server.
|
|
98
|
-
- If a task errors with a timeout, note this in your report. It may be worth retrying.
|
|
99
|
-
|
|
100
|
-
## What You Do NOT Do
|
|
101
|
-
|
|
102
|
-
- ❌ Interpret or analyze task results beyond summarizing
|
|
103
|
-
- ❌ Make decisions about next steps
|
|
104
|
-
- ❌ Cancel tasks (ever)
|
|
105
|
-
- ❌ Interact with the user
|
|
106
|
-
- ❌ Modify any files
|
|
107
|
-
- ❌ Call other agents
|
|
108
|
-
- ❌ Use tools other than agentuity_background_output, agentuity_background_inspect, and agentuity_session_dashboard
|
|
109
|
-
|
|
110
|
-
You are a patient, focused watcher. When work is done, you report. Nothing more.
|
|
111
|
-
|
|
112
|
-
## Example Workflow
|
|
113
|
-
|
|
114
|
-
Given task: "Monitor these tasks: bg_abc123, bg_def456"
|
|
115
|
-
|
|
116
|
-
1. Call agentuity_background_output for bg_abc123
|
|
117
|
-
2. Call agentuity_background_output for bg_def456
|
|
118
|
-
3. If any status is "pending" or "running" and cycle < 10, wait 20 seconds
|
|
119
|
-
4. Repeat steps 1-3 until all complete or 10 cycles reached
|
|
120
|
-
5. Output final report
|
|
121
|
-
|
|
122
|
-
## Waiting Between Polls
|
|
123
|
-
|
|
124
|
-
Since you cannot use setTimeout, after checking all tasks and finding some still running, you MUST output:
|
|
125
|
-
|
|
126
|
-
"⏳ Waiting 20 seconds before next check... (cycle 3/10)"
|
|
127
|
-
|
|
128
|
-
Then poll again. The conversation history serves as your "timer" — each response and check adds natural delay. Do NOT skip the waiting message.
|
|
129
|
-
|
|
130
|
-
**After 10 cycles:** Report final status even if tasks are still running, noting which tasks did not complete within the monitoring window.
|
|
131
|
-
`;
|
|
132
|
-
export const monitorAgent = {
|
|
133
|
-
role: 'monitor',
|
|
134
|
-
id: 'ag-monitor',
|
|
135
|
-
displayName: 'Agentuity Coder Monitor',
|
|
136
|
-
description: 'Background task monitor - watches background tasks and reports completions',
|
|
137
|
-
defaultModel: 'anthropic/claude-haiku-4-5-20251001', // Lightweight, fast
|
|
138
|
-
systemPrompt: MONITOR_SYSTEM_PROMPT,
|
|
139
|
-
mode: 'subagent', // Only used as subagent, never primary
|
|
140
|
-
hidden: true, // Hidden from @ autocomplete, but can be invoked via Task tool
|
|
141
|
-
tools: {
|
|
142
|
-
// Monitor only needs the background output tool - exclude everything else
|
|
143
|
-
exclude: [
|
|
144
|
-
'write',
|
|
145
|
-
'edit',
|
|
146
|
-
'apply_patch',
|
|
147
|
-
'bash',
|
|
148
|
-
'read',
|
|
149
|
-
'glob',
|
|
150
|
-
'grep',
|
|
151
|
-
'task',
|
|
152
|
-
'agentuity_background_task',
|
|
153
|
-
'agentuity_background_cancel',
|
|
154
|
-
'agentuity_memory_share',
|
|
155
|
-
],
|
|
156
|
-
},
|
|
157
|
-
temperature: 0.0, // Deterministic - just poll and report
|
|
158
|
-
};
|
|
159
|
-
//# sourceMappingURL=monitor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"monitor.js","sourceRoot":"","sources":["../../src/agents/monitor.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkIpC,CAAC;AAEF,MAAM,CAAC,MAAM,YAAY,GAAoB;IAC5C,IAAI,EAAE,SAAS;IACf,EAAE,EAAE,YAAY;IAChB,WAAW,EAAE,yBAAyB;IACtC,WAAW,EAAE,4EAA4E;IACzF,YAAY,EAAE,qCAAqC,EAAE,oBAAoB;IACzE,YAAY,EAAE,qBAAqB;IACnC,IAAI,EAAE,UAAU,EAAE,uCAAuC;IACzD,MAAM,EAAE,IAAI,EAAE,+DAA+D;IAC7E,KAAK,EAAE;QACN,0EAA0E;QAC1E,OAAO,EAAE;YACR,OAAO;YACP,MAAM;YACN,aAAa;YACb,MAAM;YACN,MAAM;YACN,MAAM;YACN,MAAM;YACN,MAAM;YACN,2BAA2B;YAC3B,6BAA6B;YAC7B,wBAAwB;SACxB;KACD;IACD,WAAW,EAAE,GAAG,EAAE,uCAAuC;CACzD,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Error thrown when a concurrency waiter is cancelled.
|
|
3
|
-
*/
|
|
4
|
-
export declare const ConcurrencyCancelledError: {
|
|
5
|
-
new (args?: ({
|
|
6
|
-
key?: string;
|
|
7
|
-
} & {
|
|
8
|
-
cause?: unknown;
|
|
9
|
-
}) | undefined): import("@agentuity/core").RichError & {
|
|
10
|
-
readonly _tag: "ConcurrencyCancelledError";
|
|
11
|
-
} & Readonly<{
|
|
12
|
-
key?: string;
|
|
13
|
-
}>;
|
|
14
|
-
readonly defaultMessage?: string;
|
|
15
|
-
};
|
|
16
|
-
export interface ConcurrencyConfig {
|
|
17
|
-
defaultLimit: number;
|
|
18
|
-
limits?: Record<string, number>;
|
|
19
|
-
}
|
|
20
|
-
export declare class ConcurrencyManager {
|
|
21
|
-
private defaultLimit;
|
|
22
|
-
private limits;
|
|
23
|
-
private counts;
|
|
24
|
-
private queues;
|
|
25
|
-
constructor(config?: Partial<ConcurrencyConfig>);
|
|
26
|
-
getConcurrencyLimit(key: string): number;
|
|
27
|
-
acquire(key: string): Promise<void>;
|
|
28
|
-
release(key: string): void;
|
|
29
|
-
cancelWaiters(key: string): void;
|
|
30
|
-
clear(): void;
|
|
31
|
-
getCount(key: string): number;
|
|
32
|
-
getQueueLength(key: string): number;
|
|
33
|
-
private getQueue;
|
|
34
|
-
private flushQueue;
|
|
35
|
-
}
|
|
36
|
-
//# sourceMappingURL=concurrency.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"concurrency.d.ts","sourceRoot":"","sources":["../../src/background/concurrency.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,yBAAyB;;cAG5B,MAAM;;;;;;cAAN,MAAM;;;CAAK,CAAC;AAOtB,MAAM,WAAW,iBAAiB;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED,qBAAa,kBAAkB;IAC9B,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,MAAM,CAA+B;gBAEjC,MAAM,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC;IAW/C,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAIlC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAqBzC,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAQ1B,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAUhC,KAAK,IAAI,IAAI;IAQb,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAI7B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAInC,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,UAAU;CAWlB"}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { StructuredError } from '@agentuity/core';
|
|
2
|
-
/**
|
|
3
|
-
* Error thrown when a concurrency waiter is cancelled.
|
|
4
|
-
*/
|
|
5
|
-
export const ConcurrencyCancelledError = StructuredError('ConcurrencyCancelledError', 'Concurrency waiter cancelled')();
|
|
6
|
-
export class ConcurrencyManager {
|
|
7
|
-
defaultLimit;
|
|
8
|
-
limits = new Map();
|
|
9
|
-
counts = new Map();
|
|
10
|
-
queues = new Map();
|
|
11
|
-
constructor(config) {
|
|
12
|
-
// Clamp defaultLimit to at least 1 to prevent deadlocks
|
|
13
|
-
this.defaultLimit = Math.max(1, config?.defaultLimit ?? 1);
|
|
14
|
-
if (config?.limits) {
|
|
15
|
-
for (const [key, value] of Object.entries(config.limits)) {
|
|
16
|
-
// Clamp each limit to at least 1
|
|
17
|
-
this.limits.set(key, Math.max(1, value));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
getConcurrencyLimit(key) {
|
|
22
|
-
return this.limits.get(key) ?? this.defaultLimit;
|
|
23
|
-
}
|
|
24
|
-
async acquire(key) {
|
|
25
|
-
const limit = this.getConcurrencyLimit(key);
|
|
26
|
-
const count = this.getCount(key);
|
|
27
|
-
if (count < limit) {
|
|
28
|
-
this.counts.set(key, count + 1);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
await new Promise((resolve, reject) => {
|
|
32
|
-
const queue = this.getQueue(key);
|
|
33
|
-
queue.push({
|
|
34
|
-
resolve: () => {
|
|
35
|
-
this.counts.set(key, this.getCount(key) + 1);
|
|
36
|
-
resolve();
|
|
37
|
-
},
|
|
38
|
-
reject,
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
release(key) {
|
|
43
|
-
const count = this.getCount(key);
|
|
44
|
-
if (count > 0) {
|
|
45
|
-
this.counts.set(key, count - 1);
|
|
46
|
-
}
|
|
47
|
-
this.flushQueue(key);
|
|
48
|
-
}
|
|
49
|
-
cancelWaiters(key) {
|
|
50
|
-
const queue = this.queues.get(key);
|
|
51
|
-
if (!queue || queue.length === 0)
|
|
52
|
-
return;
|
|
53
|
-
for (const waiter of queue) {
|
|
54
|
-
waiter.reject(new ConcurrencyCancelledError({ key }));
|
|
55
|
-
}
|
|
56
|
-
this.queues.delete(key);
|
|
57
|
-
}
|
|
58
|
-
clear() {
|
|
59
|
-
for (const key of this.queues.keys()) {
|
|
60
|
-
this.cancelWaiters(key);
|
|
61
|
-
}
|
|
62
|
-
this.counts.clear();
|
|
63
|
-
this.queues.clear();
|
|
64
|
-
}
|
|
65
|
-
getCount(key) {
|
|
66
|
-
return this.counts.get(key) ?? 0;
|
|
67
|
-
}
|
|
68
|
-
getQueueLength(key) {
|
|
69
|
-
return this.queues.get(key)?.length ?? 0;
|
|
70
|
-
}
|
|
71
|
-
getQueue(key) {
|
|
72
|
-
const existing = this.queues.get(key);
|
|
73
|
-
if (existing)
|
|
74
|
-
return existing;
|
|
75
|
-
const queue = [];
|
|
76
|
-
this.queues.set(key, queue);
|
|
77
|
-
return queue;
|
|
78
|
-
}
|
|
79
|
-
flushQueue(key) {
|
|
80
|
-
const queue = this.queues.get(key);
|
|
81
|
-
if (!queue || queue.length === 0)
|
|
82
|
-
return;
|
|
83
|
-
const limit = this.getConcurrencyLimit(key);
|
|
84
|
-
while (queue.length > 0 && this.getCount(key) < limit) {
|
|
85
|
-
const waiter = queue.shift();
|
|
86
|
-
if (!waiter)
|
|
87
|
-
break;
|
|
88
|
-
waiter.resolve();
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
//# sourceMappingURL=concurrency.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"concurrency.js","sourceRoot":"","sources":["../../src/background/concurrency.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,eAAe,CACvD,2BAA2B,EAC3B,8BAA8B,CAC9B,EAAoB,CAAC;AAYtB,MAAM,OAAO,kBAAkB;IACtB,YAAY,CAAS;IACrB,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnC,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnC,MAAM,GAAG,IAAI,GAAG,EAAoB,CAAC;IAE7C,YAAY,MAAmC;QAC9C,wDAAwD;QACxD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,IAAI,CAAC,CAAC,CAAC;QAC3D,IAAI,MAAM,EAAE,MAAM,EAAE,CAAC;YACpB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC1D,iCAAiC;gBACjC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;YAC1C,CAAC;QACF,CAAC;IACF,C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KAAK,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO;QAEzC,MAAM,KAAK,GAAG,IAAI,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;QAC5C,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,EAAE,CAAC;YACvD,MAAM,MAAM,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM;gBAAE,MAAM;YACnB,MAAM,CAAC,OAAO,EAAE,CAAC;QAClB,CAAC;IACF,CAAC;CACD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/background/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,YAAY,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/background/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/background/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import type { PluginInput } from '@opencode-ai/plugin';
|
|
2
|
-
import type { OpenCodeDBReader } from '../sqlite';
|
|
3
|
-
import type { BackgroundTask, BackgroundTaskConfig, BackgroundTaskStatus, LaunchInput, TaskInspection } from './types';
|
|
4
|
-
type EventPayload = {
|
|
5
|
-
type: string;
|
|
6
|
-
properties?: Record<string, unknown>;
|
|
7
|
-
};
|
|
8
|
-
export interface BackgroundManagerCallbacks {
|
|
9
|
-
onSubagentSessionCreated?: (event: {
|
|
10
|
-
sessionId: string;
|
|
11
|
-
parentId: string;
|
|
12
|
-
title: string;
|
|
13
|
-
}) => void;
|
|
14
|
-
onSubagentSessionDeleted?: (event: {
|
|
15
|
-
sessionId: string;
|
|
16
|
-
}) => void;
|
|
17
|
-
onShutdown?: () => void | Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
export declare class BackgroundManager {
|
|
20
|
-
private ctx;
|
|
21
|
-
private config;
|
|
22
|
-
private concurrency;
|
|
23
|
-
private callbacks?;
|
|
24
|
-
private dbReader?;
|
|
25
|
-
private serverUrl;
|
|
26
|
-
private authHeaders;
|
|
27
|
-
private tasks;
|
|
28
|
-
private tasksByParent;
|
|
29
|
-
private tasksBySession;
|
|
30
|
-
private notifications;
|
|
31
|
-
private toolCallIds;
|
|
32
|
-
/** Tracks tool call IDs that are currently in-flight (pending/running state) per task */
|
|
33
|
-
private activeToolCallIds;
|
|
34
|
-
/** Maps parent session ID → monitor task ID for auto-launched monitors */
|
|
35
|
-
private monitorsPerParent;
|
|
36
|
-
private lastNotifyTimes;
|
|
37
|
-
private shuttingDown;
|
|
38
|
-
private refreshIntervalId;
|
|
39
|
-
constructor(ctx: PluginInput, config?: BackgroundTaskConfig, callbacks?: BackgroundManagerCallbacks, dbReader?: OpenCodeDBReader);
|
|
40
|
-
/**
|
|
41
|
-
* Resolve the server URL from the plugin context.
|
|
42
|
-
* Mirrors the defensive pattern used in the tmux manager to handle
|
|
43
|
-
* sandbox environments where the client may not have a baseUrl configured.
|
|
44
|
-
*/
|
|
45
|
-
private resolveServerUrl;
|
|
46
|
-
/**
|
|
47
|
-
* Resolve authentication headers from environment variables.
|
|
48
|
-
*
|
|
49
|
-
* Reads `OPENCODE_SERVER_USERNAME` and `OPENCODE_SERVER_PASSWORD` (set
|
|
50
|
-
* automatically by the OpenCode server in sandbox environments) and
|
|
51
|
-
* produces a Basic Auth header (`base64("username:password")`).
|
|
52
|
-
*
|
|
53
|
-
* In sandbox environments the SDK client's default auth may not carry over
|
|
54
|
-
* when a per-call `baseUrl` override is provided, so we need to explicitly
|
|
55
|
-
* attach these credentials for server-to-server requests.
|
|
56
|
-
*/
|
|
57
|
-
private resolveAuthHeaders;
|
|
58
|
-
/**
|
|
59
|
-
* Build the per-call client overrides (baseUrl + auth headers).
|
|
60
|
-
* Spread this into every SDK client call so both the server URL and
|
|
61
|
-
* authentication are correctly forwarded in sandbox environments.
|
|
62
|
-
*/
|
|
63
|
-
private getClientOverrides;
|
|
64
|
-
launch(input: LaunchInput): Promise<BackgroundTask>;
|
|
65
|
-
getTask(id: string): BackgroundTask | undefined;
|
|
66
|
-
getTasksByParent(sessionId: string): BackgroundTask[];
|
|
67
|
-
findBySession(sessionId: string): BackgroundTask | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* Inspect a background task by fetching its session messages.
|
|
70
|
-
* Useful for seeing what a child Lead or other agent is doing.
|
|
71
|
-
*/
|
|
72
|
-
inspectTask(taskId: string): Promise<TaskInspection | undefined>;
|
|
73
|
-
/**
|
|
74
|
-
* Refresh task statuses from the server.
|
|
75
|
-
* Useful for recovering state after issues or checking on stuck tasks.
|
|
76
|
-
*/
|
|
77
|
-
refreshStatuses(): Promise<Map<string, BackgroundTaskStatus>>;
|
|
78
|
-
/**
|
|
79
|
-
* Recover background tasks from existing sessions.
|
|
80
|
-
* Call this on plugin startup to restore state after restart.
|
|
81
|
-
*
|
|
82
|
-
* This method queries all sessions and reconstructs task state from
|
|
83
|
-
* sessions that have JSON-encoded task metadata in their title.
|
|
84
|
-
*
|
|
85
|
-
* @returns The number of tasks recovered
|
|
86
|
-
*/
|
|
87
|
-
recoverTasks(): Promise<number>;
|
|
88
|
-
private mapSessionStatusToTaskStatus;
|
|
89
|
-
cancel(taskId: string): boolean;
|
|
90
|
-
handleEvent(event: EventPayload): void;
|
|
91
|
-
markForNotification(task: BackgroundTask): void;
|
|
92
|
-
getPendingNotifications(sessionId: string): BackgroundTask[];
|
|
93
|
-
clearNotifications(sessionId: string): void;
|
|
94
|
-
shutdown(): void;
|
|
95
|
-
private indexTask;
|
|
96
|
-
/**
|
|
97
|
-
* Ensure a Monitor agent is watching all background tasks for the given parent session.
|
|
98
|
-
*
|
|
99
|
-
* Called automatically whenever a new background task is launched. If a Monitor is
|
|
100
|
-
* already running for this parent, this is a no-op. The Monitor uses
|
|
101
|
-
* `agentuity_session_dashboard({ session_id: parentSessionId })` which is scoped
|
|
102
|
-
* to child sessions of that parent only — it does not see unrelated sessions.
|
|
103
|
-
*
|
|
104
|
-
* The Monitor pushes a consolidated status update to Lead when all tasks complete,
|
|
105
|
-
* so Lead doesn't need to self-poll.
|
|
106
|
-
*/
|
|
107
|
-
private ensureMonitorForParent;
|
|
108
|
-
private startTask;
|
|
109
|
-
private updateProgress;
|
|
110
|
-
private createProgress;
|
|
111
|
-
private completeTask;
|
|
112
|
-
private failTask;
|
|
113
|
-
private releaseConcurrency;
|
|
114
|
-
private notifyParent;
|
|
115
|
-
private abortSession;
|
|
116
|
-
private fetchLatestResult;
|
|
117
|
-
private mapDbStatusToTaskStatus;
|
|
118
|
-
private getConcurrencyGroup;
|
|
119
|
-
private getConcurrencyKey;
|
|
120
|
-
private expireStaleTasks;
|
|
121
|
-
}
|
|
122
|
-
export {};
|
|
123
|
-
//# sourceMappingURL=manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/background/manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGvD,OAAO,KAAK,EAAc,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC9D,OAAO,KAAK,EACX,cAAc,EACd,oBAAoB,EACpB,oBAAoB,EACpB,WAAW,EACX,cAAc,EAEd,MAAM,SAAS,CAAC;AAkBjB,KAAK,YAAY,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC,M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