notsleep 1.0.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/.env.example +117 -0
- package/LICENSE +21 -0
- package/README.md +341 -0
- package/dashboard/index.html +893 -0
- package/dist/agent.d.ts +162 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +1064 -0
- package/dist/agent.js.map +1 -0
- package/dist/api.d.ts +10 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +39 -0
- package/dist/api.js.map +1 -0
- package/dist/checkpoint.d.ts +52 -0
- package/dist/checkpoint.d.ts.map +1 -0
- package/dist/checkpoint.js +234 -0
- package/dist/checkpoint.js.map +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +265 -0
- package/dist/config.js.map +1 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +237 -0
- package/dist/context.js.map +1 -0
- package/dist/cost.d.ts +26 -0
- package/dist/cost.d.ts.map +1 -0
- package/dist/cost.js +161 -0
- package/dist/cost.js.map +1 -0
- package/dist/dashboard.d.ts +96 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +292 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/fileconfig.d.ts +129 -0
- package/dist/fileconfig.d.ts.map +1 -0
- package/dist/fileconfig.js +391 -0
- package/dist/fileconfig.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +882 -0
- package/dist/index.js.map +1 -0
- package/dist/init.d.ts +9 -0
- package/dist/init.d.ts.map +1 -0
- package/dist/init.js +221 -0
- package/dist/init.js.map +1 -0
- package/dist/logger.d.ts +33 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +150 -0
- package/dist/logger.js.map +1 -0
- package/dist/modelsdev.d.ts +63 -0
- package/dist/modelsdev.d.ts.map +1 -0
- package/dist/modelsdev.js +265 -0
- package/dist/modelsdev.js.map +1 -0
- package/dist/parallel.d.ts +54 -0
- package/dist/parallel.d.ts.map +1 -0
- package/dist/parallel.js +139 -0
- package/dist/parallel.js.map +1 -0
- package/dist/pool.d.ts +17 -0
- package/dist/pool.d.ts.map +1 -0
- package/dist/pool.js +53 -0
- package/dist/pool.js.map +1 -0
- package/dist/provider.d.ts +60 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +396 -0
- package/dist/provider.js.map +1 -0
- package/dist/registry.d.ts +60 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +153 -0
- package/dist/registry.js.map +1 -0
- package/dist/safety.d.ts +21 -0
- package/dist/safety.d.ts.map +1 -0
- package/dist/safety.js +118 -0
- package/dist/safety.js.map +1 -0
- package/dist/schema.d.ts +9 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +166 -0
- package/dist/schema.js.map +1 -0
- package/dist/test-dashboard.d.ts +5 -0
- package/dist/test-dashboard.d.ts.map +1 -0
- package/dist/test-dashboard.js +202 -0
- package/dist/test-dashboard.js.map +1 -0
- package/dist/tools.d.ts +27 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +1212 -0
- package/dist/tools.js.map +1 -0
- package/dist/types.d.ts +180 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +14 -0
- package/dist/types.js.map +1 -0
- package/dist/worktree.d.ts +50 -0
- package/dist/worktree.d.ts.map +1 -0
- package/dist/worktree.js +186 -0
- package/dist/worktree.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// NotSleep - Live model metadata (context window + pricing)
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// The agent's context-usage ratio is (current tokens ÷ window limit). The
|
|
7
|
+
// numerator is already the REAL prompt_tokens the API reports. This module
|
|
8
|
+
// makes the DENOMINATOR live too, instead of a static hand-maintained table,
|
|
9
|
+
// via three layered sources (most authoritative first):
|
|
10
|
+
//
|
|
11
|
+
// 1. models.dev — the models.dev/api.json catalog (what OpenCode uses):
|
|
12
|
+
// accurate context/output limits + pricing for ~all
|
|
13
|
+
// providers & models. Fetched once, cached to disk.
|
|
14
|
+
// 2. /models — a provider's own OpenAI-style `GET /models` endpoint,
|
|
15
|
+
// for custom proxies / models the catalog doesn't list.
|
|
16
|
+
// 3. static table — the offline fallback baked into cost.ts.
|
|
17
|
+
//
|
|
18
|
+
// Plus a reactive safety net: parseContextOverflow() reads the true maximum
|
|
19
|
+
// out of a provider's "context length exceeded" error so the agent can
|
|
20
|
+
// self-correct even when every source above was wrong.
|
|
21
|
+
//
|
|
22
|
+
// Networking is best-effort and never throws: offline runs silently fall
|
|
23
|
+
// back to the static table. The parsed catalog is held in a module singleton
|
|
24
|
+
// that config.ts reads SYNCHRONOUSLY — it stays empty until ensureModelCatalog()
|
|
25
|
+
// is called, so unit tests (which never call it) remain fully offline/static.
|
|
26
|
+
// ============================================================
|
|
27
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
28
|
+
if (k2 === undefined) k2 = k;
|
|
29
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
30
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
31
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
32
|
+
}
|
|
33
|
+
Object.defineProperty(o, k2, desc);
|
|
34
|
+
}) : (function(o, m, k, k2) {
|
|
35
|
+
if (k2 === undefined) k2 = k;
|
|
36
|
+
o[k2] = m[k];
|
|
37
|
+
}));
|
|
38
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
39
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
40
|
+
}) : function(o, v) {
|
|
41
|
+
o["default"] = v;
|
|
42
|
+
});
|
|
43
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
44
|
+
var ownKeys = function(o) {
|
|
45
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
46
|
+
var ar = [];
|
|
47
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
48
|
+
return ar;
|
|
49
|
+
};
|
|
50
|
+
return ownKeys(o);
|
|
51
|
+
};
|
|
52
|
+
return function (mod) {
|
|
53
|
+
if (mod && mod.__esModule) return mod;
|
|
54
|
+
var result = {};
|
|
55
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
56
|
+
__setModuleDefault(result, mod);
|
|
57
|
+
return result;
|
|
58
|
+
};
|
|
59
|
+
})();
|
|
60
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
61
|
+
exports.setCatalogForTest = setCatalogForTest;
|
|
62
|
+
exports.ensureModelCatalog = ensureModelCatalog;
|
|
63
|
+
exports.lookupModelInfo = lookupModelInfo;
|
|
64
|
+
exports.liveContextLimit = liveContextLimit;
|
|
65
|
+
exports.livePrice = livePrice;
|
|
66
|
+
exports.fetchEndpointContextLimit = fetchEndpointContextLimit;
|
|
67
|
+
exports.parseContextOverflow = parseContextOverflow;
|
|
68
|
+
const fs = __importStar(require("fs"));
|
|
69
|
+
const path = __importStar(require("path"));
|
|
70
|
+
const os = __importStar(require("os"));
|
|
71
|
+
const API_URL = 'https://models.dev/api.json';
|
|
72
|
+
const CACHE_PATH = path.join(os.homedir(), '.notsleep', 'models.dev.json');
|
|
73
|
+
const TTL_MS = 24 * 60 * 60 * 1000; // refresh at most once a day
|
|
74
|
+
const DEFAULT_FETCH_TIMEOUT_MS = 8000;
|
|
75
|
+
/**
|
|
76
|
+
* Map a NotSleep registry provider name to its models.dev provider id where
|
|
77
|
+
* they differ. Providers not on models.dev (together, fireworks, ollama,
|
|
78
|
+
* limitrouter, ...) simply miss and fall through to the next source.
|
|
79
|
+
*/
|
|
80
|
+
const PROVIDER_ALIAS = {
|
|
81
|
+
gemini: 'google',
|
|
82
|
+
};
|
|
83
|
+
let memoryCatalog = null;
|
|
84
|
+
/** Test / advanced hook: inject or clear the in-memory catalog directly. */
|
|
85
|
+
function setCatalogForTest(catalog) {
|
|
86
|
+
memoryCatalog = catalog;
|
|
87
|
+
}
|
|
88
|
+
function readDiskCache() {
|
|
89
|
+
try {
|
|
90
|
+
const obj = JSON.parse(fs.readFileSync(CACHE_PATH, 'utf-8'));
|
|
91
|
+
if (obj && typeof obj.fetchedAt === 'number' && obj.catalog)
|
|
92
|
+
return obj;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
/* no/invalid cache */
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
function writeDiskCache(catalog) {
|
|
100
|
+
try {
|
|
101
|
+
fs.mkdirSync(path.dirname(CACHE_PATH), { recursive: true });
|
|
102
|
+
fs.writeFileSync(CACHE_PATH, JSON.stringify({ fetchedAt: Date.now(), catalog }));
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
/* cache is best-effort */
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Ensure the model catalog is loaded into memory, refreshing from models.dev
|
|
110
|
+
* when the disk cache is missing or older than the TTL. Never throws: on any
|
|
111
|
+
* network/parse failure it falls back to a stale cache, or leaves the catalog
|
|
112
|
+
* empty (callers then use the static table). Returns the catalog or null.
|
|
113
|
+
*/
|
|
114
|
+
async function ensureModelCatalog(opts) {
|
|
115
|
+
if (memoryCatalog && !opts?.force)
|
|
116
|
+
return memoryCatalog;
|
|
117
|
+
const disk = readDiskCache();
|
|
118
|
+
const fresh = disk ? Date.now() - disk.fetchedAt < TTL_MS : false;
|
|
119
|
+
if (disk && fresh && !opts?.force) {
|
|
120
|
+
memoryCatalog = disk.catalog;
|
|
121
|
+
return memoryCatalog;
|
|
122
|
+
}
|
|
123
|
+
// Opt-out: never touch the network. Use a (possibly stale) disk cache if we
|
|
124
|
+
// have one, otherwise leave the catalog empty (callers use the static table).
|
|
125
|
+
const optOut = /^(1|true|yes)$/i.test(process.env.NOTSLEEP_NO_MODEL_SYNC || '');
|
|
126
|
+
if (optOut && !opts?.force) {
|
|
127
|
+
if (disk) {
|
|
128
|
+
memoryCatalog = disk.catalog;
|
|
129
|
+
return memoryCatalog;
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
// Cache missing or stale → try the network.
|
|
134
|
+
try {
|
|
135
|
+
const controller = new AbortController();
|
|
136
|
+
const timer = setTimeout(() => controller.abort(), opts?.timeoutMs ?? DEFAULT_FETCH_TIMEOUT_MS);
|
|
137
|
+
const res = await fetch(API_URL, { signal: controller.signal });
|
|
138
|
+
clearTimeout(timer);
|
|
139
|
+
if (res.ok) {
|
|
140
|
+
const catalog = (await res.json());
|
|
141
|
+
memoryCatalog = catalog;
|
|
142
|
+
writeDiskCache(catalog);
|
|
143
|
+
opts?.log?.(`Synced model catalog from models.dev (${Object.keys(catalog).length} providers).`);
|
|
144
|
+
return memoryCatalog;
|
|
145
|
+
}
|
|
146
|
+
opts?.log?.(`models.dev returned HTTP ${res.status}; using ${disk ? 'cached' : 'static'} model limits.`);
|
|
147
|
+
}
|
|
148
|
+
catch (err) {
|
|
149
|
+
opts?.log?.(`models.dev sync failed (${err?.message || err}); using ${disk ? 'cached' : 'static'} model limits.`);
|
|
150
|
+
}
|
|
151
|
+
// Fall back to a stale cache if we have one.
|
|
152
|
+
if (disk) {
|
|
153
|
+
memoryCatalog = disk.catalog;
|
|
154
|
+
return memoryCatalog;
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Look up a model in the in-memory catalog. Tries the provider-scoped entry
|
|
160
|
+
* first (with alias mapping), then a global scan by exact id, then a loose
|
|
161
|
+
* match (key ends with "/modelId", or the entry's own `id` matches) to handle
|
|
162
|
+
* aggregators like OpenRouter that key models as "vendor/model".
|
|
163
|
+
*/
|
|
164
|
+
function lookupModelInfo(providerName, modelId) {
|
|
165
|
+
if (!memoryCatalog || !modelId)
|
|
166
|
+
return null;
|
|
167
|
+
const pid = PROVIDER_ALIAS[providerName] ?? providerName;
|
|
168
|
+
const scoped = memoryCatalog[pid]?.models?.[modelId];
|
|
169
|
+
if (scoped)
|
|
170
|
+
return scoped;
|
|
171
|
+
// Exact id match anywhere.
|
|
172
|
+
for (const p of Object.keys(memoryCatalog)) {
|
|
173
|
+
const hit = memoryCatalog[p]?.models?.[modelId];
|
|
174
|
+
if (hit)
|
|
175
|
+
return hit;
|
|
176
|
+
}
|
|
177
|
+
// Loose match (last resort).
|
|
178
|
+
for (const p of Object.keys(memoryCatalog)) {
|
|
179
|
+
const models = memoryCatalog[p]?.models;
|
|
180
|
+
if (!models)
|
|
181
|
+
continue;
|
|
182
|
+
for (const key of Object.keys(models)) {
|
|
183
|
+
if (key.endsWith('/' + modelId) || models[key]?.id === modelId)
|
|
184
|
+
return models[key];
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
/** Live max context window for a model, or undefined if unknown. */
|
|
190
|
+
function liveContextLimit(providerName, modelId) {
|
|
191
|
+
const ctx = lookupModelInfo(providerName, modelId)?.limit?.context;
|
|
192
|
+
return typeof ctx === 'number' && ctx > 0 ? ctx : undefined;
|
|
193
|
+
}
|
|
194
|
+
/** Live per-1M pricing for a model, or undefined if unknown. */
|
|
195
|
+
function livePrice(providerName, modelId) {
|
|
196
|
+
const cost = lookupModelInfo(providerName, modelId)?.cost;
|
|
197
|
+
if (cost && typeof cost.input === 'number' && typeof cost.output === 'number') {
|
|
198
|
+
return { input: cost.input, output: cost.output };
|
|
199
|
+
}
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Query a provider's own OpenAI-style `GET {baseURL}/models` for a model's
|
|
204
|
+
* context window. Handles the common field spellings (OpenRouter's
|
|
205
|
+
* `context_length` / `top_provider.context_length`, etc). Best-effort:
|
|
206
|
+
* returns undefined on any failure. Used as a fallback for custom proxies
|
|
207
|
+
* and models that models.dev doesn't list.
|
|
208
|
+
*/
|
|
209
|
+
async function fetchEndpointContextLimit(baseURL, apiKey, modelId, timeoutMs = 6000) {
|
|
210
|
+
if (!baseURL || !modelId)
|
|
211
|
+
return undefined;
|
|
212
|
+
const url = baseURL.replace(/\/+$/, '') + '/models';
|
|
213
|
+
try {
|
|
214
|
+
const controller = new AbortController();
|
|
215
|
+
const timer = setTimeout(() => controller.abort(), timeoutMs);
|
|
216
|
+
const res = await fetch(url, {
|
|
217
|
+
headers: apiKey ? { Authorization: `Bearer ${apiKey}` } : {},
|
|
218
|
+
signal: controller.signal,
|
|
219
|
+
});
|
|
220
|
+
clearTimeout(timer);
|
|
221
|
+
if (!res.ok)
|
|
222
|
+
return undefined;
|
|
223
|
+
const body = await res.json();
|
|
224
|
+
const list = Array.isArray(body?.data) ? body.data : Array.isArray(body) ? body : [];
|
|
225
|
+
const m = list.find((x) => x?.id === modelId || x?.name === modelId);
|
|
226
|
+
if (!m)
|
|
227
|
+
return undefined;
|
|
228
|
+
const ctx = m.context_length ??
|
|
229
|
+
m.context_window ??
|
|
230
|
+
m.max_context_length ??
|
|
231
|
+
m?.top_provider?.context_length ??
|
|
232
|
+
m?.limit?.context;
|
|
233
|
+
return typeof ctx === 'number' && ctx > 0 ? ctx : undefined;
|
|
234
|
+
}
|
|
235
|
+
catch {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Extract the true maximum context length out of a provider's "context length
|
|
241
|
+
* exceeded" error message, so the agent can self-correct. Returns the model's
|
|
242
|
+
* max in tokens, or undefined if the message isn't a context-overflow error.
|
|
243
|
+
*
|
|
244
|
+
* Handles e.g.:
|
|
245
|
+
* OpenAI: "maximum context length is 128000 tokens. However, your
|
|
246
|
+
* messages resulted in 130512 tokens"
|
|
247
|
+
* Anthropic: "prompt is too long: 215000 tokens > 200000 maximum"
|
|
248
|
+
*/
|
|
249
|
+
function parseContextOverflow(message) {
|
|
250
|
+
if (!message)
|
|
251
|
+
return undefined;
|
|
252
|
+
const low = message.toLowerCase();
|
|
253
|
+
const isOverflow = /context length|context window|context_length_exceeded|maximum context|prompt is too long|too many tokens|reduce the length/.test(low);
|
|
254
|
+
if (!isOverflow)
|
|
255
|
+
return undefined;
|
|
256
|
+
// Collect token-sized numbers (>= 1000), commas allowed.
|
|
257
|
+
const nums = (message.match(/\d[\d,]{3,}/g) || [])
|
|
258
|
+
.map((s) => parseInt(s.replace(/,/g, ''), 10))
|
|
259
|
+
.filter((n) => Number.isFinite(n) && n >= 1000);
|
|
260
|
+
if (nums.length === 0)
|
|
261
|
+
return undefined;
|
|
262
|
+
// In "max is X but you sent Y", the limit is the smaller value (X < Y).
|
|
263
|
+
return Math.min(...nums);
|
|
264
|
+
}
|
|
265
|
+
//# sourceMappingURL=modelsdev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"modelsdev.js","sourceRoot":"","sources":["../src/modelsdev.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,4DAA4D;AAC5D,+DAA+D;AAC/D,EAAE;AACF,0EAA0E;AAC1E,2EAA2E;AAC3E,6EAA6E;AAC7E,wDAAwD;AACxD,EAAE;AACF,2EAA2E;AAC3E,uEAAuE;AACvE,uEAAuE;AACvE,4EAA4E;AAC5E,2EAA2E;AAC3E,+DAA+D;AAC/D,EAAE;AACF,4EAA4E;AAC5E,uEAAuE;AACvE,uDAAuD;AACvD,EAAE;AACF,yEAAyE;AACzE,6EAA6E;AAC7E,iFAAiF;AACjF,8EAA8E;AAC9E,+DAA+D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmC/D,8CAEC;AAgCD,gDAiDC;AAQD,0CAqBC;AAGD,4CAGC;AAGD,8BASC;AASD,8DAiCC;AAYD,oDA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|
|
|
1
|
+
import { WorktreeManager } from './worktree';
|
|
2
|
+
import { Logger } from './logger';
|
|
3
|
+
export interface ParallelTask {
|
|
4
|
+
id: string;
|
|
5
|
+
description: string;
|
|
6
|
+
}
|
|
7
|
+
export interface TaskRunContext {
|
|
8
|
+
task: ParallelTask;
|
|
9
|
+
/** The isolated worktree directory this task must run in. */
|
|
10
|
+
workdir: string;
|
|
11
|
+
/** The branch checked out in that worktree. */
|
|
12
|
+
branch: string;
|
|
13
|
+
}
|
|
14
|
+
/** Executes a single task inside its worktree. Should resolve on success. */
|
|
15
|
+
export type TaskRunner = (ctx: TaskRunContext) => Promise<void>;
|
|
16
|
+
export interface ParallelOptions {
|
|
17
|
+
/** Max tasks running at once. */
|
|
18
|
+
concurrency: number;
|
|
19
|
+
/** Merge each task's branch back into the base branch when it succeeds. */
|
|
20
|
+
merge?: boolean;
|
|
21
|
+
/** Delete a task's worktree after it finishes (branch is kept). Default true. */
|
|
22
|
+
cleanup?: boolean;
|
|
23
|
+
}
|
|
24
|
+
export interface ParallelTaskOutcome {
|
|
25
|
+
task: ParallelTask;
|
|
26
|
+
branch: string;
|
|
27
|
+
ok: boolean;
|
|
28
|
+
merged: boolean;
|
|
29
|
+
conflict: boolean;
|
|
30
|
+
error?: string;
|
|
31
|
+
note?: string;
|
|
32
|
+
}
|
|
33
|
+
export declare class ParallelRunner {
|
|
34
|
+
private readonly repoRoot;
|
|
35
|
+
private readonly logger;
|
|
36
|
+
private readonly wm;
|
|
37
|
+
constructor(repoRoot: string, logger: Logger, wm?: WorktreeManager);
|
|
38
|
+
/**
|
|
39
|
+
* Run all tasks with bounded concurrency, each in its own worktree.
|
|
40
|
+
* Returns one outcome per task (input order preserved).
|
|
41
|
+
*/
|
|
42
|
+
run(tasks: ParallelTask[], taskRunner: TaskRunner, options: ParallelOptions): Promise<ParallelTaskOutcome[]>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Production task runner: launches the notsleep one-shot CLI as a child
|
|
46
|
+
* process, with cwd set to the task's worktree. This gives OS-level isolation
|
|
47
|
+
* (separate process, separate cwd) so parallel agents share nothing mutable.
|
|
48
|
+
*
|
|
49
|
+
* @param nodeBin Path to node (usually process.execPath).
|
|
50
|
+
* @param cliEntry Path to the built CLI entry (dist/index.js).
|
|
51
|
+
* @param extraArgs Extra CLI args to forward (e.g. ['--max-iterations','30']).
|
|
52
|
+
*/
|
|
53
|
+
export declare function spawnAgentInWorktree(nodeBin: string, cliEntry: string, extraArgs: string[], logger: Logger): TaskRunner;
|
|
54
|
+
//# sourceMappingURL=parallel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parallel.d.ts","sourceRoot":"","sources":["../src/parallel.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,MAAM,WAAW,YAAY;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,6EAA6E;AAC7E,MAAM,MAAM,UAAU,GAAG,CAAC,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAEhE,MAAM,WAAW,eAAe;IAC9B,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,YAAY,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAkB;gBAEzB,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,eAAe;IAMlE;;;OAGG;IACG,GAAG,CACP,KAAK,EAAE,YAAY,EAAE,EACrB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,mBAAmB,EAAE,CAAC;CA4FlC;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EAAE,EACnB,MAAM,EAAE,MAAM,GACb,UAAU,CAmBZ"}
|
package/dist/parallel.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// NotSleep - Parallel task runner
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Runs multiple tasks CONCURRENTLY and SAFELY. Each task gets its own git
|
|
7
|
+
// worktree (isolated working directory + branch), so agents editing files at
|
|
8
|
+
// the same time can never clobber each other. After a task finishes, its
|
|
9
|
+
// branch is optionally merged back into the base branch; merge conflicts are
|
|
10
|
+
// aborted and the branch is kept for manual review rather than forcing a
|
|
11
|
+
// broken merge.
|
|
12
|
+
//
|
|
13
|
+
// The actual per-task execution is injected as `taskRunner`, which keeps this
|
|
14
|
+
// orchestrator fully unit-testable without spawning real agents or hitting the
|
|
15
|
+
// network. The production runner (spawnAgentInWorktree) launches the existing
|
|
16
|
+
// one-shot CLI as a child process with cwd set to the task's worktree.
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ParallelRunner = void 0;
|
|
19
|
+
exports.spawnAgentInWorktree = spawnAgentInWorktree;
|
|
20
|
+
const child_process_1 = require("child_process");
|
|
21
|
+
const worktree_1 = require("./worktree");
|
|
22
|
+
const pool_1 = require("./pool");
|
|
23
|
+
class ParallelRunner {
|
|
24
|
+
repoRoot;
|
|
25
|
+
logger;
|
|
26
|
+
wm;
|
|
27
|
+
constructor(repoRoot, logger, wm) {
|
|
28
|
+
this.repoRoot = repoRoot;
|
|
29
|
+
this.logger = logger;
|
|
30
|
+
this.wm = wm ?? new worktree_1.WorktreeManager(repoRoot);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Run all tasks with bounded concurrency, each in its own worktree.
|
|
34
|
+
* Returns one outcome per task (input order preserved).
|
|
35
|
+
*/
|
|
36
|
+
async run(tasks, taskRunner, options) {
|
|
37
|
+
await this.wm.assertGitRepo();
|
|
38
|
+
const cleanup = options.cleanup !== false; // default true
|
|
39
|
+
const merge = options.merge === true;
|
|
40
|
+
this.logger.info(`Parallel run: ${tasks.length} task(s), concurrency ${options.concurrency}, ` +
|
|
41
|
+
`merge=${merge}, cleanup=${cleanup}.`);
|
|
42
|
+
const outcomes = [];
|
|
43
|
+
const poolResults = await (0, pool_1.runPool)(tasks, options.concurrency, async (task) => {
|
|
44
|
+
const wt = await this.wm.add(task.id);
|
|
45
|
+
this.logger.info(`[${task.id}] worktree ready at ${wt.dir} (branch ${wt.branch}).`);
|
|
46
|
+
const outcome = {
|
|
47
|
+
task,
|
|
48
|
+
branch: wt.branch,
|
|
49
|
+
ok: false,
|
|
50
|
+
merged: false,
|
|
51
|
+
conflict: false,
|
|
52
|
+
};
|
|
53
|
+
try {
|
|
54
|
+
await taskRunner({ task, workdir: wt.dir, branch: wt.branch });
|
|
55
|
+
outcome.ok = true;
|
|
56
|
+
this.logger.info(`[${task.id}] finished.`);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
outcome.ok = false;
|
|
60
|
+
outcome.error = err?.message || String(err);
|
|
61
|
+
this.logger.error(`[${task.id}] failed: ${outcome.error}`);
|
|
62
|
+
}
|
|
63
|
+
// Merge only successful branches. A failed task's partial work stays on
|
|
64
|
+
// its branch for inspection and is never merged automatically.
|
|
65
|
+
if (outcome.ok && merge) {
|
|
66
|
+
try {
|
|
67
|
+
const m = await this.wm.mergeBranch(task.id);
|
|
68
|
+
outcome.merged = m.merged;
|
|
69
|
+
outcome.conflict = m.conflict;
|
|
70
|
+
outcome.note = m.message;
|
|
71
|
+
this.logger[m.conflict ? 'warn' : 'info'](`[${task.id}] ${m.message}`);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
outcome.note = `merge error: ${err?.message || String(err)}`;
|
|
75
|
+
this.logger.error(`[${task.id}] ${outcome.note}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// Remove the worktree directory. Keep the branch either way so commits
|
|
79
|
+
// are recoverable (successful-but-unmerged, or failed for review).
|
|
80
|
+
if (cleanup) {
|
|
81
|
+
await this.wm.remove(task.id, false).catch((e) => this.logger.warn(`[${task.id}] worktree cleanup failed: ${e.message}`));
|
|
82
|
+
}
|
|
83
|
+
return outcome;
|
|
84
|
+
}, (settled) => {
|
|
85
|
+
// Pool never throws, but a worker that somehow rejected still yields a
|
|
86
|
+
// PoolResult; surface a minimal outcome so counts stay correct.
|
|
87
|
+
if (!settled.ok && !settled.value) {
|
|
88
|
+
outcomes[settled.index] = {
|
|
89
|
+
task: settled.item,
|
|
90
|
+
branch: '(none)',
|
|
91
|
+
ok: false,
|
|
92
|
+
merged: false,
|
|
93
|
+
conflict: false,
|
|
94
|
+
error: settled.error?.message || 'unknown error',
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
for (const r of poolResults) {
|
|
99
|
+
outcomes[r.index] = r.value ?? outcomes[r.index];
|
|
100
|
+
}
|
|
101
|
+
const ok = outcomes.filter((o) => o && o.ok).length;
|
|
102
|
+
const merged = outcomes.filter((o) => o && o.merged).length;
|
|
103
|
+
const conflicts = outcomes.filter((o) => o && o.conflict).length;
|
|
104
|
+
this.logger.info(`Parallel run complete: ${ok}/${tasks.length} ok, ${merged} merged, ${conflicts} conflict(s).`);
|
|
105
|
+
return outcomes;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.ParallelRunner = ParallelRunner;
|
|
109
|
+
/**
|
|
110
|
+
* Production task runner: launches the notsleep one-shot CLI as a child
|
|
111
|
+
* process, with cwd set to the task's worktree. This gives OS-level isolation
|
|
112
|
+
* (separate process, separate cwd) so parallel agents share nothing mutable.
|
|
113
|
+
*
|
|
114
|
+
* @param nodeBin Path to node (usually process.execPath).
|
|
115
|
+
* @param cliEntry Path to the built CLI entry (dist/index.js).
|
|
116
|
+
* @param extraArgs Extra CLI args to forward (e.g. ['--max-iterations','30']).
|
|
117
|
+
*/
|
|
118
|
+
function spawnAgentInWorktree(nodeBin, cliEntry, extraArgs, logger) {
|
|
119
|
+
return (ctx) => new Promise((resolve, reject) => {
|
|
120
|
+
const args = [cliEntry, '--task-file', '-', ...extraArgs];
|
|
121
|
+
// We pass the task via a temp file rather than argv to avoid shell/quoting
|
|
122
|
+
// issues; but simplest portable approach: pass description as a single arg.
|
|
123
|
+
const child = (0, child_process_1.spawn)(nodeBin, [cliEntry, ctx.task.description, ...extraArgs], {
|
|
124
|
+
cwd: ctx.workdir,
|
|
125
|
+
stdio: 'inherit',
|
|
126
|
+
env: { ...process.env },
|
|
127
|
+
});
|
|
128
|
+
child.on('error', reject);
|
|
129
|
+
child.on('exit', (code) => {
|
|
130
|
+
if (code === 0)
|
|
131
|
+
resolve();
|
|
132
|
+
else
|
|
133
|
+
reject(new Error(`agent process exited with code ${code}`));
|
|
134
|
+
});
|
|
135
|
+
void args; // reserved for a future stdin-based task handoff
|
|
136
|
+
void logger;
|
|
137
|
+
});
|
|
138
|
+
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A4E;QAC5E,MAAM,KAAK,GAAG,IAAA,qBAAK,EAAC,OAAO,EAAE,CAAC,QAAQ,EAAE,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,SAAS,CAAC,EAAE;YAC3E,GAAG,EAAE,GAAG,CAAC,OAAO;YAChB,KAAK,EAAE,SAAS;YAChB,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE;SACxB,CAAC,CAAC;QACH,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC1B,KAAK,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YACxB,IAAI,IAAI,KAAK,CAAC;gBAAE,OAAO,EAAE,CAAC;;gBACrB,MAAM,CAAC,IAAI,KAAK,CAAC,kCAAkC,IAAI,EAAE,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC,CAAC;QACH,KAAK,IAAI,CAAC,CAAC,iDAAiD;QAC5D,KAAK,MAAM,CAAC;IACd,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/pool.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface PoolResult<T, R> {
|
|
2
|
+
item: T;
|
|
3
|
+
index: number;
|
|
4
|
+
ok: boolean;
|
|
5
|
+
value?: R;
|
|
6
|
+
error?: Error;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Process `items` with a worker, capping in-flight work at `concurrency`.
|
|
10
|
+
*
|
|
11
|
+
* @param items Work items.
|
|
12
|
+
* @param concurrency Max simultaneous workers (clamped to >= 1).
|
|
13
|
+
* @param worker Async fn producing a result for an item.
|
|
14
|
+
* @param onSettled Optional callback fired as each item finishes.
|
|
15
|
+
*/
|
|
16
|
+
export declare function runPool<T, R>(items: T[], concurrency: number, worker: (item: T, index: number) => Promise<R>, onSettled?: (result: PoolResult<T, R>) => void): Promise<PoolResult<T, R>[]>;
|
|
17
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU,CAAC,CAAC,EAAE,CAAC;IAC9B,IAAI,EAAE,CAAC,CAAC;IACR,KAAK,EAAE,MAAM,CAAC;IACd,EAAE,EAAE,OAAO,CAAC;IACZ,KAAK,CAAC,EAAE,CAAC,CAAC;IACV,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED;;;;;;;GAOG;AACH,wBAAsB,OAAO,CAAC,CAAC,EAAE,CAAC,EAChC,KAAK,EAAE,CAAC,EAAE,EACV,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,EAC9C,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,IAAI,GAC7C,OAAO,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CA8B7B"}
|
package/dist/pool.js
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// NotSleep - Bounded concurrency pool
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Runs async work over a list of items with at most `concurrency` running at
|
|
7
|
+
// once. Never rejects: each item's outcome is captured as ok/err so one
|
|
8
|
+
// failure can't sink the whole batch. Order of results matches input order.
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.runPool = runPool;
|
|
11
|
+
/**
|
|
12
|
+
* Process `items` with a worker, capping in-flight work at `concurrency`.
|
|
13
|
+
*
|
|
14
|
+
* @param items Work items.
|
|
15
|
+
* @param concurrency Max simultaneous workers (clamped to >= 1).
|
|
16
|
+
* @param worker Async fn producing a result for an item.
|
|
17
|
+
* @param onSettled Optional callback fired as each item finishes.
|
|
18
|
+
*/
|
|
19
|
+
async function runPool(items, concurrency, worker, onSettled) {
|
|
20
|
+
const limit = Math.max(1, Math.floor(concurrency) || 1);
|
|
21
|
+
const results = new Array(items.length);
|
|
22
|
+
let next = 0;
|
|
23
|
+
async function runWorkerLoop() {
|
|
24
|
+
while (true) {
|
|
25
|
+
const index = next++;
|
|
26
|
+
if (index >= items.length)
|
|
27
|
+
return;
|
|
28
|
+
const item = items[index];
|
|
29
|
+
let settled;
|
|
30
|
+
try {
|
|
31
|
+
const value = await worker(item, index);
|
|
32
|
+
settled = { item, index, ok: true, value };
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
settled = { item, index, ok: false, error: error instanceof Error ? error : new Error(String(error)) };
|
|
36
|
+
}
|
|
37
|
+
results[index] = settled;
|
|
38
|
+
if (onSettled) {
|
|
39
|
+
try {
|
|
40
|
+
onSettled(settled);
|
|
41
|
+
}
|
|
42
|
+
catch { /* callback errors never break the pool */ }
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const workerCount = Math.min(limit, items.length);
|
|
47
|
+
const loops = [];
|
|
48
|
+
for (let i = 0; i < workerCount; i++)
|
|
49
|
+
loops.push(runWorkerLoop());
|
|
50
|
+
await Promise.all(loops);
|
|
51
|
+
return results;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=pool.js.map
|
package/dist/pool.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,sCAAsC;AACtC,+DAA+D;AAC/D,EAAE;AACF,6EAA6E;AAC7E,wEAAwE;AACxE,4EAA4E;;AAkB5E,0BAmCC;AA3CD;;;;;;;GAOG;AACI,KAAK,UAAU,OAAO,CAC3B,KAAU,EACV,WAAmB,EACnB,MAA8C,EAC9C,SAA8C;IAE9C,MAAM,KAAK,GAAG,IA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;IAClC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE;QAAE,KAAK,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC;IAClE,MAAM,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAEzB,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AgentConfig, LLMResponse, Message, ToolDefinition } from './types';
|
|
2
|
+
import { Logger } from './logger';
|
|
3
|
+
/**
|
|
4
|
+
* Converts our ToolDefinition[] to provider-specific tool format.
|
|
5
|
+
* Handles retries with exponential backoff.
|
|
6
|
+
* Normalizes responses to a unified LLMResponse format.
|
|
7
|
+
*
|
|
8
|
+
* Supports two endpoints — primary (chat) and an optional cheaper small model
|
|
9
|
+
* (chatSmall) — which may be different providers entirely. Clients are built
|
|
10
|
+
* lazily and cached per (baseURL, apiKey), so a mixed setup (e.g. Anthropic
|
|
11
|
+
* primary + OpenAI small) works without extra wiring.
|
|
12
|
+
*/
|
|
13
|
+
export declare class LLMProvider {
|
|
14
|
+
private config;
|
|
15
|
+
private logger;
|
|
16
|
+
private readonly primary;
|
|
17
|
+
private readonly small?;
|
|
18
|
+
private openaiClients;
|
|
19
|
+
private anthropicClients;
|
|
20
|
+
constructor(config: AgentConfig, logger: Logger);
|
|
21
|
+
/** Build the primary endpoint from the resolved config blocks. */
|
|
22
|
+
private endpointFromConfig;
|
|
23
|
+
private getOpenAIClient;
|
|
24
|
+
private getAnthropicClient;
|
|
25
|
+
/**
|
|
26
|
+
* Send messages to the PRIMARY model and get a response.
|
|
27
|
+
* Automatically retries on transient errors with exponential backoff.
|
|
28
|
+
*/
|
|
29
|
+
chat(messages: Message[], tools: ToolDefinition[], opts?: {
|
|
30
|
+
maxRetries?: number;
|
|
31
|
+
maxDelayMs?: number;
|
|
32
|
+
}): Promise<LLMResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Send messages to the SMALL model (if configured), else the primary. Used
|
|
35
|
+
* for the agent's own internal calls — context summarization and follow-up
|
|
36
|
+
* task generation — so they run on a cheaper model when one is set.
|
|
37
|
+
*/
|
|
38
|
+
chatSmall(messages: Message[], tools: ToolDefinition[], opts?: {
|
|
39
|
+
maxRetries?: number;
|
|
40
|
+
maxDelayMs?: number;
|
|
41
|
+
}): Promise<LLMResponse>;
|
|
42
|
+
/** True when a distinct small model is configured. */
|
|
43
|
+
hasSmallModel(): boolean;
|
|
44
|
+
private callEndpoint;
|
|
45
|
+
private chatOpenAI;
|
|
46
|
+
private toOpenAIMessage;
|
|
47
|
+
private toOpenAITool;
|
|
48
|
+
private chatAnthropic;
|
|
49
|
+
private toAnthropicMessages;
|
|
50
|
+
private toAnthropicTool;
|
|
51
|
+
private isRetryableError;
|
|
52
|
+
private calculateBackoff;
|
|
53
|
+
/**
|
|
54
|
+
* Wrap common API errors with actionable, user-friendly messages so the
|
|
55
|
+
* operator can fix config issues without digging through raw HTTP bodies.
|
|
56
|
+
*/
|
|
57
|
+
private enhanceError;
|
|
58
|
+
private sleep;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,OAAO,EAAsB,cAAc,EAAE,MAAM,SAAS,CAAC;AAChG,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAclC;;;;;;;;;GASG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,MAAM,CAAS;IAEvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAW;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAW;IAElC,OAAO,CAAC,aAAa,CAA6B;IAClD,OAAO,CAAC,gBAAgB,CAAgC;gBAE5C,M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