@ai-setting/roy-agent-cli 1.7.37 → 1.7.38
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/bin/roy-agent.js +222 -58
- package/dist/index.js +222 -58
- package/dist/roy-agent-linux-x64/bin/roy-agent +2 -2
- package/package.json +1 -1
package/dist/bin/roy-agent.js
CHANGED
|
@@ -9461,7 +9461,7 @@ class CliQuietModeService {
|
|
|
9461
9461
|
// package.json
|
|
9462
9462
|
var package_default = {
|
|
9463
9463
|
name: "@ai-setting/roy-agent-cli",
|
|
9464
|
-
version: "1.7.
|
|
9464
|
+
version: "1.7.38",
|
|
9465
9465
|
type: "module",
|
|
9466
9466
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
9467
9467
|
main: "./dist/index.js",
|
|
@@ -11527,6 +11527,12 @@ function extractChatId(event) {
|
|
|
11527
11527
|
return;
|
|
11528
11528
|
}
|
|
11529
11529
|
|
|
11530
|
+
// src/commands/shared/event-handler-wiring.ts
|
|
11531
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
11532
|
+
import { join } from "node:path";
|
|
11533
|
+
import { homedir } from "node:os";
|
|
11534
|
+
import { EventStoreImpl, setSharedEventStore } from "@ai-setting/roy-agent-core/env/event-source/event-store";
|
|
11535
|
+
|
|
11530
11536
|
// src/commands/shared/event-handler.ts
|
|
11531
11537
|
import { TracedAs as TracedAs5 } from "@ai-setting/roy-agent-core";
|
|
11532
11538
|
class EventHandler {
|
|
@@ -11543,6 +11549,8 @@ class EventHandler {
|
|
|
11543
11549
|
unsubscribe = null;
|
|
11544
11550
|
sessionComponent = null;
|
|
11545
11551
|
activeEventSessionId = null;
|
|
11552
|
+
eventStore = null;
|
|
11553
|
+
getHandlerForEsType = null;
|
|
11546
11554
|
constructor(options) {
|
|
11547
11555
|
this.env = options.env;
|
|
11548
11556
|
this.eventTypes = options.eventTypes;
|
|
@@ -11552,6 +11560,8 @@ class EventHandler {
|
|
|
11552
11560
|
this.isIdle = options.isIdle ?? (() => true);
|
|
11553
11561
|
this.idleCheckInterval = options.idleCheckInterval ?? 100;
|
|
11554
11562
|
this.sessionComponent = options.sessionComponent ?? null;
|
|
11563
|
+
this.eventStore = options.eventStore ?? null;
|
|
11564
|
+
this.getHandlerForEsType = options.getHandlerForEsType ?? null;
|
|
11555
11565
|
}
|
|
11556
11566
|
start() {
|
|
11557
11567
|
this.isStopped = false;
|
|
@@ -11589,13 +11599,94 @@ class EventHandler {
|
|
|
11589
11599
|
this.isProcessing = false;
|
|
11590
11600
|
this.clearActiveSession();
|
|
11591
11601
|
}
|
|
11592
|
-
handleEvent(event) {
|
|
11602
|
+
async handleEvent(event) {
|
|
11593
11603
|
if (this.isStopped) {
|
|
11594
11604
|
return;
|
|
11595
11605
|
}
|
|
11596
|
-
const formatted = this.
|
|
11606
|
+
const formatted = await this.formatEvent(event);
|
|
11597
11607
|
this.enqueue(formatted);
|
|
11598
11608
|
}
|
|
11609
|
+
async formatEvent(event) {
|
|
11610
|
+
if (event.type.startsWith("task.background.") && event.metadata?.triggerEventId && this.eventStore && this.getHandlerForEsType) {
|
|
11611
|
+
try {
|
|
11612
|
+
const v2Formatted = await this.formatEventViaESPluginV2(event);
|
|
11613
|
+
if (v2Formatted) {
|
|
11614
|
+
return v2Formatted;
|
|
11615
|
+
}
|
|
11616
|
+
} catch (err) {
|
|
11617
|
+
console.error(`[EventHandler] ESPlugin v2 path failed, falling back to formatter`, err);
|
|
11618
|
+
}
|
|
11619
|
+
}
|
|
11620
|
+
return this.formatter.formatWithEvent(event);
|
|
11621
|
+
}
|
|
11622
|
+
async formatEventViaESPluginV2(event) {
|
|
11623
|
+
const triggerEventId = event.metadata.triggerEventId;
|
|
11624
|
+
const triggerEvent = await this.eventStore.getEventById(triggerEventId);
|
|
11625
|
+
if (!triggerEvent) {
|
|
11626
|
+
return null;
|
|
11627
|
+
}
|
|
11628
|
+
const handler = this.getHandlerForEsType(triggerEvent.esType);
|
|
11629
|
+
if (!handler || !handler.buildNotifyHandlePrompt) {
|
|
11630
|
+
return null;
|
|
11631
|
+
}
|
|
11632
|
+
const payload = event.payload;
|
|
11633
|
+
const subAgentResult = {
|
|
11634
|
+
summary: typeof payload?.result === "string" ? payload.result : typeof payload?.error === "string" ? payload.error : "(无结果)"
|
|
11635
|
+
};
|
|
11636
|
+
const profile = triggerEvent.metadata?.profile ?? undefined;
|
|
11637
|
+
const prompt = handler.buildNotifyHandlePrompt({
|
|
11638
|
+
notifyEvent: {
|
|
11639
|
+
type: event.type,
|
|
11640
|
+
taskId: typeof payload?.associatedTaskId === "number" ? payload.associatedTaskId : undefined,
|
|
11641
|
+
description: typeof payload?.description === "string" ? payload.description : undefined,
|
|
11642
|
+
result: typeof payload?.result === "string" ? payload.result : undefined,
|
|
11643
|
+
error: typeof payload?.error === "string" ? payload.error : undefined
|
|
11644
|
+
},
|
|
11645
|
+
triggerEvent,
|
|
11646
|
+
subAgentResult,
|
|
11647
|
+
profile
|
|
11648
|
+
});
|
|
11649
|
+
if (handler.postProcessNotifyEvent) {
|
|
11650
|
+
const notifyEventForHook = {
|
|
11651
|
+
type: event.type,
|
|
11652
|
+
taskId: typeof payload?.associatedTaskId === "number" ? payload.associatedTaskId : undefined,
|
|
11653
|
+
description: typeof payload?.description === "string" ? payload.description : undefined,
|
|
11654
|
+
result: typeof payload?.result === "string" ? payload.result : undefined,
|
|
11655
|
+
error: typeof payload?.error === "string" ? payload.error : undefined
|
|
11656
|
+
};
|
|
11657
|
+
setTimeout(() => {
|
|
11658
|
+
Promise.resolve(handler.postProcessNotifyEvent({
|
|
11659
|
+
notifyEvent: notifyEventForHook,
|
|
11660
|
+
triggerEvent,
|
|
11661
|
+
subAgentResult,
|
|
11662
|
+
formattedPrompt: prompt.promptText,
|
|
11663
|
+
profile
|
|
11664
|
+
})).catch((err) => {
|
|
11665
|
+
console.error(`[EventHandler] postProcessNotifyEvent hook failed (swallowed)`, err);
|
|
11666
|
+
});
|
|
11667
|
+
}, 0);
|
|
11668
|
+
}
|
|
11669
|
+
const triggerChatId = triggerEvent.metadata?.chatId ?? undefined;
|
|
11670
|
+
const triggerMessageId = triggerEvent.metadata?.messageId ?? undefined;
|
|
11671
|
+
const triggerSessionId = event?.metadata?.trigger_session_id;
|
|
11672
|
+
return {
|
|
11673
|
+
message: prompt.promptText,
|
|
11674
|
+
envEvent: event,
|
|
11675
|
+
triggerSessionId,
|
|
11676
|
+
chatId: triggerChatId,
|
|
11677
|
+
...triggerMessageId ? { triggerMessageId } : {}
|
|
11678
|
+
};
|
|
11679
|
+
}
|
|
11680
|
+
async handleNotifyEventForTest(event) {
|
|
11681
|
+
if (this.isStopped)
|
|
11682
|
+
return;
|
|
11683
|
+
const formatted = await this.formatEvent(event);
|
|
11684
|
+
if (this.onEventWithEnv) {
|
|
11685
|
+
await this.onEventWithEnv(formatted);
|
|
11686
|
+
} else {
|
|
11687
|
+
await this.onEvent(formatted.message);
|
|
11688
|
+
}
|
|
11689
|
+
}
|
|
11599
11690
|
enqueue(formattedEvent) {
|
|
11600
11691
|
if (this.isStopped) {
|
|
11601
11692
|
return;
|
|
@@ -11771,13 +11862,29 @@ class EventHandler {
|
|
|
11771
11862
|
}
|
|
11772
11863
|
}
|
|
11773
11864
|
__legacyDecorateClassTS([
|
|
11774
|
-
TracedAs5("
|
|
11865
|
+
TracedAs5("event_handler.handle_event", { recordParams: true }),
|
|
11775
11866
|
__legacyMetadataTS("design:type", Function),
|
|
11776
11867
|
__legacyMetadataTS("design:paramtypes", [
|
|
11777
11868
|
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
11778
11869
|
]),
|
|
11779
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
11870
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
11780
11871
|
], EventHandler.prototype, "handleEvent", null);
|
|
11872
|
+
__legacyDecorateClassTS([
|
|
11873
|
+
TracedAs5("cli.event-handler.formatEvent", { recordParams: true, recordResult: false }),
|
|
11874
|
+
__legacyMetadataTS("design:type", Function),
|
|
11875
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
11876
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
11877
|
+
]),
|
|
11878
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
11879
|
+
], EventHandler.prototype, "formatEvent", null);
|
|
11880
|
+
__legacyDecorateClassTS([
|
|
11881
|
+
TracedAs5("event_handler.process_notify", { recordParams: true, recordResult: false }),
|
|
11882
|
+
__legacyMetadataTS("design:type", Function),
|
|
11883
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
11884
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
11885
|
+
]),
|
|
11886
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
11887
|
+
], EventHandler.prototype, "formatEventViaESPluginV2", null);
|
|
11781
11888
|
__legacyDecorateClassTS([
|
|
11782
11889
|
TracedAs5("cli.event-handler.ensureActiveSession", { recordParams: true }),
|
|
11783
11890
|
__legacyMetadataTS("design:type", Function),
|
|
@@ -11795,6 +11902,62 @@ __legacyDecorateClassTS([
|
|
|
11795
11902
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
11796
11903
|
], EventHandler.prototype, "ensureChatSession", null);
|
|
11797
11904
|
|
|
11905
|
+
// src/commands/shared/event-handler-wiring.ts
|
|
11906
|
+
var storeCache = new Map;
|
|
11907
|
+
function getOrCreateEventStore(dbPath) {
|
|
11908
|
+
const normalized = normalizeDbPath(dbPath);
|
|
11909
|
+
let store = storeCache.get(normalized);
|
|
11910
|
+
if (store)
|
|
11911
|
+
return store;
|
|
11912
|
+
ensureParentDir(normalized);
|
|
11913
|
+
store = new EventStoreImpl({ dbPath: normalized });
|
|
11914
|
+
storeCache.set(normalized, store);
|
|
11915
|
+
setSharedEventStore(store);
|
|
11916
|
+
return store;
|
|
11917
|
+
}
|
|
11918
|
+
function normalizeDbPath(dbPath) {
|
|
11919
|
+
const expanded = dbPath.startsWith("~") ? join(homedir(), dbPath.slice(1).replace(/^\//, "")) : dbPath;
|
|
11920
|
+
return expanded;
|
|
11921
|
+
}
|
|
11922
|
+
function ensureParentDir(dbPath) {
|
|
11923
|
+
const parent = join(dbPath, "..");
|
|
11924
|
+
if (!existsSync(parent)) {
|
|
11925
|
+
mkdirSync(parent, { recursive: true });
|
|
11926
|
+
}
|
|
11927
|
+
}
|
|
11928
|
+
function getHandlerForEsTypeForEnv(env) {
|
|
11929
|
+
let component = null;
|
|
11930
|
+
try {
|
|
11931
|
+
component = env.getComponent?.("event-source") ?? null;
|
|
11932
|
+
} catch {
|
|
11933
|
+
component = null;
|
|
11934
|
+
}
|
|
11935
|
+
const hasGetHandler = component !== null && component !== undefined && typeof component.getHandler === "function";
|
|
11936
|
+
return (esType) => {
|
|
11937
|
+
if (!hasGetHandler)
|
|
11938
|
+
return;
|
|
11939
|
+
try {
|
|
11940
|
+
const h = component.getHandler(esType);
|
|
11941
|
+
return h ?? undefined;
|
|
11942
|
+
} catch {
|
|
11943
|
+
return;
|
|
11944
|
+
}
|
|
11945
|
+
};
|
|
11946
|
+
}
|
|
11947
|
+
function createDefaultEventStoreDbPath() {
|
|
11948
|
+
return join(homedir(), ".roy-agent", "event-store.db");
|
|
11949
|
+
}
|
|
11950
|
+
function createEventHandlerForInteractive(options) {
|
|
11951
|
+
const dbPath = options.dbPath ?? createDefaultEventStoreDbPath();
|
|
11952
|
+
const eventStore = getOrCreateEventStore(dbPath);
|
|
11953
|
+
const getHandlerForEsType = getHandlerForEsTypeForEnv(options.env);
|
|
11954
|
+
return new EventHandler({
|
|
11955
|
+
...options,
|
|
11956
|
+
eventStore,
|
|
11957
|
+
getHandlerForEsType
|
|
11958
|
+
});
|
|
11959
|
+
}
|
|
11960
|
+
|
|
11798
11961
|
// src/commands/shared/esc-active-descendant.ts
|
|
11799
11962
|
function hasActiveDescendants(env, parentSessionId) {
|
|
11800
11963
|
if (!env || !parentSessionId)
|
|
@@ -13646,12 +13809,13 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
13646
13809
|
console
|
|
13647
13810
|
});
|
|
13648
13811
|
});
|
|
13649
|
-
const eventHandler =
|
|
13812
|
+
const eventHandler = createEventHandlerForInteractive({
|
|
13650
13813
|
env,
|
|
13651
13814
|
eventTypes: ["task.background.*", "event-source.event.*"],
|
|
13652
13815
|
formatter: new EventMessageFormatter({ prefix: "[通知]" }),
|
|
13653
13816
|
isIdle: () => repl.isIdle(),
|
|
13654
13817
|
sessionComponent,
|
|
13818
|
+
onEvent: async (_message) => {},
|
|
13655
13819
|
onEventWithEnv: async (formattedEvent) => {
|
|
13656
13820
|
await repl.handleEventMessageWithEnv(formattedEvent);
|
|
13657
13821
|
}
|
|
@@ -14510,7 +14674,7 @@ async function loadHandleQuery(options, hooks) {
|
|
|
14510
14674
|
env,
|
|
14511
14675
|
enabled: true
|
|
14512
14676
|
});
|
|
14513
|
-
const eventHandler =
|
|
14677
|
+
const eventHandler = createEventHandlerForInteractive({
|
|
14514
14678
|
env,
|
|
14515
14679
|
eventTypes: ["task.background.*", "event-source.event.*"],
|
|
14516
14680
|
formatter: new EventMessageFormatter({ prefix: "[通知]" }),
|
|
@@ -14646,7 +14810,7 @@ function createRunCommand() {
|
|
|
14646
14810
|
const maxLines = Number.parseInt(argv.maxLines ?? "500", 10);
|
|
14647
14811
|
const runState = {
|
|
14648
14812
|
isIdle: () => true,
|
|
14649
|
-
onNotification: () => {}
|
|
14813
|
+
onNotification: async () => {}
|
|
14650
14814
|
};
|
|
14651
14815
|
const {
|
|
14652
14816
|
handleQuery,
|
|
@@ -21450,15 +21614,15 @@ function resolveServerUrl(serverUrl, fallback) {
|
|
|
21450
21614
|
}
|
|
21451
21615
|
|
|
21452
21616
|
// src/lib/bounty-profile-reader.ts
|
|
21453
|
-
import { existsSync as
|
|
21454
|
-
import { homedir } from "node:os";
|
|
21455
|
-
import { join } from "node:path";
|
|
21617
|
+
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
21618
|
+
import { homedir as homedir2 } from "node:os";
|
|
21619
|
+
import { join as join2 } from "node:path";
|
|
21456
21620
|
function readBountyProfile(name, profilesDir) {
|
|
21457
21621
|
if (!name)
|
|
21458
21622
|
return null;
|
|
21459
|
-
const dir = profilesDir ??
|
|
21460
|
-
const profilePath =
|
|
21461
|
-
if (!
|
|
21623
|
+
const dir = profilesDir ?? join2(homedir2(), ".config", "bounty", "profiles");
|
|
21624
|
+
const profilePath = join2(dir, `${name}.json`);
|
|
21625
|
+
if (!existsSync3(profilePath))
|
|
21462
21626
|
return null;
|
|
21463
21627
|
try {
|
|
21464
21628
|
const raw = readFileSync(profilePath, "utf-8");
|
|
@@ -25875,19 +26039,19 @@ var LspCommand = {
|
|
|
25875
26039
|
|
|
25876
26040
|
// src/commands/install/index.ts
|
|
25877
26041
|
import { spawnSync } from "node:child_process";
|
|
25878
|
-
import { existsSync as
|
|
25879
|
-
import { join as
|
|
25880
|
-
import { homedir as
|
|
26042
|
+
import { existsSync as existsSync6, readFileSync as readFileSync4, writeFileSync, mkdirSync as mkdirSync2, rmSync as rmSync2 } from "node:fs";
|
|
26043
|
+
import { join as join7, resolve } from "node:path";
|
|
26044
|
+
import { homedir as homedir5 } from "node:os";
|
|
25881
26045
|
|
|
25882
26046
|
// src/commands/install/cleanup-stale-plugin-copies.ts
|
|
25883
|
-
import { existsSync as
|
|
25884
|
-
import { join as
|
|
26047
|
+
import { existsSync as existsSync5, readFileSync as readFileSync3, rmSync, cpSync } from "node:fs";
|
|
26048
|
+
import { join as join6 } from "node:path";
|
|
25885
26049
|
import { homedir as nodeHomedir, tmpdir as nodeTmpdir } from "node:os";
|
|
25886
26050
|
function cleanupStalePluginCopies(packageName, options) {
|
|
25887
26051
|
const HOME = options.homedir ?? nodeHomedir();
|
|
25888
26052
|
const paths = options.localNodeModulesPaths ?? [
|
|
25889
|
-
|
|
25890
|
-
|
|
26053
|
+
join6(HOME, "node_modules"),
|
|
26054
|
+
join6(HOME, ".roy-agent", "node_modules")
|
|
25891
26055
|
];
|
|
25892
26056
|
const backupRoot = options.backupDir ?? nodeTmpdir();
|
|
25893
26057
|
const result = {
|
|
@@ -25897,15 +26061,15 @@ function cleanupStalePluginCopies(packageName, options) {
|
|
|
25897
26061
|
};
|
|
25898
26062
|
if (!options.globalVersion) {
|
|
25899
26063
|
for (const p of paths) {
|
|
25900
|
-
const candidate =
|
|
26064
|
+
const candidate = join6(p, packageName);
|
|
25901
26065
|
result.skipped.push({ path: candidate, reason: "no-global-version" });
|
|
25902
26066
|
}
|
|
25903
26067
|
return result;
|
|
25904
26068
|
}
|
|
25905
26069
|
for (const nmPath of paths) {
|
|
25906
|
-
const localPkgDir =
|
|
25907
|
-
const localPkgJson =
|
|
25908
|
-
if (!
|
|
26070
|
+
const localPkgDir = join6(nmPath, packageName);
|
|
26071
|
+
const localPkgJson = join6(localPkgDir, "package.json");
|
|
26072
|
+
if (!existsSync5(localPkgJson)) {
|
|
25909
26073
|
result.skipped.push({ path: localPkgDir, reason: "no-local-copy" });
|
|
25910
26074
|
continue;
|
|
25911
26075
|
}
|
|
@@ -25926,7 +26090,7 @@ function cleanupStalePluginCopies(packageName, options) {
|
|
|
25926
26090
|
const safeName = packageName.replace(/@/g, "").replace(/[^a-zA-Z0-9._/-]/g, "-");
|
|
25927
26091
|
const safeLocalVersion = (localVersion ?? "unknown").replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
25928
26092
|
const timestamp = Date.now();
|
|
25929
|
-
backupPath =
|
|
26093
|
+
backupPath = join6(backupRoot, `${safeName}-${safeLocalVersion}-backup-${timestamp}`);
|
|
25930
26094
|
cpSync(localPkgDir, backupPath, { recursive: true });
|
|
25931
26095
|
result.backups.push({ originalPath: localPkgDir, backupPath });
|
|
25932
26096
|
} catch (err) {
|
|
@@ -25961,19 +26125,19 @@ function compareVersions(a, b) {
|
|
|
25961
26125
|
|
|
25962
26126
|
// src/commands/install/index.ts
|
|
25963
26127
|
function getConfigDir(scope) {
|
|
25964
|
-
return scope === "global" ?
|
|
26128
|
+
return scope === "global" ? join7(homedir5(), ".roy-agent") : join7(process.cwd(), ".roy");
|
|
25965
26129
|
}
|
|
25966
26130
|
function detectDefaultScope() {
|
|
25967
|
-
const projectDir =
|
|
25968
|
-
return
|
|
26131
|
+
const projectDir = join7(process.cwd(), ".roy");
|
|
26132
|
+
return existsSync6(projectDir) ? "project" : "global";
|
|
25969
26133
|
}
|
|
25970
26134
|
function getConfigPath(scope) {
|
|
25971
|
-
return
|
|
26135
|
+
return join7(getConfigDir(scope), "plugins.json");
|
|
25972
26136
|
}
|
|
25973
26137
|
function loadPlugins(scope) {
|
|
25974
26138
|
const configPath = getConfigPath(scope);
|
|
25975
26139
|
try {
|
|
25976
|
-
if (
|
|
26140
|
+
if (existsSync6(configPath)) {
|
|
25977
26141
|
const raw = readFileSync4(configPath, "utf-8");
|
|
25978
26142
|
const config = JSON.parse(raw);
|
|
25979
26143
|
return config.plugins ?? [];
|
|
@@ -25984,8 +26148,8 @@ function loadPlugins(scope) {
|
|
|
25984
26148
|
function savePlugins(plugins, scope) {
|
|
25985
26149
|
const configDir = getConfigDir(scope);
|
|
25986
26150
|
const configPath = getConfigPath(scope);
|
|
25987
|
-
if (!
|
|
25988
|
-
|
|
26151
|
+
if (!existsSync6(configDir)) {
|
|
26152
|
+
mkdirSync2(configDir, { recursive: true });
|
|
25989
26153
|
}
|
|
25990
26154
|
const config = { plugins };
|
|
25991
26155
|
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
@@ -26000,8 +26164,8 @@ function stripVersionSpec(packageName) {
|
|
|
26000
26164
|
function readPackageInfo(packageName) {
|
|
26001
26165
|
const bareName = packageName.startsWith("/") || packageName.startsWith(".") ? packageName : stripVersionSpec(packageName);
|
|
26002
26166
|
if (packageName.startsWith("/") || packageName.startsWith(".")) {
|
|
26003
|
-
const localPkgPath =
|
|
26004
|
-
if (
|
|
26167
|
+
const localPkgPath = join7(packageName, "package.json");
|
|
26168
|
+
if (existsSync6(localPkgPath)) {
|
|
26005
26169
|
try {
|
|
26006
26170
|
const pkg = JSON.parse(readFileSync4(localPkgPath, "utf-8"));
|
|
26007
26171
|
return {
|
|
@@ -26015,18 +26179,18 @@ function readPackageInfo(packageName) {
|
|
|
26015
26179
|
}
|
|
26016
26180
|
}
|
|
26017
26181
|
const searchPaths = [
|
|
26018
|
-
|
|
26182
|
+
join7(process.cwd(), "node_modules", bareName, "package.json"),
|
|
26019
26183
|
resolve(process.cwd(), "..", "node_modules", bareName, "package.json"),
|
|
26020
|
-
|
|
26184
|
+
join7(process.cwd(), ".roy", "plugins", bareName, "package.json"),
|
|
26021
26185
|
...(() => {
|
|
26022
26186
|
const globalRoot = getNpmGlobalRoot();
|
|
26023
|
-
return globalRoot ? [
|
|
26187
|
+
return globalRoot ? [join7(globalRoot, bareName, "package.json")] : [];
|
|
26024
26188
|
})(),
|
|
26025
|
-
|
|
26189
|
+
join7(homedir5(), ".roy-agent", "node_modules", bareName, "package.json")
|
|
26026
26190
|
];
|
|
26027
26191
|
for (const pkgPath of searchPaths) {
|
|
26028
26192
|
try {
|
|
26029
|
-
if (
|
|
26193
|
+
if (existsSync6(pkgPath)) {
|
|
26030
26194
|
const pkg = JSON.parse(readFileSync4(pkgPath, "utf-8"));
|
|
26031
26195
|
return {
|
|
26032
26196
|
version: pkg.version ?? "0.0.0",
|
|
@@ -26060,15 +26224,15 @@ async function verifyInstalledVersion(packageName, declaredVersion) {
|
|
|
26060
26224
|
return { ok: true, actualVersion: actual.version };
|
|
26061
26225
|
}
|
|
26062
26226
|
function getPackageManagerCommand() {
|
|
26063
|
-
if (
|
|
26064
|
-
if (
|
|
26227
|
+
if (existsSync6(join7(process.cwd(), "pnpm-lock.yaml"))) {
|
|
26228
|
+
if (existsSync6(join7(process.cwd(), "pnpm-workspace.yaml"))) {
|
|
26065
26229
|
return "pnpm -w";
|
|
26066
26230
|
}
|
|
26067
26231
|
return "pnpm";
|
|
26068
26232
|
}
|
|
26069
|
-
if (
|
|
26233
|
+
if (existsSync6(join7(process.cwd(), "yarn.lock")))
|
|
26070
26234
|
return "yarn";
|
|
26071
|
-
if (
|
|
26235
|
+
if (existsSync6(join7(process.cwd(), "bun.lock")) || existsSync6(join7(process.cwd(), "bun.lockb")))
|
|
26072
26236
|
return "bun";
|
|
26073
26237
|
return "npm";
|
|
26074
26238
|
}
|
|
@@ -26107,15 +26271,15 @@ var InstallPackageCommand = {
|
|
|
26107
26271
|
}
|
|
26108
26272
|
resolvedName = info2.name;
|
|
26109
26273
|
const srcDir = resolve(packageName);
|
|
26110
|
-
if (!
|
|
26274
|
+
if (!existsSync6(srcDir)) {
|
|
26111
26275
|
console.error(`
|
|
26112
26276
|
❌ Local path '${srcDir}' does not exist.
|
|
26113
26277
|
`);
|
|
26114
26278
|
process.exit(1);
|
|
26115
26279
|
}
|
|
26116
|
-
const pluginDir =
|
|
26117
|
-
if (!
|
|
26118
|
-
|
|
26280
|
+
const pluginDir = join7(process.cwd(), ".roy", "plugins", resolvedName);
|
|
26281
|
+
if (!existsSync6(pluginDir)) {
|
|
26282
|
+
mkdirSync2(pluginDir, { recursive: true });
|
|
26119
26283
|
}
|
|
26120
26284
|
const result = spawnSync("cp", ["-r", `${srcDir}/.`, pluginDir], {
|
|
26121
26285
|
stdio: "inherit",
|
|
@@ -26149,12 +26313,12 @@ var InstallPackageCommand = {
|
|
|
26149
26313
|
process.exit(1);
|
|
26150
26314
|
}
|
|
26151
26315
|
resolvedName = info2.name;
|
|
26152
|
-
const pluginDir =
|
|
26153
|
-
if (!
|
|
26154
|
-
|
|
26316
|
+
const pluginDir = join7(process.cwd(), ".roy", "plugins", resolvedName);
|
|
26317
|
+
if (!existsSync6(pluginDir)) {
|
|
26318
|
+
mkdirSync2(pluginDir, { recursive: true });
|
|
26155
26319
|
}
|
|
26156
|
-
const nmPath =
|
|
26157
|
-
if (
|
|
26320
|
+
const nmPath = join7(process.cwd(), "node_modules", packageName);
|
|
26321
|
+
if (existsSync6(nmPath)) {
|
|
26158
26322
|
spawnSync("cp", ["-r", `${nmPath}/.`, pluginDir], { stdio: "inherit", shell: false });
|
|
26159
26323
|
}
|
|
26160
26324
|
}
|
|
@@ -26176,7 +26340,7 @@ var InstallPackageCommand = {
|
|
|
26176
26340
|
if (tmpInfo) {
|
|
26177
26341
|
const cleanupResult = cleanupStalePluginCopies(tmpInfo.name, {
|
|
26178
26342
|
globalVersion: tmpInfo.version,
|
|
26179
|
-
homedir:
|
|
26343
|
+
homedir: homedir5()
|
|
26180
26344
|
});
|
|
26181
26345
|
if (cleanupResult.cleaned.length > 0) {
|
|
26182
26346
|
console.log(`
|
|
@@ -26316,8 +26480,8 @@ var InstallRemoveCommand = {
|
|
|
26316
26480
|
\uD83D\uDDD1️ Removing plugin: ${plugin.packageName}@${plugin.version} (${scope})
|
|
26317
26481
|
`);
|
|
26318
26482
|
if (scope === "project") {
|
|
26319
|
-
const pluginDir =
|
|
26320
|
-
if (
|
|
26483
|
+
const pluginDir = join7(process.cwd(), ".roy", "plugins", plugin.packageName);
|
|
26484
|
+
if (existsSync6(pluginDir)) {
|
|
26321
26485
|
spawnSync("rm", ["-rf", pluginDir], { stdio: "inherit", shell: false });
|
|
26322
26486
|
console.log(` Removed plugin directory: ${pluginDir}`);
|
|
26323
26487
|
}
|
|
@@ -26332,8 +26496,8 @@ var InstallRemoveCommand = {
|
|
|
26332
26496
|
`);
|
|
26333
26497
|
process.exit(result.status ?? 1);
|
|
26334
26498
|
}
|
|
26335
|
-
const globalNm =
|
|
26336
|
-
if (
|
|
26499
|
+
const globalNm = join7(homedir5(), ".roy-agent", "node_modules", plugin.packageName);
|
|
26500
|
+
if (existsSync6(globalNm)) {
|
|
26337
26501
|
spawnSync("rm", ["-rf", globalNm], { stdio: "inherit", shell: false });
|
|
26338
26502
|
}
|
|
26339
26503
|
}
|
package/dist/index.js
CHANGED
|
@@ -9460,7 +9460,7 @@ class CliQuietModeService {
|
|
|
9460
9460
|
// package.json
|
|
9461
9461
|
var package_default = {
|
|
9462
9462
|
name: "@ai-setting/roy-agent-cli",
|
|
9463
|
-
version: "1.7.
|
|
9463
|
+
version: "1.7.38",
|
|
9464
9464
|
type: "module",
|
|
9465
9465
|
description: "CLI for roy-agent - Non-interactive command execution",
|
|
9466
9466
|
main: "./dist/index.js",
|
|
@@ -11526,6 +11526,12 @@ function extractChatId(event) {
|
|
|
11526
11526
|
return;
|
|
11527
11527
|
}
|
|
11528
11528
|
|
|
11529
|
+
// src/commands/shared/event-handler-wiring.ts
|
|
11530
|
+
import { existsSync, mkdirSync } from "node:fs";
|
|
11531
|
+
import { join } from "node:path";
|
|
11532
|
+
import { homedir } from "node:os";
|
|
11533
|
+
import { EventStoreImpl, setSharedEventStore } from "@ai-setting/roy-agent-core/env/event-source/event-store";
|
|
11534
|
+
|
|
11529
11535
|
// src/commands/shared/event-handler.ts
|
|
11530
11536
|
import { TracedAs as TracedAs5 } from "@ai-setting/roy-agent-core";
|
|
11531
11537
|
class EventHandler {
|
|
@@ -11542,6 +11548,8 @@ class EventHandler {
|
|
|
11542
11548
|
unsubscribe = null;
|
|
11543
11549
|
sessionComponent = null;
|
|
11544
11550
|
activeEventSessionId = null;
|
|
11551
|
+
eventStore = null;
|
|
11552
|
+
getHandlerForEsType = null;
|
|
11545
11553
|
constructor(options) {
|
|
11546
11554
|
this.env = options.env;
|
|
11547
11555
|
this.eventTypes = options.eventTypes;
|
|
@@ -11551,6 +11559,8 @@ class EventHandler {
|
|
|
11551
11559
|
this.isIdle = options.isIdle ?? (() => true);
|
|
11552
11560
|
this.idleCheckInterval = options.idleCheckInterval ?? 100;
|
|
11553
11561
|
this.sessionComponent = options.sessionComponent ?? null;
|
|
11562
|
+
this.eventStore = options.eventStore ?? null;
|
|
11563
|
+
this.getHandlerForEsType = options.getHandlerForEsType ?? null;
|
|
11554
11564
|
}
|
|
11555
11565
|
start() {
|
|
11556
11566
|
this.isStopped = false;
|
|
@@ -11588,13 +11598,94 @@ class EventHandler {
|
|
|
11588
11598
|
this.isProcessing = false;
|
|
11589
11599
|
this.clearActiveSession();
|
|
11590
11600
|
}
|
|
11591
|
-
handleEvent(event) {
|
|
11601
|
+
async handleEvent(event) {
|
|
11592
11602
|
if (this.isStopped) {
|
|
11593
11603
|
return;
|
|
11594
11604
|
}
|
|
11595
|
-
const formatted = this.
|
|
11605
|
+
const formatted = await this.formatEvent(event);
|
|
11596
11606
|
this.enqueue(formatted);
|
|
11597
11607
|
}
|
|
11608
|
+
async formatEvent(event) {
|
|
11609
|
+
if (event.type.startsWith("task.background.") && event.metadata?.triggerEventId && this.eventStore && this.getHandlerForEsType) {
|
|
11610
|
+
try {
|
|
11611
|
+
const v2Formatted = await this.formatEventViaESPluginV2(event);
|
|
11612
|
+
if (v2Formatted) {
|
|
11613
|
+
return v2Formatted;
|
|
11614
|
+
}
|
|
11615
|
+
} catch (err) {
|
|
11616
|
+
console.error(`[EventHandler] ESPlugin v2 path failed, falling back to formatter`, err);
|
|
11617
|
+
}
|
|
11618
|
+
}
|
|
11619
|
+
return this.formatter.formatWithEvent(event);
|
|
11620
|
+
}
|
|
11621
|
+
async formatEventViaESPluginV2(event) {
|
|
11622
|
+
const triggerEventId = event.metadata.triggerEventId;
|
|
11623
|
+
const triggerEvent = await this.eventStore.getEventById(triggerEventId);
|
|
11624
|
+
if (!triggerEvent) {
|
|
11625
|
+
return null;
|
|
11626
|
+
}
|
|
11627
|
+
const handler = this.getHandlerForEsType(triggerEvent.esType);
|
|
11628
|
+
if (!handler || !handler.buildNotifyHandlePrompt) {
|
|
11629
|
+
return null;
|
|
11630
|
+
}
|
|
11631
|
+
const payload = event.payload;
|
|
11632
|
+
const subAgentResult = {
|
|
11633
|
+
summary: typeof payload?.result === "string" ? payload.result : typeof payload?.error === "string" ? payload.error : "(无结果)"
|
|
11634
|
+
};
|
|
11635
|
+
const profile = triggerEvent.metadata?.profile ?? undefined;
|
|
11636
|
+
const prompt = handler.buildNotifyHandlePrompt({
|
|
11637
|
+
notifyEvent: {
|
|
11638
|
+
type: event.type,
|
|
11639
|
+
taskId: typeof payload?.associatedTaskId === "number" ? payload.associatedTaskId : undefined,
|
|
11640
|
+
description: typeof payload?.description === "string" ? payload.description : undefined,
|
|
11641
|
+
result: typeof payload?.result === "string" ? payload.result : undefined,
|
|
11642
|
+
error: typeof payload?.error === "string" ? payload.error : undefined
|
|
11643
|
+
},
|
|
11644
|
+
triggerEvent,
|
|
11645
|
+
subAgentResult,
|
|
11646
|
+
profile
|
|
11647
|
+
});
|
|
11648
|
+
if (handler.postProcessNotifyEvent) {
|
|
11649
|
+
const notifyEventForHook = {
|
|
11650
|
+
type: event.type,
|
|
11651
|
+
taskId: typeof payload?.associatedTaskId === "number" ? payload.associatedTaskId : undefined,
|
|
11652
|
+
description: typeof payload?.description === "string" ? payload.description : undefined,
|
|
11653
|
+
result: typeof payload?.result === "string" ? payload.result : undefined,
|
|
11654
|
+
error: typeof payload?.error === "string" ? payload.error : undefined
|
|
11655
|
+
};
|
|
11656
|
+
setTimeout(() => {
|
|
11657
|
+
Promise.resolve(handler.postProcessNotifyEvent({
|
|
11658
|
+
notifyEvent: notifyEventForHook,
|
|
11659
|
+
triggerEvent,
|
|
11660
|
+
subAgentResult,
|
|
11661
|
+
formattedPrompt: prompt.promptText,
|
|
11662
|
+
profile
|
|
11663
|
+
})).catch((err) => {
|
|
11664
|
+
console.error(`[EventHandler] postProcessNotifyEvent hook failed (swallowed)`, err);
|
|
11665
|
+
});
|
|
11666
|
+
}, 0);
|
|
11667
|
+
}
|
|
11668
|
+
const triggerChatId = triggerEvent.metadata?.chatId ?? undefined;
|
|
11669
|
+
const triggerMessageId = triggerEvent.metadata?.messageId ?? undefined;
|
|
11670
|
+
const triggerSessionId = event?.metadata?.trigger_session_id;
|
|
11671
|
+
return {
|
|
11672
|
+
message: prompt.promptText,
|
|
11673
|
+
envEvent: event,
|
|
11674
|
+
triggerSessionId,
|
|
11675
|
+
chatId: triggerChatId,
|
|
11676
|
+
...triggerMessageId ? { triggerMessageId } : {}
|
|
11677
|
+
};
|
|
11678
|
+
}
|
|
11679
|
+
async handleNotifyEventForTest(event) {
|
|
11680
|
+
if (this.isStopped)
|
|
11681
|
+
return;
|
|
11682
|
+
const formatted = await this.formatEvent(event);
|
|
11683
|
+
if (this.onEventWithEnv) {
|
|
11684
|
+
await this.onEventWithEnv(formatted);
|
|
11685
|
+
} else {
|
|
11686
|
+
await this.onEvent(formatted.message);
|
|
11687
|
+
}
|
|
11688
|
+
}
|
|
11598
11689
|
enqueue(formattedEvent) {
|
|
11599
11690
|
if (this.isStopped) {
|
|
11600
11691
|
return;
|
|
@@ -11770,13 +11861,29 @@ class EventHandler {
|
|
|
11770
11861
|
}
|
|
11771
11862
|
}
|
|
11772
11863
|
__legacyDecorateClassTS([
|
|
11773
|
-
TracedAs5("
|
|
11864
|
+
TracedAs5("event_handler.handle_event", { recordParams: true }),
|
|
11774
11865
|
__legacyMetadataTS("design:type", Function),
|
|
11775
11866
|
__legacyMetadataTS("design:paramtypes", [
|
|
11776
11867
|
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
11777
11868
|
]),
|
|
11778
|
-
__legacyMetadataTS("design:returntype", undefined)
|
|
11869
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
11779
11870
|
], EventHandler.prototype, "handleEvent", null);
|
|
11871
|
+
__legacyDecorateClassTS([
|
|
11872
|
+
TracedAs5("cli.event-handler.formatEvent", { recordParams: true, recordResult: false }),
|
|
11873
|
+
__legacyMetadataTS("design:type", Function),
|
|
11874
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
11875
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
11876
|
+
]),
|
|
11877
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
11878
|
+
], EventHandler.prototype, "formatEvent", null);
|
|
11879
|
+
__legacyDecorateClassTS([
|
|
11880
|
+
TracedAs5("event_handler.process_notify", { recordParams: true, recordResult: false }),
|
|
11881
|
+
__legacyMetadataTS("design:type", Function),
|
|
11882
|
+
__legacyMetadataTS("design:paramtypes", [
|
|
11883
|
+
typeof EnvEvent === "undefined" ? Object : EnvEvent
|
|
11884
|
+
]),
|
|
11885
|
+
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
11886
|
+
], EventHandler.prototype, "formatEventViaESPluginV2", null);
|
|
11780
11887
|
__legacyDecorateClassTS([
|
|
11781
11888
|
TracedAs5("cli.event-handler.ensureActiveSession", { recordParams: true }),
|
|
11782
11889
|
__legacyMetadataTS("design:type", Function),
|
|
@@ -11794,6 +11901,62 @@ __legacyDecorateClassTS([
|
|
|
11794
11901
|
__legacyMetadataTS("design:returntype", typeof Promise === "undefined" ? Object : Promise)
|
|
11795
11902
|
], EventHandler.prototype, "ensureChatSession", null);
|
|
11796
11903
|
|
|
11904
|
+
// src/commands/shared/event-handler-wiring.ts
|
|
11905
|
+
var storeCache = new Map;
|
|
11906
|
+
function getOrCreateEventStore(dbPath) {
|
|
11907
|
+
const normalized = normalizeDbPath(dbPath);
|
|
11908
|
+
let store = storeCache.get(normalized);
|
|
11909
|
+
if (store)
|
|
11910
|
+
return store;
|
|
11911
|
+
ensureParentDir(normalized);
|
|
11912
|
+
store = new EventStoreImpl({ dbPath: normalized });
|
|
11913
|
+
storeCache.set(normalized, store);
|
|
11914
|
+
setSharedEventStore(store);
|
|
11915
|
+
return store;
|
|
11916
|
+
}
|
|
11917
|
+
function normalizeDbPath(dbPath) {
|
|
11918
|
+
const expanded = dbPath.startsWith("~") ? join(homedir(), dbPath.slice(1).replace(/^\//, "")) : dbPath;
|
|
11919
|
+
return expanded;
|
|
11920
|
+
}
|
|
11921
|
+
function ensureParentDir(dbPath) {
|
|
11922
|
+
const parent = join(dbPath, "..");
|
|
11923
|
+
if (!existsSync(parent)) {
|
|
11924
|
+
mkdirSync(parent, { recursive: true });
|
|
11925
|
+
}
|
|
11926
|
+
}
|
|
11927
|
+
function getHandlerForEsTypeForEnv(env) {
|
|
11928
|
+
let component = null;
|
|
11929
|
+
try {
|
|
11930
|
+
component = env.getComponent?.("event-source") ?? null;
|
|
11931
|
+
} catch {
|
|
11932
|
+
component = null;
|
|
11933
|
+
}
|
|
11934
|
+
const hasGetHandler = component !== null && component !== undefined && typeof component.getHandler === "function";
|
|
11935
|
+
return (esType) => {
|
|
11936
|
+
if (!hasGetHandler)
|
|
11937
|
+
return;
|
|
11938
|
+
try {
|
|
11939
|
+
const h = component.getHandler(esType);
|
|
11940
|
+
return h ?? undefined;
|
|
11941
|
+
} catch {
|
|
11942
|
+
return;
|
|
11943
|
+
}
|
|
11944
|
+
};
|
|
11945
|
+
}
|
|
11946
|
+
function createDefaultEventStoreDbPath() {
|
|
11947
|
+
return join(homedir(), ".roy-agent", "event-store.db");
|
|
11948
|
+
}
|
|
11949
|
+
function createEventHandlerForInteractive(options) {
|
|
11950
|
+
const dbPath = options.dbPath ?? createDefaultEventStoreDbPath();
|
|
11951
|
+
const eventStore = getOrCreateEventStore(dbPath);
|
|
11952
|
+
const getHandlerForEsType = getHandlerForEsTypeForEnv(options.env);
|
|
11953
|
+
return new EventHandler({
|
|
11954
|
+
...options,
|
|
11955
|
+
eventStore,
|
|
11956
|
+
getHandlerForEsType
|
|
11957
|
+
});
|
|
11958
|
+
}
|
|
11959
|
+
|
|
11797
11960
|
// src/commands/shared/esc-active-descendant.ts
|
|
11798
11961
|
function hasActiveDescendants(env, parentSessionId) {
|
|
11799
11962
|
if (!env || !parentSessionId)
|
|
@@ -13645,12 +13808,13 @@ function createInteractiveCommand(externalEnvService) {
|
|
|
13645
13808
|
console
|
|
13646
13809
|
});
|
|
13647
13810
|
});
|
|
13648
|
-
const eventHandler =
|
|
13811
|
+
const eventHandler = createEventHandlerForInteractive({
|
|
13649
13812
|
env,
|
|
13650
13813
|
eventTypes: ["task.background.*", "event-source.event.*"],
|
|
13651
13814
|
formatter: new EventMessageFormatter({ prefix: "[通知]" }),
|
|
13652
13815
|
isIdle: () => repl.isIdle(),
|
|
13653
13816
|
sessionComponent,
|
|
13817
|
+
onEvent: async (_message) => {},
|
|
13654
13818
|
onEventWithEnv: async (formattedEvent) => {
|
|
13655
13819
|
await repl.handleEventMessageWithEnv(formattedEvent);
|
|
13656
13820
|
}
|
|
@@ -14509,7 +14673,7 @@ async function loadHandleQuery(options, hooks) {
|
|
|
14509
14673
|
env,
|
|
14510
14674
|
enabled: true
|
|
14511
14675
|
});
|
|
14512
|
-
const eventHandler =
|
|
14676
|
+
const eventHandler = createEventHandlerForInteractive({
|
|
14513
14677
|
env,
|
|
14514
14678
|
eventTypes: ["task.background.*", "event-source.event.*"],
|
|
14515
14679
|
formatter: new EventMessageFormatter({ prefix: "[通知]" }),
|
|
@@ -14645,7 +14809,7 @@ function createRunCommand() {
|
|
|
14645
14809
|
const maxLines = Number.parseInt(argv.maxLines ?? "500", 10);
|
|
14646
14810
|
const runState = {
|
|
14647
14811
|
isIdle: () => true,
|
|
14648
|
-
onNotification: () => {}
|
|
14812
|
+
onNotification: async () => {}
|
|
14649
14813
|
};
|
|
14650
14814
|
const {
|
|
14651
14815
|
handleQuery,
|
|
@@ -21449,15 +21613,15 @@ function resolveServerUrl(serverUrl, fallback) {
|
|
|
21449
21613
|
}
|
|
21450
21614
|
|
|
21451
21615
|
// src/lib/bounty-profile-reader.ts
|
|
21452
|
-
import { existsSync as
|
|
21453
|
-
import { homedir } from "node:os";
|
|
21454
|
-
import { join } from "node:path";
|
|
21616
|
+
import { existsSync as existsSync3, readFileSync } from "node:fs";
|
|
21617
|
+
import { homedir as homedir2 } from "node:os";
|
|
21618
|
+
import { join as join2 } from "node:path";
|
|
21455
21619
|
function readBountyProfile(name, profilesDir) {
|
|
21456
21620
|
if (!name)
|
|
21457
21621
|
return null;
|
|
21458
|
-
const dir = profilesDir ??
|
|
21459
|
-
const profilePath =
|
|
21460
|
-
if (!
|
|
21622
|
+
const dir = profilesDir ?? join2(homedir2(), ".config", "bounty", "profiles");
|
|
21623
|
+
const profilePath = join2(dir, `${name}.json`);
|
|
21624
|
+
if (!existsSync3(profilePath))
|
|
21461
21625
|
return null;
|
|
21462
21626
|
try {
|
|
21463
21627
|
const raw = readFileSync(profilePath, "utf-8");
|
|
@@ -25874,19 +26038,19 @@ var LspCommand = {
|
|
|
25874
26038
|
|
|
25875
26039
|
// src/commands/install/index.ts
|
|
25876
26040
|
import { spawnSync } from "node:child_process";
|
|
25877
|
-
import { existsSync as
|
|
25878
|
-
import { join as
|
|
25879
|
-
import { homedir as
|
|
26041
|
+
import { existsSync as existsSync6, readFileSync as readFileSync4, writeFileSync, mkdirSync as mkdirSync2, rmSync as rmSync2 } from "node:fs";
|
|
26042
|
+
import { join as join7, resolve } from "node:path";
|
|
26043
|
+
import { homedir as homedir5 } from "node:os";
|
|
25880
26044
|
|
|
25881
26045
|
// src/commands/install/cleanup-stale-plugin-copies.ts
|
|
25882
|
-
import { existsSync as
|
|
25883
|
-
import { join as
|
|
26046
|
+
import { existsSync as existsSync5, readFileSync as readFileSync3, rmSync, cpSync } from "node:fs";
|
|
26047
|
+
import { join as join6 } from "node:path";
|
|
25884
26048
|
import { homedir as nodeHomedir, tmpdir as nodeTmpdir } from "node:os";
|
|
25885
26049
|
function cleanupStalePluginCopies(packageName, options) {
|
|
25886
26050
|
const HOME = options.homedir ?? nodeHomedir();
|
|
25887
26051
|
const paths = options.localNodeModulesPaths ?? [
|
|
25888
|
-
|
|
25889
|
-
|
|
26052
|
+
join6(HOME, "node_modules"),
|
|
26053
|
+
join6(HOME, ".roy-agent", "node_modules")
|
|
25890
26054
|
];
|
|
25891
26055
|
const backupRoot = options.backupDir ?? nodeTmpdir();
|
|
25892
26056
|
const result = {
|
|
@@ -25896,15 +26060,15 @@ function cleanupStalePluginCopies(packageName, options) {
|
|
|
25896
26060
|
};
|
|
25897
26061
|
if (!options.globalVersion) {
|
|
25898
26062
|
for (const p of paths) {
|
|
25899
|
-
const candidate =
|
|
26063
|
+
const candidate = join6(p, packageName);
|
|
25900
26064
|
result.skipped.push({ path: candidate, reason: "no-global-version" });
|
|
25901
26065
|
}
|
|
25902
26066
|
return result;
|
|
25903
26067
|
}
|
|
25904
26068
|
for (const nmPath of paths) {
|
|
25905
|
-
const localPkgDir =
|
|
25906
|
-
const localPkgJson =
|
|
25907
|
-
if (!
|
|
26069
|
+
const localPkgDir = join6(nmPath, packageName);
|
|
26070
|
+
const localPkgJson = join6(localPkgDir, "package.json");
|
|
26071
|
+
if (!existsSync5(localPkgJson)) {
|
|
25908
26072
|
result.skipped.push({ path: localPkgDir, reason: "no-local-copy" });
|
|
25909
26073
|
continue;
|
|
25910
26074
|
}
|
|
@@ -25925,7 +26089,7 @@ function cleanupStalePluginCopies(packageName, options) {
|
|
|
25925
26089
|
const safeName = packageName.replace(/@/g, "").replace(/[^a-zA-Z0-9._/-]/g, "-");
|
|
25926
26090
|
const safeLocalVersion = (localVersion ?? "unknown").replace(/[^a-zA-Z0-9._-]/g, "-");
|
|
25927
26091
|
const timestamp = Date.now();
|
|
25928
|
-
backupPath =
|
|
26092
|
+
backupPath = join6(backupRoot, `${safeName}-${safeLocalVersion}-backup-${timestamp}`);
|
|
25929
26093
|
cpSync(localPkgDir, backupPath, { recursive: true });
|
|
25930
26094
|
result.backups.push({ originalPath: localPkgDir, backupPath });
|
|
25931
26095
|
} catch (err) {
|
|
@@ -25960,19 +26124,19 @@ function compareVersions(a, b) {
|
|
|
25960
26124
|
|
|
25961
26125
|
// src/commands/install/index.ts
|
|
25962
26126
|
function getConfigDir(scope) {
|
|
25963
|
-
return scope === "global" ?
|
|
26127
|
+
return scope === "global" ? join7(homedir5(), ".roy-agent") : join7(process.cwd(), ".roy");
|
|
25964
26128
|
}
|
|
25965
26129
|
function detectDefaultScope() {
|
|
25966
|
-
const projectDir =
|
|
25967
|
-
return
|
|
26130
|
+
const projectDir = join7(process.cwd(), ".roy");
|
|
26131
|
+
return existsSync6(projectDir) ? "project" : "global";
|
|
25968
26132
|
}
|
|
25969
26133
|
function getConfigPath(scope) {
|
|
25970
|
-
return
|
|
26134
|
+
return join7(getConfigDir(scope), "plugins.json");
|
|
25971
26135
|
}
|
|
25972
26136
|
function loadPlugins(scope) {
|
|
25973
26137
|
const configPath = getConfigPath(scope);
|
|
25974
26138
|
try {
|
|
25975
|
-
if (
|
|
26139
|
+
if (existsSync6(configPath)) {
|
|
25976
26140
|
const raw = readFileSync4(configPath, "utf-8");
|
|
25977
26141
|
const config = JSON.parse(raw);
|
|
25978
26142
|
return config.plugins ?? [];
|
|
@@ -25983,8 +26147,8 @@ function loadPlugins(scope) {
|
|
|
25983
26147
|
function savePlugins(plugins, scope) {
|
|
25984
26148
|
const configDir = getConfigDir(scope);
|
|
25985
26149
|
const configPath = getConfigPath(scope);
|
|
25986
|
-
if (!
|
|
25987
|
-
|
|
26150
|
+
if (!existsSync6(configDir)) {
|
|
26151
|
+
mkdirSync2(configDir, { recursive: true });
|
|
25988
26152
|
}
|
|
25989
26153
|
const config = { plugins };
|
|
25990
26154
|
writeFileSync(configPath, JSON.stringify(config, null, 2), "utf-8");
|
|
@@ -25999,8 +26163,8 @@ function stripVersionSpec(packageName) {
|
|
|
25999
26163
|
function readPackageInfo(packageName) {
|
|
26000
26164
|
const bareName = packageName.startsWith("/") || packageName.startsWith(".") ? packageName : stripVersionSpec(packageName);
|
|
26001
26165
|
if (packageName.startsWith("/") || packageName.startsWith(".")) {
|
|
26002
|
-
const localPkgPath =
|
|
26003
|
-
if (
|
|
26166
|
+
const localPkgPath = join7(packageName, "package.json");
|
|
26167
|
+
if (existsSync6(localPkgPath)) {
|
|
26004
26168
|
try {
|
|
26005
26169
|
const pkg = JSON.parse(readFileSync4(localPkgPath, "utf-8"));
|
|
26006
26170
|
return {
|
|
@@ -26014,18 +26178,18 @@ function readPackageInfo(packageName) {
|
|
|
26014
26178
|
}
|
|
26015
26179
|
}
|
|
26016
26180
|
const searchPaths = [
|
|
26017
|
-
|
|
26181
|
+
join7(process.cwd(), "node_modules", bareName, "package.json"),
|
|
26018
26182
|
resolve(process.cwd(), "..", "node_modules", bareName, "package.json"),
|
|
26019
|
-
|
|
26183
|
+
join7(process.cwd(), ".roy", "plugins", bareName, "package.json"),
|
|
26020
26184
|
...(() => {
|
|
26021
26185
|
const globalRoot = getNpmGlobalRoot();
|
|
26022
|
-
return globalRoot ? [
|
|
26186
|
+
return globalRoot ? [join7(globalRoot, bareName, "package.json")] : [];
|
|
26023
26187
|
})(),
|
|
26024
|
-
|
|
26188
|
+
join7(homedir5(), ".roy-agent", "node_modules", bareName, "package.json")
|
|
26025
26189
|
];
|
|
26026
26190
|
for (const pkgPath of searchPaths) {
|
|
26027
26191
|
try {
|
|
26028
|
-
if (
|
|
26192
|
+
if (existsSync6(pkgPath)) {
|
|
26029
26193
|
const pkg = JSON.parse(readFileSync4(pkgPath, "utf-8"));
|
|
26030
26194
|
return {
|
|
26031
26195
|
version: pkg.version ?? "0.0.0",
|
|
@@ -26059,15 +26223,15 @@ async function verifyInstalledVersion(packageName, declaredVersion) {
|
|
|
26059
26223
|
return { ok: true, actualVersion: actual.version };
|
|
26060
26224
|
}
|
|
26061
26225
|
function getPackageManagerCommand() {
|
|
26062
|
-
if (
|
|
26063
|
-
if (
|
|
26226
|
+
if (existsSync6(join7(process.cwd(), "pnpm-lock.yaml"))) {
|
|
26227
|
+
if (existsSync6(join7(process.cwd(), "pnpm-workspace.yaml"))) {
|
|
26064
26228
|
return "pnpm -w";
|
|
26065
26229
|
}
|
|
26066
26230
|
return "pnpm";
|
|
26067
26231
|
}
|
|
26068
|
-
if (
|
|
26232
|
+
if (existsSync6(join7(process.cwd(), "yarn.lock")))
|
|
26069
26233
|
return "yarn";
|
|
26070
|
-
if (
|
|
26234
|
+
if (existsSync6(join7(process.cwd(), "bun.lock")) || existsSync6(join7(process.cwd(), "bun.lockb")))
|
|
26071
26235
|
return "bun";
|
|
26072
26236
|
return "npm";
|
|
26073
26237
|
}
|
|
@@ -26106,15 +26270,15 @@ var InstallPackageCommand = {
|
|
|
26106
26270
|
}
|
|
26107
26271
|
resolvedName = info2.name;
|
|
26108
26272
|
const srcDir = resolve(packageName);
|
|
26109
|
-
if (!
|
|
26273
|
+
if (!existsSync6(srcDir)) {
|
|
26110
26274
|
console.error(`
|
|
26111
26275
|
❌ Local path '${srcDir}' does not exist.
|
|
26112
26276
|
`);
|
|
26113
26277
|
process.exit(1);
|
|
26114
26278
|
}
|
|
26115
|
-
const pluginDir =
|
|
26116
|
-
if (!
|
|
26117
|
-
|
|
26279
|
+
const pluginDir = join7(process.cwd(), ".roy", "plugins", resolvedName);
|
|
26280
|
+
if (!existsSync6(pluginDir)) {
|
|
26281
|
+
mkdirSync2(pluginDir, { recursive: true });
|
|
26118
26282
|
}
|
|
26119
26283
|
const result = spawnSync("cp", ["-r", `${srcDir}/.`, pluginDir], {
|
|
26120
26284
|
stdio: "inherit",
|
|
@@ -26148,12 +26312,12 @@ var InstallPackageCommand = {
|
|
|
26148
26312
|
process.exit(1);
|
|
26149
26313
|
}
|
|
26150
26314
|
resolvedName = info2.name;
|
|
26151
|
-
const pluginDir =
|
|
26152
|
-
if (!
|
|
26153
|
-
|
|
26315
|
+
const pluginDir = join7(process.cwd(), ".roy", "plugins", resolvedName);
|
|
26316
|
+
if (!existsSync6(pluginDir)) {
|
|
26317
|
+
mkdirSync2(pluginDir, { recursive: true });
|
|
26154
26318
|
}
|
|
26155
|
-
const nmPath =
|
|
26156
|
-
if (
|
|
26319
|
+
const nmPath = join7(process.cwd(), "node_modules", packageName);
|
|
26320
|
+
if (existsSync6(nmPath)) {
|
|
26157
26321
|
spawnSync("cp", ["-r", `${nmPath}/.`, pluginDir], { stdio: "inherit", shell: false });
|
|
26158
26322
|
}
|
|
26159
26323
|
}
|
|
@@ -26175,7 +26339,7 @@ var InstallPackageCommand = {
|
|
|
26175
26339
|
if (tmpInfo) {
|
|
26176
26340
|
const cleanupResult = cleanupStalePluginCopies(tmpInfo.name, {
|
|
26177
26341
|
globalVersion: tmpInfo.version,
|
|
26178
|
-
homedir:
|
|
26342
|
+
homedir: homedir5()
|
|
26179
26343
|
});
|
|
26180
26344
|
if (cleanupResult.cleaned.length > 0) {
|
|
26181
26345
|
console.log(`
|
|
@@ -26315,8 +26479,8 @@ var InstallRemoveCommand = {
|
|
|
26315
26479
|
\uD83D\uDDD1️ Removing plugin: ${plugin.packageName}@${plugin.version} (${scope})
|
|
26316
26480
|
`);
|
|
26317
26481
|
if (scope === "project") {
|
|
26318
|
-
const pluginDir =
|
|
26319
|
-
if (
|
|
26482
|
+
const pluginDir = join7(process.cwd(), ".roy", "plugins", plugin.packageName);
|
|
26483
|
+
if (existsSync6(pluginDir)) {
|
|
26320
26484
|
spawnSync("rm", ["-rf", pluginDir], { stdio: "inherit", shell: false });
|
|
26321
26485
|
console.log(` Removed plugin directory: ${pluginDir}`);
|
|
26322
26486
|
}
|
|
@@ -26331,8 +26495,8 @@ var InstallRemoveCommand = {
|
|
|
26331
26495
|
`);
|
|
26332
26496
|
process.exit(result.status ?? 1);
|
|
26333
26497
|
}
|
|
26334
|
-
const globalNm =
|
|
26335
|
-
if (
|
|
26498
|
+
const globalNm = join7(homedir5(), ".roy-agent", "node_modules", plugin.packageName);
|
|
26499
|
+
if (existsSync6(globalNm)) {
|
|
26336
26500
|
spawnSync("rm", ["-rf", globalNm], { stdio: "inherit", shell: false });
|
|
26337
26501
|
}
|
|
26338
26502
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/dist/roy-agent-linux-x64/bin/roy-agent
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 109602944 bytes
|
|
4
|
+
sha256: 4bff7951c55594175f880f2caca477359a3c55c89b5b973d9ba7cf8e721d8928
|