agent-steward 0.0.2 → 0.0.4
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/CHANGELOG.md +45 -2
- package/CROSS_PLATFORM.md +11 -9
- package/README.md +11 -10
- package/ROADMAP-STRATEGY.md +93 -44
- package/ROADMAP.md +148 -1017
- package/dist/core/cron-to-schtasks.d.ts +0 -8
- package/dist/core/cron-to-schtasks.d.ts.map +1 -1
- package/dist/core/cron-to-schtasks.js +11 -86
- package/dist/core/dlq-api.d.ts +44 -0
- package/dist/core/dlq-api.d.ts.map +1 -0
- package/dist/core/dlq-api.js +68 -0
- package/dist/core/dry-run.d.ts.map +1 -1
- package/dist/core/dry-run.js +19 -2
- package/dist/core/file-watcher.js +9 -9
- package/dist/core/git-trigger.js +4 -4
- package/dist/core/lock.d.ts +20 -4
- package/dist/core/lock.d.ts.map +1 -1
- package/dist/core/lock.js +99 -26
- package/dist/core/one-shot.d.ts +31 -5
- package/dist/core/one-shot.d.ts.map +1 -1
- package/dist/core/one-shot.js +78 -10
- package/dist/core/opencode-cli.d.ts +28 -0
- package/dist/core/opencode-cli.d.ts.map +1 -0
- package/dist/core/opencode-cli.js +74 -0
- package/dist/core/opencode-models.d.ts +62 -0
- package/dist/core/opencode-models.d.ts.map +1 -0
- package/dist/core/opencode-models.js +277 -0
- package/dist/core/otel.js +2 -2
- package/dist/core/ps-wrapper.d.ts +1 -1
- package/dist/core/ps-wrapper.d.ts.map +1 -1
- package/dist/core/ps-wrapper.js +66 -36
- package/dist/core/record-history.d.ts +15 -0
- package/dist/core/record-history.d.ts.map +1 -1
- package/dist/core/record-history.js +78 -54
- package/dist/core/router/dispatch.d.ts +36 -0
- package/dist/core/router/dispatch.d.ts.map +1 -0
- package/dist/core/router/dispatch.js +59 -0
- package/dist/core/router/escalation.d.ts +47 -0
- package/dist/core/router/escalation.d.ts.map +1 -0
- package/dist/core/router/escalation.js +87 -0
- package/dist/core/router/planner.d.ts +53 -0
- package/dist/core/router/planner.d.ts.map +1 -0
- package/dist/core/router/planner.js +113 -0
- package/dist/core/router/rules.d.ts +46 -0
- package/dist/core/router/rules.d.ts.map +1 -0
- package/dist/core/router/rules.js +85 -0
- package/dist/core/run-panel-api.d.ts +94 -0
- package/dist/core/run-panel-api.d.ts.map +1 -0
- package/dist/core/run-panel-api.js +169 -0
- package/dist/core/schedule-gate.js +5 -1
- package/dist/core/schedule-v2.d.ts +36 -2
- package/dist/core/schedule-v2.d.ts.map +1 -1
- package/dist/core/schedule-v2.js +98 -12
- package/dist/core/scheduler/at-fallback.d.ts +95 -0
- package/dist/core/scheduler/at-fallback.d.ts.map +1 -0
- package/dist/core/scheduler/at-fallback.js +200 -0
- package/dist/core/scheduler/linux.d.ts +13 -2
- package/dist/core/scheduler/linux.d.ts.map +1 -1
- package/dist/core/scheduler/linux.js +67 -13
- package/dist/core/scheduler/mac.d.ts +14 -8
- package/dist/core/scheduler/mac.d.ts.map +1 -1
- package/dist/core/scheduler/mac.js +71 -22
- package/dist/core/scheduler/posix.d.ts.map +1 -1
- package/dist/core/scheduler/posix.js +37 -2
- package/dist/core/scheduler/registry.d.ts +13 -0
- package/dist/core/scheduler/registry.d.ts.map +1 -1
- package/dist/core/scheduler/registry.js +83 -21
- package/dist/core/scheduler/run-now.d.ts +16 -0
- package/dist/core/scheduler/run-now.d.ts.map +1 -0
- package/dist/core/scheduler/run-now.js +28 -0
- package/dist/core/scheduler/windows.d.ts +16 -3
- package/dist/core/scheduler/windows.d.ts.map +1 -1
- package/dist/core/scheduler/windows.js +249 -96
- package/dist/core/secrets.d.ts.map +1 -1
- package/dist/core/secrets.js +127 -30
- package/dist/core/self-analysis.js +55 -55
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +18 -11
- package/dist/core/summary.js +1 -1
- package/dist/core/task-name.d.ts +24 -0
- package/dist/core/task-name.d.ts.map +1 -0
- package/dist/core/task-name.js +40 -0
- package/dist/core/triage-chain.js +1 -1
- package/dist/core/triage-worker.js +2 -2
- package/dist/core/triage.js +1 -1
- package/dist/core/wrappers/bash.d.ts.map +1 -1
- package/dist/core/wrappers/bash.js +82 -37
- package/dist/db/capability-repo.d.ts +83 -0
- package/dist/db/capability-repo.d.ts.map +1 -0
- package/dist/db/capability-repo.js +182 -0
- package/dist/db/history-repo.d.ts +8 -0
- package/dist/db/history-repo.d.ts.map +1 -1
- package/dist/db/history-repo.js +19 -0
- package/dist/db/index.d.ts +6 -0
- package/dist/db/index.d.ts.map +1 -1
- package/dist/db/index.js +48 -2
- package/dist/db/migrate.d.ts.map +1 -1
- package/dist/db/migrate.js +3 -1
- package/dist/db/run-context.d.ts +103 -0
- package/dist/db/run-context.d.ts.map +1 -0
- package/dist/db/run-context.js +224 -0
- package/dist/db/run-dlq.d.ts +100 -0
- package/dist/db/run-dlq.d.ts.map +1 -0
- package/dist/db/run-dlq.js +191 -0
- package/dist/db/run-journal.d.ts +60 -0
- package/dist/db/run-journal.d.ts.map +1 -0
- package/dist/db/run-journal.js +143 -0
- package/dist/db/run-resume.d.ts +51 -0
- package/dist/db/run-resume.d.ts.map +1 -0
- package/dist/db/run-resume.js +156 -0
- package/dist/db/runs-repo.d.ts +128 -0
- package/dist/db/runs-repo.d.ts.map +1 -0
- package/dist/db/runs-repo.js +342 -0
- package/dist/db/schema.d.ts +16 -2
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +342 -35
- package/dist/db/settings-repo.d.ts +11 -0
- package/dist/db/settings-repo.d.ts.map +1 -1
- package/dist/db/settings-repo.js +25 -0
- package/dist/db/step-idempotency.d.ts +51 -0
- package/dist/db/step-idempotency.d.ts.map +1 -0
- package/dist/db/step-idempotency.js +136 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +168 -40
- package/dist/notifications.js +18 -18
- package/dist/profiles.d.ts +7 -3
- package/dist/profiles.d.ts.map +1 -1
- package/dist/profiles.js +85 -7
- package/dist/rpc.d.ts +787 -0
- package/dist/rpc.d.ts.map +1 -1
- package/dist/rpc.js +324 -0
- package/dist/server.d.ts +33 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +115 -54
- package/dist/shared/jobs-view.d.ts.map +1 -1
- package/dist/skill.js +1 -1
- package/dist/task-transfer.d.ts +1 -1
- package/dist/task-transfer.d.ts.map +1 -1
- package/dist/task-transfer.js +14 -10
- package/dist/types.d.ts +20 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +44 -9
- package/dist/workspaces.d.ts +25 -3
- package/dist/workspaces.d.ts.map +1 -1
- package/dist/workspaces.js +44 -9
- package/docs/ARCHITECTURE.md +335 -9
- package/docs/COMPATIBILITY.md +10 -6
- package/docs/CONCEPT.md +183 -91
- package/docs/CROSS_PLATFORM.ru.md +11 -9
- package/docs/CROSS_PLATFORM.zh.md +11 -9
- package/docs/EXECUTION-LOOP.md +196 -0
- package/docs/FAQ.md +2 -2
- package/docs/FAQ.ru.md +2 -2
- package/docs/FAQ.zh.md +2 -2
- package/docs/FEATURES.md +5 -4
- package/docs/FEATURES.zh.md +5 -4
- package/docs/MIGRATION.md +34 -26
- package/docs/README.ru.md +27 -8
- package/docs/README.zh.md +11 -10
- package/docs/SAFETY.md +122 -0
- package/docs/SAVINGS.md +29 -0
- package/docs/SAVINGS.ru.md +29 -0
- package/docs/SAVINGS.zh.md +18 -0
- package/docs/V1-V2-COMPATIBILITY-PLAN.md +6 -6
- package/gui-experimental.cjs +8 -8
- package/index.js +1 -0
- package/locales/en.json +68 -0
- package/locales/ru.json +68 -0
- package/locales/zh.json +68 -0
- package/package.json +57 -11
- package/scripts/audit-bundle.mjs +215 -0
- package/src/core/analytics.ts +2 -2
- package/src/core/audit.ts +17 -17
- package/src/core/cron-to-schtasks.ts +14 -93
- package/src/core/dlq-api.ts +98 -0
- package/src/core/dry-run.ts +51 -27
- package/src/core/file-watcher.ts +17 -17
- package/src/core/git-trigger.ts +9 -9
- package/src/core/glob.ts +1 -1
- package/src/core/local-ai.ts +2 -2
- package/src/core/lock.ts +104 -31
- package/src/core/matrix.ts +31 -31
- package/src/core/native-notify.ts +2 -2
- package/src/core/one-shot.ts +91 -13
- package/src/core/opencode-cli.ts +103 -0
- package/src/core/opencode-models.ts +315 -0
- package/src/core/otel.ts +4 -4
- package/src/core/permissions.ts +5 -5
- package/src/core/prometheus.ts +17 -17
- package/src/core/ps-wrapper.ts +68 -38
- package/src/core/record-history.ts +114 -76
- package/src/core/retention.ts +3 -3
- package/src/core/router/dispatch.ts +94 -0
- package/src/core/router/escalation.ts +129 -0
- package/src/core/router/planner.ts +166 -0
- package/src/core/router/rules.ts +109 -0
- package/src/core/run-panel-api.ts +262 -0
- package/src/core/savings.ts +1 -1
- package/src/core/schedule-gate.ts +17 -13
- package/src/core/schedule-v2.ts +138 -29
- package/src/core/scheduler/at-fallback.ts +298 -0
- package/src/core/scheduler/index.ts +3 -3
- package/src/core/scheduler/linux.ts +92 -19
- package/src/core/scheduler/logs.ts +1 -1
- package/src/core/scheduler/mac.ts +112 -60
- package/src/core/scheduler/posix.ts +35 -2
- package/src/core/scheduler/registry.ts +109 -26
- package/src/core/scheduler/run-now.ts +32 -0
- package/src/core/scheduler/windows.ts +295 -125
- package/src/core/secrets.ts +139 -39
- package/src/core/self-analysis.ts +61 -61
- package/src/core/session.ts +26 -13
- package/src/core/structured-log.ts +3 -3
- package/src/core/summary.ts +25 -25
- package/src/core/task-name.ts +67 -0
- package/src/core/telegram.ts +16 -16
- package/src/core/triage-chain.ts +4 -4
- package/src/core/triage-compare.ts +8 -8
- package/src/core/triage-rules.ts +4 -4
- package/src/core/triage-shadow.ts +7 -7
- package/src/core/triage-worker.ts +6 -6
- package/src/core/triage.ts +23 -23
- package/src/core/watch-paths.ts +1 -1
- package/src/core/wrappers/bash.ts +90 -45
- package/src/db/capability-repo.ts +285 -0
- package/src/db/git-state-repo.ts +1 -1
- package/src/db/history-repo.ts +44 -22
- package/src/db/index.ts +53 -7
- package/src/db/metrics-repo.ts +10 -10
- package/src/db/migrate.ts +13 -11
- package/src/db/recovery.ts +3 -3
- package/src/db/run-context.ts +370 -0
- package/src/db/run-dlq.ts +310 -0
- package/src/db/run-journal.ts +212 -0
- package/src/db/run-resume.ts +256 -0
- package/src/db/runs-repo.ts +504 -0
- package/src/db/schema.ts +357 -44
- package/src/db/settings-repo.ts +33 -2
- package/src/db/step-idempotency.ts +185 -0
- package/src/db/tasks-repo.ts +10 -10
- package/src/db/templates-repo.ts +7 -7
- package/src/gui.tsx +516 -1
- package/src/history.ts +4 -4
- package/src/i18n.ts +7 -7
- package/src/index.ts +465 -308
- package/src/integrations.ts +6 -6
- package/src/notifications.ts +76 -76
- package/src/profiles.ts +98 -7
- package/src/rpc.ts +347 -1
- package/src/schtasks.ts +2 -2
- package/src/server.ts +155 -78
- package/src/settings.ts +44 -44
- package/src/shared/jobs-view.ts +60 -60
- package/src/skill.ts +1 -1
- package/src/task-transfer.ts +58 -56
- package/src/templates.ts +1 -1
- package/src/types.ts +54 -10
- package/src/workspaces.ts +73 -24
- package/dist/core/self-analysis.test.d.ts +0 -2
- package/dist/core/self-analysis.test.d.ts.map +0 -1
- package/dist/core/self-analysis.test.js +0 -219
- package/dist/gui-experimental.cjs +0 -1
package/dist/notifications.js
CHANGED
|
@@ -281,12 +281,12 @@ async function deliverDetailed(config, message, only) {
|
|
|
281
281
|
webhook.url.trim()) {
|
|
282
282
|
try {
|
|
283
283
|
await sendWebhook(webhook.url, message, webhookOptionsFrom(config));
|
|
284
|
-
console.log("[
|
|
284
|
+
console.log("[agent-steward] Уведомление отправлено в webhook.");
|
|
285
285
|
results.push({ channel: "webhook", ok: true });
|
|
286
286
|
}
|
|
287
287
|
catch (err) {
|
|
288
288
|
const text = err instanceof Error ? err.message : String(err);
|
|
289
|
-
console.error(`[
|
|
289
|
+
console.error(`[agent-steward] Webhook: ${text}`);
|
|
290
290
|
results.push({ channel: "webhook", ok: false, error: text });
|
|
291
291
|
}
|
|
292
292
|
}
|
|
@@ -295,7 +295,7 @@ async function deliverDetailed(config, message, only) {
|
|
|
295
295
|
const { token, chatId } = telegramCredentials(config);
|
|
296
296
|
if (!token || !chatId) {
|
|
297
297
|
const text = t("notify.error.telegramNoCreds");
|
|
298
|
-
console.error(`[
|
|
298
|
+
console.error(`[agent-steward] ${text}`);
|
|
299
299
|
results.push({ channel: "telegram", ok: false, error: text });
|
|
300
300
|
}
|
|
301
301
|
else {
|
|
@@ -308,12 +308,12 @@ async function deliverDetailed(config, message, only) {
|
|
|
308
308
|
includeDashboardLink: telegram.includeDashboardLink,
|
|
309
309
|
dashboardUrl,
|
|
310
310
|
});
|
|
311
|
-
console.log("[
|
|
311
|
+
console.log("[agent-steward] Уведомление отправлено в Telegram.");
|
|
312
312
|
results.push({ channel: "telegram", ok: true });
|
|
313
313
|
}
|
|
314
314
|
catch (err) {
|
|
315
315
|
const text = err instanceof Error ? err.message : String(err);
|
|
316
|
-
console.error(`[
|
|
316
|
+
console.error(`[agent-steward] Telegram: ${text}`);
|
|
317
317
|
results.push({ channel: "telegram", ok: false, error: text });
|
|
318
318
|
}
|
|
319
319
|
}
|
|
@@ -322,12 +322,12 @@ async function deliverDetailed(config, message, only) {
|
|
|
322
322
|
if ((!only || only === "native") && config.enabled && native?.enabled) {
|
|
323
323
|
const result = await sendNativeNotification({ title: t("notify.native.title"), body: message, sound: native.sound }, {});
|
|
324
324
|
if (result.success) {
|
|
325
|
-
console.log("[
|
|
325
|
+
console.log("[agent-steward] Нативное уведомление показано.");
|
|
326
326
|
results.push({ channel: "native", ok: true });
|
|
327
327
|
}
|
|
328
328
|
else {
|
|
329
329
|
const text = result.error ?? t("notify.error.nativeFailed");
|
|
330
|
-
console.error(`[
|
|
330
|
+
console.error(`[agent-steward] Нативное уведомление: ${text}`);
|
|
331
331
|
results.push({ channel: "native", ok: false, error: text });
|
|
332
332
|
}
|
|
333
333
|
}
|
|
@@ -340,7 +340,7 @@ async function deliver(config, message) {
|
|
|
340
340
|
}
|
|
341
341
|
/** Ключ дедупа: комбинация задачи и статуса. */
|
|
342
342
|
function dedupKey(taskName, status) {
|
|
343
|
-
return (taskName +
|
|
343
|
+
return (taskName + "|" + status).toLowerCase();
|
|
344
344
|
}
|
|
345
345
|
/** Читает или создаёт запись дедупа. Возвращает { record, isDuplicate }.
|
|
346
346
|
* Если записи нет или окно истекло — создаёт новую с count=1.
|
|
@@ -409,7 +409,7 @@ function isDedupSuppressed(status, dedup) {
|
|
|
409
409
|
function messageWithDedupCount(message, count) {
|
|
410
410
|
if (count <= 1)
|
|
411
411
|
return message;
|
|
412
|
-
return message +
|
|
412
|
+
return message + " " + t("notify.dedup.count", { count });
|
|
413
413
|
}
|
|
414
414
|
/** Размерность вектора фиксирована: feature hashing, а не словарь сообщения. */
|
|
415
415
|
const EMBEDDING_DIMENSION = 512;
|
|
@@ -423,7 +423,7 @@ function fnv1a32(value) {
|
|
|
423
423
|
return hash >>> 0;
|
|
424
424
|
}
|
|
425
425
|
function embeddingKey(taskName, status) {
|
|
426
|
-
return `emb:${(taskName +
|
|
426
|
+
return `emb:${(taskName + "|" + status).toLowerCase()}`;
|
|
427
427
|
}
|
|
428
428
|
/** Простой токенизатор: слова, цифры, нижний регистр. */
|
|
429
429
|
function tokenize(text) {
|
|
@@ -570,12 +570,12 @@ export async function notifyTaskCompletion(taskName, status, durationMs, error,
|
|
|
570
570
|
// Injected scheduler может быть асинхронным — не оставляем rejection.
|
|
571
571
|
if (job && typeof job.then === "function") {
|
|
572
572
|
void Promise.resolve(job).catch((err) => {
|
|
573
|
-
console.error(`[
|
|
573
|
+
console.error(`[agent-steward] Ошибка фонового триажа: ${err instanceof Error ? err.message : String(err)}`);
|
|
574
574
|
});
|
|
575
575
|
}
|
|
576
576
|
}
|
|
577
577
|
catch (err) {
|
|
578
|
-
console.error(`[
|
|
578
|
+
console.error(`[agent-steward] Не удалось запустить фоновый триаж: ${err instanceof Error ? err.message : String(err)}`);
|
|
579
579
|
}
|
|
580
580
|
}
|
|
581
581
|
else if (mode !== "off") {
|
|
@@ -642,7 +642,7 @@ export async function notifyTaskCompletion(taskName, status, durationMs, error,
|
|
|
642
642
|
}
|
|
643
643
|
catch (err) {
|
|
644
644
|
// Уведомление не должно ломать запись истории и саму задачу.
|
|
645
|
-
console.error(`[
|
|
645
|
+
console.error(`[agent-steward] Ошибка подготовки уведомления: ${err instanceof Error ? err.message : String(err)}`);
|
|
646
646
|
}
|
|
647
647
|
}
|
|
648
648
|
/**
|
|
@@ -674,7 +674,7 @@ export async function notifyMatrixCompletion(info) {
|
|
|
674
674
|
await deliver(config, formatMatrixMessage(info));
|
|
675
675
|
}
|
|
676
676
|
catch (err) {
|
|
677
|
-
console.error(`[
|
|
677
|
+
console.error(`[agent-steward] Ошибка уведомления о матрице: ${err instanceof Error ? err.message : String(err)}`);
|
|
678
678
|
}
|
|
679
679
|
}
|
|
680
680
|
/**
|
|
@@ -729,7 +729,7 @@ export async function notifyStuckMatrix(stuck) {
|
|
|
729
729
|
return await deliver(config, formatStuckMatrixMessage(stuck));
|
|
730
730
|
}
|
|
731
731
|
catch (err) {
|
|
732
|
-
console.error(`[
|
|
732
|
+
console.error(`[agent-steward] Ошибка уведомления о зависшей матрице: ${err instanceof Error ? err.message : String(err)}`);
|
|
733
733
|
return false;
|
|
734
734
|
}
|
|
735
735
|
}
|
|
@@ -894,14 +894,14 @@ export async function maybeSendDigest(now = new Date()) {
|
|
|
894
894
|
return false;
|
|
895
895
|
const result = await sendDigestNow({ now, updateLastSentAt: true });
|
|
896
896
|
if (result.success) {
|
|
897
|
-
console.log("[
|
|
897
|
+
console.log("[agent-steward] Дайджест уведомлений отправлен.");
|
|
898
898
|
return true;
|
|
899
899
|
}
|
|
900
|
-
console.error(`[
|
|
900
|
+
console.error(`[agent-steward] Дайджест не отправлен: ${result.message}`);
|
|
901
901
|
return false;
|
|
902
902
|
}
|
|
903
903
|
catch (err) {
|
|
904
|
-
console.error(`[
|
|
904
|
+
console.error(`[agent-steward] Ошибка дайджеста: ${err instanceof Error ? err.message : String(err)}`);
|
|
905
905
|
return false;
|
|
906
906
|
}
|
|
907
907
|
}
|
package/dist/profiles.d.ts
CHANGED
|
@@ -21,10 +21,14 @@ export interface ProfileInfo {
|
|
|
21
21
|
/**
|
|
22
22
|
* Базовая директория плагина (до профилей).
|
|
23
23
|
*
|
|
24
|
-
* Windows: %APPDATA%\opencode\
|
|
25
|
-
* macOS/Linux: $XDG_CONFIG_HOME/opencode/
|
|
26
|
-
* ~/.config/opencode/
|
|
24
|
+
* Windows: %APPDATA%\opencode\agent-steward.
|
|
25
|
+
* macOS/Linux: $XDG_CONFIG_HOME/opencode/agent-steward или
|
|
26
|
+
* ~/.config/opencode/agent-steward.
|
|
27
27
|
* OPENCODE_SCHEDULER_HOME переопределяет всё (тесты, кастомные установки).
|
|
28
|
+
*
|
|
29
|
+
* При первом запуске после переименования данные из исторической
|
|
30
|
+
* .../opencode/windows-scheduler копируются в новую директорию (legacy
|
|
31
|
+
* остаётся на месте как резервная копия).
|
|
28
32
|
*/
|
|
29
33
|
export declare function getBasePluginDir(): string;
|
|
30
34
|
/** Нормализует имя профиля: нижний регистр, только [a-z0-9_-]. */
|
package/dist/profiles.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AAEH,eAAO,MAAM,eAAe,YAAY,CAAC;AAKzC,+CAA+C;AAC/C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../src/profiles.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AAEH,eAAO,MAAM,eAAe,YAAY,CAAC;AAKzC,+CAA+C;AAC/C,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED,oCAAoC;AACpC,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACjB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,CAsBzC;AA8ED,kEAAkE;AAClE,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAQ5E;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAOhE;AAYD;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAIvC;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,IAAI,GAAE,MAAyB,GAAG,MAAM,CAKrE;AAOD,uEAAuE;AACvE,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAahE;AAED,mFAAmF;AACnF,wBAAgB,cAAc,CAAC,IAAI,GAAE,MAAyB,GAAG,MAAM,GAAG,IAAI,CAQ7E;AAED,4DAA4D;AAC5D,wBAAgB,YAAY,IAAI,WAAW,EAAE,CA6B5C;AAcD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,CAkBtE;AAED,iFAAiF;AACjF,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAiClE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAQnD;AAED,iFAAiF;AACjF,wBAAgB,oBAAoB,IAAI,OAAO,CAE9C"}
|
package/dist/profiles.js
CHANGED
|
@@ -13,21 +13,99 @@ const ACTIVE_PROFILE_FILE = "active-profile";
|
|
|
13
13
|
/**
|
|
14
14
|
* Базовая директория плагина (до профилей).
|
|
15
15
|
*
|
|
16
|
-
* Windows: %APPDATA%\opencode\
|
|
17
|
-
* macOS/Linux: $XDG_CONFIG_HOME/opencode/
|
|
18
|
-
* ~/.config/opencode/
|
|
16
|
+
* Windows: %APPDATA%\opencode\agent-steward.
|
|
17
|
+
* macOS/Linux: $XDG_CONFIG_HOME/opencode/agent-steward или
|
|
18
|
+
* ~/.config/opencode/agent-steward.
|
|
19
19
|
* OPENCODE_SCHEDULER_HOME переопределяет всё (тесты, кастомные установки).
|
|
20
|
+
*
|
|
21
|
+
* При первом запуске после переименования данные из исторической
|
|
22
|
+
* .../opencode/windows-scheduler копируются в новую директорию (legacy
|
|
23
|
+
* остаётся на месте как резервная копия).
|
|
20
24
|
*/
|
|
21
25
|
export function getBasePluginDir() {
|
|
22
26
|
const custom = process.env.OPENCODE_SCHEDULER_HOME?.trim();
|
|
23
27
|
if (custom)
|
|
24
28
|
return path.resolve(custom);
|
|
29
|
+
const root = path.join(pluginConfigRoot(), "opencode");
|
|
30
|
+
const target = path.join(root, "agent-steward");
|
|
31
|
+
const legacy = path.join(root, "windows-scheduler");
|
|
32
|
+
if (fs.existsSync(target) || !fs.existsSync(legacy))
|
|
33
|
+
return target;
|
|
34
|
+
try {
|
|
35
|
+
migrateLegacyBaseDir(legacy, target);
|
|
36
|
+
return target;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
// Не теряем доступ к данным: продолжаем работать в старой директории.
|
|
40
|
+
console.error(`[agent-steward] Не удалось перенести данные из "${legacy}" в "${target}": ${error instanceof Error ? error.message : String(error)}. Использую старую директорию.`);
|
|
41
|
+
return legacy;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Корень конфигурации пользователя (без .../opencode). */
|
|
45
|
+
function pluginConfigRoot() {
|
|
25
46
|
if (process.platform === "win32") {
|
|
26
|
-
|
|
27
|
-
return path.join(base, "opencode", "windows-scheduler");
|
|
47
|
+
return process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming");
|
|
28
48
|
}
|
|
29
|
-
|
|
30
|
-
|
|
49
|
+
return process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
|
|
50
|
+
}
|
|
51
|
+
const MIGRATION_MARKER = ".migrated-from-windows-scheduler";
|
|
52
|
+
/** Расширения текстовых файлов, в которых могут быть абсолютные пути. */
|
|
53
|
+
const PATH_REWRITE_EXTENSIONS = new Set([
|
|
54
|
+
".json",
|
|
55
|
+
".cmd",
|
|
56
|
+
".sh",
|
|
57
|
+
".bash",
|
|
58
|
+
".ps1",
|
|
59
|
+
".txt",
|
|
60
|
+
]);
|
|
61
|
+
/**
|
|
62
|
+
* Копирует legacy-директорию в новую и переписывает в текстовых файлах
|
|
63
|
+
* абсолютные пути старой директории на новую. Копия делается во временную
|
|
64
|
+
* директорию и переименовывается атомарно, чтобы не оставить половину данных.
|
|
65
|
+
*/
|
|
66
|
+
function migrateLegacyBaseDir(legacy, target) {
|
|
67
|
+
const temp = `${target}.migrating-${process.pid}`;
|
|
68
|
+
fs.rmSync(temp, { recursive: true, force: true });
|
|
69
|
+
fs.cpSync(legacy, temp, { recursive: true });
|
|
70
|
+
rewriteAbsolutePaths(temp, legacy, target);
|
|
71
|
+
fs.writeFileSync(path.join(temp, MIGRATION_MARKER), `${new Date().toISOString()}\n`, "utf8");
|
|
72
|
+
try {
|
|
73
|
+
fs.renameSync(temp, target);
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
fs.rmSync(temp, { recursive: true, force: true });
|
|
77
|
+
// Параллельный процесс мог успеть создать target — это не ошибка.
|
|
78
|
+
if (fs.existsSync(target))
|
|
79
|
+
return;
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function rewriteAbsolutePaths(root, from, to) {
|
|
84
|
+
const variants = [
|
|
85
|
+
from,
|
|
86
|
+
from.replace(/\\/g, "/"),
|
|
87
|
+
from.replace(/\\/g, "\\\\"),
|
|
88
|
+
].filter((value, index, all) => value && all.indexOf(value) === index);
|
|
89
|
+
const walk = (dir) => {
|
|
90
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
91
|
+
const full = path.join(dir, entry.name);
|
|
92
|
+
if (entry.isDirectory()) {
|
|
93
|
+
walk(full);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (!PATH_REWRITE_EXTENSIONS.has(path.extname(entry.name).toLowerCase())) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
const text = fs.readFileSync(full, "utf8");
|
|
100
|
+
let next = text;
|
|
101
|
+
for (const variant of variants) {
|
|
102
|
+
next = next.split(variant).join(variant.includes("\\\\") ? to.replace(/\\/g, "\\\\") : variant.includes("/") ? to.replace(/\\/g, "/") : to);
|
|
103
|
+
}
|
|
104
|
+
if (next !== text)
|
|
105
|
+
fs.writeFileSync(full, next, "utf8");
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
walk(root);
|
|
31
109
|
}
|
|
32
110
|
/** Нормализует имя профиля: нижний регистр, только [a-z0-9_-]. */
|
|
33
111
|
export function sanitizeProfileName(value) {
|