@farmslot/agent-runtime 0.9.0 → 0.10.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/CHANGELOG.md +16 -1
- package/README.md +1 -1
- package/bin/farmslot-agent.mjs +1 -1
- package/dist/execution-template/create.d.ts.map +1 -1
- package/dist/execution-template/create.js +4 -9
- package/dist/execution-template/create.js.map +1 -1
- package/dist/execution-template/execution-template.test.js +85 -34
- package/dist/execution-template/execution-template.test.js.map +1 -1
- package/dist/execution-template/frontmatter.d.ts +6 -3
- package/dist/execution-template/frontmatter.d.ts.map +1 -1
- package/dist/execution-template/frontmatter.js +8 -10
- package/dist/execution-template/frontmatter.js.map +1 -1
- package/dist/execution-template/index.d.ts +2 -2
- package/dist/execution-template/index.d.ts.map +1 -1
- package/dist/execution-template/index.js +2 -2
- package/dist/execution-template/index.js.map +1 -1
- package/dist/execution-template/infer.d.ts +2 -3
- package/dist/execution-template/infer.d.ts.map +1 -1
- package/dist/execution-template/infer.js +2 -19
- package/dist/execution-template/infer.js.map +1 -1
- package/dist/execution-template/lint.d.ts.map +1 -1
- package/dist/execution-template/lint.js +12 -14
- package/dist/execution-template/lint.js.map +1 -1
- package/dist/execution-template/resolve.d.ts.map +1 -1
- package/dist/execution-template/resolve.js +0 -2
- package/dist/execution-template/resolve.js.map +1 -1
- package/dist/execution-template/select.d.ts.map +1 -1
- package/dist/execution-template/select.js +4 -8
- package/dist/execution-template/select.js.map +1 -1
- package/dist/execution-template/snapshot.d.ts.map +1 -1
- package/dist/execution-template/snapshot.js +0 -1
- package/dist/execution-template/snapshot.js.map +1 -1
- package/dist/execution-template/types.d.ts +10 -5
- package/dist/execution-template/types.d.ts.map +1 -1
- package/dist/execution-template/types.js.map +1 -1
- package/dist/native/account-claude.d.ts +5 -0
- package/dist/native/account-claude.d.ts.map +1 -0
- package/dist/native/account-claude.js +42 -0
- package/dist/native/account-claude.js.map +1 -0
- package/dist/native/account-codex.d.ts +4 -0
- package/dist/native/account-codex.d.ts.map +1 -0
- package/dist/native/account-codex.js +51 -0
- package/dist/native/account-codex.js.map +1 -0
- package/dist/native/account-common.d.ts +30 -0
- package/dist/native/account-common.d.ts.map +1 -0
- package/dist/native/account-common.js +155 -0
- package/dist/native/account-common.js.map +1 -0
- package/dist/native/account-cursor.d.ts +5 -0
- package/dist/native/account-cursor.d.ts.map +1 -0
- package/dist/native/account-cursor.js +48 -0
- package/dist/native/account-cursor.js.map +1 -0
- package/dist/native/account-grok.d.ts +4 -0
- package/dist/native/account-grok.d.ts.map +1 -0
- package/dist/native/account-grok.js +55 -0
- package/dist/native/account-grok.js.map +1 -0
- package/dist/native/account-observation.test.d.ts +2 -0
- package/dist/native/account-observation.test.d.ts.map +1 -0
- package/dist/native/account-observation.test.js +256 -0
- package/dist/native/account-observation.test.js.map +1 -0
- package/dist/native/account-profiles.d.ts +11 -0
- package/dist/native/account-profiles.d.ts.map +1 -0
- package/dist/native/account-profiles.js +172 -0
- package/dist/native/account-profiles.js.map +1 -0
- package/dist/native/account-profiles.test.d.ts +2 -0
- package/dist/native/account-profiles.test.d.ts.map +1 -0
- package/dist/native/account-profiles.test.js +172 -0
- package/dist/native/account-profiles.test.js.map +1 -0
- package/dist/native/account-types.d.ts +11 -0
- package/dist/native/account-types.d.ts.map +1 -0
- package/dist/native/account-types.js +2 -0
- package/dist/native/account-types.js.map +1 -0
- package/dist/native/acp-requests.d.ts +11 -0
- package/dist/native/acp-requests.d.ts.map +1 -0
- package/dist/native/acp-requests.js +109 -0
- package/dist/native/acp-requests.js.map +1 -0
- package/dist/native/acp-rpc.d.ts +15 -0
- package/dist/native/acp-rpc.d.ts.map +1 -0
- package/dist/native/acp-rpc.js +73 -0
- package/dist/native/acp-rpc.js.map +1 -0
- package/dist/native/acp.d.ts +15 -0
- package/dist/native/acp.d.ts.map +1 -0
- package/dist/native/acp.js +285 -0
- package/dist/native/acp.js.map +1 -0
- package/dist/native/acp.test.d.ts +2 -0
- package/dist/native/acp.test.d.ts.map +1 -0
- package/dist/native/acp.test.js +257 -0
- package/dist/native/acp.test.js.map +1 -0
- package/dist/native/claude.d.ts.map +1 -1
- package/dist/native/claude.js +14 -0
- package/dist/native/claude.js.map +1 -1
- package/dist/native/client.d.ts +13 -0
- package/dist/native/client.d.ts.map +1 -1
- package/dist/native/client.js +112 -1
- package/dist/native/client.js.map +1 -1
- package/dist/native/codex.d.ts.map +1 -1
- package/dist/native/codex.js +61 -3
- package/dist/native/codex.js.map +1 -1
- package/dist/native/cursor-model.d.ts +6 -0
- package/dist/native/cursor-model.d.ts.map +1 -0
- package/dist/native/cursor-model.js +74 -0
- package/dist/native/cursor-model.js.map +1 -0
- package/dist/native/cursor-model.test.d.ts +2 -0
- package/dist/native/cursor-model.test.d.ts.map +1 -0
- package/dist/native/cursor-model.test.js +40 -0
- package/dist/native/cursor-model.test.js.map +1 -0
- package/dist/native/cursor.d.ts +2 -0
- package/dist/native/cursor.d.ts.map +1 -0
- package/dist/native/cursor.js +30 -0
- package/dist/native/cursor.js.map +1 -0
- package/dist/native/durability.test.js +461 -1
- package/dist/native/durability.test.js.map +1 -1
- package/dist/native/filesystem-policy.test.d.ts +2 -0
- package/dist/native/filesystem-policy.test.d.ts.map +1 -0
- package/dist/native/filesystem-policy.test.js +136 -0
- package/dist/native/filesystem-policy.test.js.map +1 -0
- package/dist/native/grok.d.ts +2 -0
- package/dist/native/grok.d.ts.map +1 -0
- package/dist/native/grok.js +17 -0
- package/dist/native/grok.js.map +1 -0
- package/dist/native/host.js +39 -0
- package/dist/native/host.js.map +1 -1
- package/dist/native/index.d.ts +3 -0
- package/dist/native/index.d.ts.map +1 -1
- package/dist/native/index.js +3 -0
- package/dist/native/index.js.map +1 -1
- package/dist/native/ipc.d.ts +59 -0
- package/dist/native/ipc.d.ts.map +1 -1
- package/dist/native/ipc.js +76 -4
- package/dist/native/ipc.js.map +1 -1
- package/dist/native/manager.d.ts +22 -4
- package/dist/native/manager.d.ts.map +1 -1
- package/dist/native/manager.js +386 -46
- package/dist/native/manager.js.map +1 -1
- package/dist/native/process-tree.d.ts +11 -0
- package/dist/native/process-tree.d.ts.map +1 -1
- package/dist/native/process-tree.js +123 -20
- package/dist/native/process-tree.js.map +1 -1
- package/dist/native/process-tree.test.js +126 -1
- package/dist/native/process-tree.test.js.map +1 -1
- package/dist/native/process.d.ts +5 -1
- package/dist/native/process.d.ts.map +1 -1
- package/dist/native/process.js +36 -13
- package/dist/native/process.js.map +1 -1
- package/dist/native/process.test.d.ts +2 -0
- package/dist/native/process.test.d.ts.map +1 -0
- package/dist/native/process.test.js +56 -0
- package/dist/native/process.test.js.map +1 -0
- package/dist/native/profile-service.d.ts +5 -0
- package/dist/native/profile-service.d.ts.map +1 -0
- package/dist/native/profile-service.js +76 -0
- package/dist/native/profile-service.js.map +1 -0
- package/dist/native/registry.d.ts +20 -0
- package/dist/native/registry.d.ts.map +1 -0
- package/dist/native/registry.js +89 -0
- package/dist/native/registry.js.map +1 -0
- package/dist/native/registry.test.d.ts +2 -0
- package/dist/native/registry.test.d.ts.map +1 -0
- package/dist/native/registry.test.js +13 -0
- package/dist/native/registry.test.js.map +1 -0
- package/dist/native/review-sandbox.d.ts +12 -0
- package/dist/native/review-sandbox.d.ts.map +1 -0
- package/dist/native/review-sandbox.js +6 -0
- package/dist/native/review-sandbox.js.map +1 -0
- package/dist/native/review-sandbox.test.d.ts +2 -0
- package/dist/native/review-sandbox.test.d.ts.map +1 -0
- package/dist/native/review-sandbox.test.js +40 -0
- package/dist/native/review-sandbox.test.js.map +1 -0
- package/dist/native/service.d.ts.map +1 -1
- package/dist/native/service.js +42 -8
- package/dist/native/service.js.map +1 -1
- package/dist/native/supervisor.js +121 -33
- package/dist/native/supervisor.js.map +1 -1
- package/dist/native/types.d.ts +11 -1
- package/dist/native/types.d.ts.map +1 -1
- package/dist/native/worker-history.d.ts +16 -0
- package/dist/native/worker-history.d.ts.map +1 -0
- package/dist/native/worker-history.js +77 -0
- package/dist/native/worker-history.js.map +1 -0
- package/dist/native/worker-history.test.d.ts +2 -0
- package/dist/native/worker-history.test.d.ts.map +1 -0
- package/dist/native/worker-history.test.js +195 -0
- package/dist/native/worker-history.test.js.map +1 -0
- package/dist/native/worker-launch.d.ts +72 -0
- package/dist/native/worker-launch.d.ts.map +1 -0
- package/dist/native/worker-launch.js +134 -0
- package/dist/native/worker-launch.js.map +1 -0
- package/dist/native/worker-launch.test.d.ts +2 -0
- package/dist/native/worker-launch.test.d.ts.map +1 -0
- package/dist/native/worker-launch.test.js +61 -0
- package/dist/native/worker-launch.test.js.map +1 -0
- package/dist/native/worker-relocation.test.d.ts +2 -0
- package/dist/native/worker-relocation.test.d.ts.map +1 -0
- package/dist/native/worker-relocation.test.js +110 -0
- package/dist/native/worker-relocation.test.js.map +1 -0
- package/dist/native/worker-service.d.ts +4 -0
- package/dist/native/worker-service.d.ts.map +1 -0
- package/dist/native/worker-service.js +85 -0
- package/dist/native/worker-service.js.map +1 -0
- package/dist/task-init/index.d.ts +5 -1
- package/dist/task-init/index.d.ts.map +1 -1
- package/dist/task-init/index.js +7 -3
- package/dist/task-init/index.js.map +1 -1
- package/dist/task-init/task-document.d.ts.map +1 -1
- package/dist/task-init/task-document.js +2 -2
- package/dist/task-init/task-document.js.map +1 -1
- package/dist/task-init/write.d.ts +0 -6
- package/dist/task-init/write.d.ts.map +1 -1
- package/dist/task-init/write.js +1 -8
- package/dist/task-init/write.js.map +1 -1
- package/package.json +2 -2
- package/scripts/cursor-session-discovery.cjs +48 -0
- package/scripts/execution-template-cli.mjs +8 -11
- package/scripts/review-filesystem.cjs +39 -0
- package/scripts/review-session.cjs +45 -0
- package/scripts/review-terminal.cjs +134 -0
- package/scripts/task-init-cli.mjs +3 -3
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, realpathSync } from 'node:fs';
|
|
3
|
+
import { homedir } from 'node:os';
|
|
4
|
+
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
5
|
+
import { farmslotHome } from '@farmslot/protocol/node/farmslot-home';
|
|
6
|
+
import { nativeRunnerDefinitions } from './registry.js';
|
|
7
|
+
import { durableWrite } from './storage.js';
|
|
8
|
+
function profileId(id) {
|
|
9
|
+
if (!/^[a-z0-9][a-z0-9_-]{0,63}$/.test(id) || id === 'ambient')
|
|
10
|
+
throw new Error('Profile label must use lowercase letters, digits, dashes or underscores');
|
|
11
|
+
}
|
|
12
|
+
function object(value) {
|
|
13
|
+
return Boolean(value && typeof value === 'object' && !Array.isArray(value));
|
|
14
|
+
}
|
|
15
|
+
function canonicalDirectory(directory) {
|
|
16
|
+
const suffix = [];
|
|
17
|
+
let existing = directory;
|
|
18
|
+
while (!existsSync(existing)) {
|
|
19
|
+
suffix.unshift(basename(existing));
|
|
20
|
+
existing = dirname(existing);
|
|
21
|
+
}
|
|
22
|
+
return join(realpathSync(existing), ...suffix);
|
|
23
|
+
}
|
|
24
|
+
export function providerAccountsConfigPath(home = farmslotHome()) {
|
|
25
|
+
return join(home, 'provider-accounts.json');
|
|
26
|
+
}
|
|
27
|
+
function readConfig(home) {
|
|
28
|
+
const file = providerAccountsConfigPath(home);
|
|
29
|
+
if (!existsSync(file))
|
|
30
|
+
return { version: 1, accounts: {} };
|
|
31
|
+
const value = JSON.parse(readFileSync(file, 'utf8'));
|
|
32
|
+
if (!object(value) ||
|
|
33
|
+
value.version !== 1 ||
|
|
34
|
+
!object(value.accounts) ||
|
|
35
|
+
(value.nativeProfiles !== undefined && !object(value.nativeProfiles)))
|
|
36
|
+
throw new Error('Invalid provider account configuration');
|
|
37
|
+
for (const [id, entry] of Object.entries(value.nativeProfiles ?? {})) {
|
|
38
|
+
profileId(id);
|
|
39
|
+
if (!object(entry) ||
|
|
40
|
+
entry.id !== id ||
|
|
41
|
+
typeof entry.runner !== 'string' ||
|
|
42
|
+
typeof entry.directory !== 'string' ||
|
|
43
|
+
!isAbsolute(entry.directory) ||
|
|
44
|
+
typeof entry.accountContextId !== 'string' ||
|
|
45
|
+
!/^[0-9a-f]{8}(?:-[0-9a-f]{4}){3}-[0-9a-f]{12}$/.test(entry.accountContextId) ||
|
|
46
|
+
Object.keys(entry).some((key) => !['id', 'runner', 'directory', 'accountContextId', 'state'].includes(key)) ||
|
|
47
|
+
!['active', 'retiring'].includes(String(entry.state)))
|
|
48
|
+
throw new Error('Invalid native profile configuration');
|
|
49
|
+
}
|
|
50
|
+
return value;
|
|
51
|
+
}
|
|
52
|
+
function writeConfig(home, config) {
|
|
53
|
+
mkdirSync(home, { recursive: true, mode: 0o700 });
|
|
54
|
+
durableWrite(providerAccountsConfigPath(home), config);
|
|
55
|
+
}
|
|
56
|
+
export function listNativeProfiles(home = farmslotHome()) {
|
|
57
|
+
return Object.values(readConfig(home).nativeProfiles ?? {});
|
|
58
|
+
}
|
|
59
|
+
export function findNativeProfile(id, home = farmslotHome()) {
|
|
60
|
+
profileId(id);
|
|
61
|
+
return listNativeProfiles(home).find((profile) => profile.id === id);
|
|
62
|
+
}
|
|
63
|
+
export function requireNativeProfile(id, runner, home = farmslotHome()) {
|
|
64
|
+
const profile = findNativeProfile(id, home);
|
|
65
|
+
if (!profile || profile.state !== 'active')
|
|
66
|
+
throw new Error('Native account profile is unavailable');
|
|
67
|
+
if (runner !== undefined && profile.runner !== runner)
|
|
68
|
+
throw new Error('Native profile belongs to another runner');
|
|
69
|
+
if (!Object.hasOwn(nativeRunnerDefinitions, profile.runner))
|
|
70
|
+
throw new Error('Native profile runner is unavailable');
|
|
71
|
+
return profile;
|
|
72
|
+
}
|
|
73
|
+
export function assertNativeProfileCurrent(profile, home = farmslotHome()) {
|
|
74
|
+
const current = requireNativeProfile(profile.id, profile.runner, home);
|
|
75
|
+
if (current.accountContextId !== profile.accountContextId ||
|
|
76
|
+
current.directory !== profile.directory)
|
|
77
|
+
throw new Error('Native account profile changed; start a new conversation');
|
|
78
|
+
}
|
|
79
|
+
export function nativeProfileEnvironment(profile, base = process.env) {
|
|
80
|
+
const definition = nativeRunnerDefinitions[profile.runner];
|
|
81
|
+
if (!definition?.account)
|
|
82
|
+
throw new Error('Native profile runner is unavailable');
|
|
83
|
+
const env = { ...base };
|
|
84
|
+
for (const key of definition.account.unset)
|
|
85
|
+
delete env[key];
|
|
86
|
+
return {
|
|
87
|
+
...env,
|
|
88
|
+
FARMSLOT_HOME: base.FARMSLOT_HOME ?? farmslotHome(),
|
|
89
|
+
...definition.account.environment(profile.directory, base),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
// Node-local profile mutations share one queue. Retirement holds it through
|
|
93
|
+
// process cleanup; ordinary profile reads still observe the persisted retiring state.
|
|
94
|
+
const mutations = new Map();
|
|
95
|
+
async function mutate(home, operation) {
|
|
96
|
+
const previous = mutations.get(home);
|
|
97
|
+
let release;
|
|
98
|
+
const current = new Promise((resolve) => {
|
|
99
|
+
release = resolve;
|
|
100
|
+
});
|
|
101
|
+
mutations.set(home, current);
|
|
102
|
+
await previous;
|
|
103
|
+
try {
|
|
104
|
+
return await operation();
|
|
105
|
+
}
|
|
106
|
+
finally {
|
|
107
|
+
release();
|
|
108
|
+
if (mutations.get(home) === current)
|
|
109
|
+
mutations.delete(home);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function inspectNativeProfile(id, inspect, home = farmslotHome()) {
|
|
113
|
+
return mutate(home, () => inspect(requireNativeProfile(id, undefined, home)));
|
|
114
|
+
}
|
|
115
|
+
export function addNativeProfile(params, home = farmslotHome()) {
|
|
116
|
+
profileId(params.profileId);
|
|
117
|
+
if (!Object.hasOwn(nativeRunnerDefinitions, params.runner))
|
|
118
|
+
throw new Error('Runner has no native profile support');
|
|
119
|
+
return mutate(home, () => {
|
|
120
|
+
const config = readConfig(home);
|
|
121
|
+
const profiles = config.nativeProfiles ?? {};
|
|
122
|
+
const existing = Object.hasOwn(profiles, params.profileId)
|
|
123
|
+
? profiles[params.profileId]
|
|
124
|
+
: undefined;
|
|
125
|
+
const requested = params.directory ?? join(home, 'runner-profiles', params.runner, params.profileId);
|
|
126
|
+
if (!isAbsolute(requested) && !requested.startsWith('~/'))
|
|
127
|
+
throw new Error('Native profile directory must be absolute or start with ~/');
|
|
128
|
+
const directory = resolve(requested.startsWith('~/') ? join(homedir(), requested.slice(2)) : requested);
|
|
129
|
+
const canonical = canonicalDirectory(directory);
|
|
130
|
+
if (existing) {
|
|
131
|
+
if (existing.runner === params.runner &&
|
|
132
|
+
existing.directory === canonical &&
|
|
133
|
+
existing.state === 'active')
|
|
134
|
+
return existing;
|
|
135
|
+
throw new Error('Retire the existing profile before changing its account location');
|
|
136
|
+
}
|
|
137
|
+
if (Object.values(profiles).some((profile) => profile.runner === params.runner && profile.directory === canonical))
|
|
138
|
+
throw new Error('This native account directory already has a profile');
|
|
139
|
+
mkdirSync(canonical, { recursive: true, mode: 0o700 });
|
|
140
|
+
const profile = {
|
|
141
|
+
id: params.profileId,
|
|
142
|
+
runner: params.runner,
|
|
143
|
+
directory: canonical,
|
|
144
|
+
accountContextId: randomUUID(),
|
|
145
|
+
state: 'active',
|
|
146
|
+
};
|
|
147
|
+
writeConfig(home, { ...config, nativeProfiles: { ...profiles, [profile.id]: profile } });
|
|
148
|
+
return profile;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
export function removeNativeProfile(id, accountContextId, stopSessions, home = farmslotHome()) {
|
|
152
|
+
profileId(id);
|
|
153
|
+
return mutate(home, async () => {
|
|
154
|
+
const config = readConfig(home);
|
|
155
|
+
const profile = Object.hasOwn(config.nativeProfiles ?? {}, id)
|
|
156
|
+
? config.nativeProfiles[id]
|
|
157
|
+
: undefined;
|
|
158
|
+
if (!profile)
|
|
159
|
+
return;
|
|
160
|
+
if (profile.accountContextId !== accountContextId)
|
|
161
|
+
throw new Error('Native profile changed; refresh before removing it');
|
|
162
|
+
profile.state = 'retiring';
|
|
163
|
+
writeConfig(home, config);
|
|
164
|
+
await stopSessions(profile);
|
|
165
|
+
const latest = readConfig(home);
|
|
166
|
+
if (latest.nativeProfiles?.[id]?.accountContextId !== accountContextId)
|
|
167
|
+
throw new Error('Native profile changed during retirement');
|
|
168
|
+
delete latest.nativeProfiles[id];
|
|
169
|
+
writeConfig(home, latest);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=account-profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-profiles.js","sourceRoot":"","sources":["../../src/native/account-profiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC5E,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGzE,OAAO,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAErE,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAS5C,SAAS,SAAS,CAAC,EAAU;IAC3B,IAAI,CAAC,4BAA4B,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,KAAK,SAAS;QAC5D,MAAM,IAAI,KAAK,CAAC,yEAAyE,CAAC,CAAC;AAC/F,CAAC;AACD,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,OAAO,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9E,CAAC;AACD,SAAS,kBAAkB,CAAC,SAAiB;IAC3C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,QAAQ,GAAG,SAAS,CAAC;IACzB,OAAO,CAAC,UAAU,CAAC,QAAQ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I,OAAO,CAAC,gBAAgB,KAAK,gBAAgB;YAC/C,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACxE,OAAO,CAAC,KAAK,GAAG,UAAU,CAAC;QAC3B,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC1B,MAAM,YAAY,CAAC,OAAO,CAAC,CAAC;QAC5B,MAAM,MAAM,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;QAChC,IAAI,MAAM,CAAC,cAAc,EAAE,CAAC,EAAE,CAAC,EAAE,gBAAgB,KAAK,gBAAgB;YACpE,MAAM,IAAI,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC9D,OAAO,MAAM,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;QACjC,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-profiles.test.d.ts","sourceRoot":"","sources":["../../src/native/account-profiles.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync, } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import test from 'node:test';
|
|
6
|
+
import { addNativeProfile, assertNativeProfileCurrent, listNativeProfiles, nativeProfileEnvironment, providerAccountsConfigPath, removeNativeProfile, requireNativeProfile, } from './account-profiles.js';
|
|
7
|
+
import { decodeRequest } from './ipc.js';
|
|
8
|
+
test('the default Claude directory retains its native credential store while custom profiles stay explicit', async () => {
|
|
9
|
+
const home = mkdtempSync(join(tmpdir(), 'native-claude-default-'));
|
|
10
|
+
try {
|
|
11
|
+
const directory = join(home, 'native-config');
|
|
12
|
+
mkdirSync(directory);
|
|
13
|
+
symlinkSync(directory, join(home, '.claude'));
|
|
14
|
+
const profile = await addNativeProfile({ profileId: 'default', runner: 'claude', directory: join(home, '.claude') }, home);
|
|
15
|
+
const base = {
|
|
16
|
+
HOME: home,
|
|
17
|
+
CLAUDE_CONFIG_DIR: '/other/config',
|
|
18
|
+
CLAUDE_SECURESTORAGE_CONFIG_DIR: '/other/storage',
|
|
19
|
+
CLAUDE_CODE_OAUTH_TOKEN: 'override',
|
|
20
|
+
};
|
|
21
|
+
const env = nativeProfileEnvironment(profile, base);
|
|
22
|
+
assert.equal(env.HOME, home);
|
|
23
|
+
assert.equal(env.CLAUDE_CONFIG_DIR, undefined);
|
|
24
|
+
assert.equal(env.CLAUDE_SECURESTORAGE_CONFIG_DIR, undefined);
|
|
25
|
+
assert.equal(env.CLAUDE_CODE_OAUTH_TOKEN, undefined);
|
|
26
|
+
const custom = await addNativeProfile({ profileId: 'custom', runner: 'claude' }, home);
|
|
27
|
+
const customEnv = nativeProfileEnvironment(custom, base);
|
|
28
|
+
assert.equal(customEnv.CLAUDE_CONFIG_DIR, custom.directory);
|
|
29
|
+
assert.equal(customEnv.CLAUDE_SECURESTORAGE_CONFIG_DIR, custom.directory);
|
|
30
|
+
const otherHome = nativeProfileEnvironment(profile, {
|
|
31
|
+
...base,
|
|
32
|
+
HOME: join(home, 'other-home'),
|
|
33
|
+
});
|
|
34
|
+
assert.equal(otherHome.CLAUDE_CONFIG_DIR, profile.directory, 'A different HOME must not redirect the chosen directory');
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
rmSync(home, { recursive: true, force: true });
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
test('named profiles preserve existing account settings and bind distinct native directories', async () => {
|
|
41
|
+
const home = mkdtempSync(join(tmpdir(), 'native-profiles-'));
|
|
42
|
+
try {
|
|
43
|
+
const existing = {
|
|
44
|
+
version: 1,
|
|
45
|
+
accounts: { old: { provider: 'codex', authPath: '/old/auth.json' } },
|
|
46
|
+
slotBindings: { slot: 'old' },
|
|
47
|
+
};
|
|
48
|
+
writeFileSync(providerAccountsConfigPath(home), JSON.stringify(existing));
|
|
49
|
+
const a = await addNativeProfile({ profileId: 'a', runner: 'claude' }, home);
|
|
50
|
+
const b = await addNativeProfile({ profileId: 'b', runner: 'claude' }, home);
|
|
51
|
+
assert.notEqual(a.directory, b.directory);
|
|
52
|
+
assert.notEqual(a.accountContextId, b.accountContextId);
|
|
53
|
+
assert.deepEqual(await addNativeProfile({ profileId: 'a', runner: 'claude' }, home), a);
|
|
54
|
+
const persisted = JSON.parse(readFileSync(providerAccountsConfigPath(home), 'utf8'));
|
|
55
|
+
assert.deepEqual(persisted.accounts, existing.accounts);
|
|
56
|
+
assert.deepEqual(persisted.slotBindings, existing.slotBindings);
|
|
57
|
+
const env = nativeProfileEnvironment(a, {
|
|
58
|
+
PATH: '/bin',
|
|
59
|
+
ANTHROPIC_API_KEY: 'sentinel',
|
|
60
|
+
SERVICE_PORT: '1234',
|
|
61
|
+
});
|
|
62
|
+
assert.equal(env.CLAUDE_CONFIG_DIR, a.directory);
|
|
63
|
+
assert.equal(env.CLAUDE_SECURESTORAGE_CONFIG_DIR, a.directory);
|
|
64
|
+
assert.equal(env.ANTHROPIC_API_KEY, undefined);
|
|
65
|
+
assert.equal(env.SERVICE_PORT, '1234');
|
|
66
|
+
const rejected = join(home, 'rejected');
|
|
67
|
+
await assert.rejects(addNativeProfile({ profileId: 'a', runner: 'claude', directory: rejected }, home));
|
|
68
|
+
assert.equal(existsSync(rejected), false);
|
|
69
|
+
await assert.rejects(addNativeProfile({ profileId: 'alias', runner: 'claude', directory: a.directory }, home));
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
rmSync(home, { recursive: true, force: true });
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
test('retirement blocks reuse until cleanup succeeds and a reused label gets a new account binding', async () => {
|
|
76
|
+
const home = mkdtempSync(join(tmpdir(), 'native-profile-retirement-'));
|
|
77
|
+
try {
|
|
78
|
+
const a = await addNativeProfile({ profileId: 'a', runner: 'codex' }, home);
|
|
79
|
+
await assert.rejects(removeNativeProfile(a.id, a.accountContextId, async () => {
|
|
80
|
+
assert.throws(() => requireNativeProfile(a.id, 'codex', home), /unavailable/);
|
|
81
|
+
throw new Error('cleanup-unconfirmed');
|
|
82
|
+
}, home), /cleanup-unconfirmed/);
|
|
83
|
+
assert.equal(listNativeProfiles(home)[0].state, 'retiring');
|
|
84
|
+
await assert.rejects(addNativeProfile({ profileId: 'a', runner: 'codex' }, home));
|
|
85
|
+
await removeNativeProfile(a.id, a.accountContextId, async () => { }, home);
|
|
86
|
+
assert.equal(existsSync(a.directory), true, 'Native-owned credentials/data are not deleted');
|
|
87
|
+
const b = await addNativeProfile({ profileId: 'a', runner: 'codex' }, home);
|
|
88
|
+
assert.notEqual(b.accountContextId, a.accountContextId);
|
|
89
|
+
assert.throws(() => assertNativeProfileCurrent(a, home), /changed/);
|
|
90
|
+
await assert.rejects(removeNativeProfile(a.id, a.accountContextId, async () => { }, home), /changed/);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
rmSync(home, { recursive: true, force: true });
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
test('reserved native creation keeps profile selection through IPC', () => {
|
|
97
|
+
const request = decodeRequest({
|
|
98
|
+
method: 'ensure',
|
|
99
|
+
owner: 'owner',
|
|
100
|
+
params: {
|
|
101
|
+
runner: 'codex',
|
|
102
|
+
cwd: '/workspace',
|
|
103
|
+
sessionId: 'fbb8f455-33ba-4e7f-9600-4eea85b9fda6',
|
|
104
|
+
profileId: 'work',
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
assert.equal(request.method, 'ensure');
|
|
108
|
+
assert.equal('params' in request && request.params.profileId, 'work');
|
|
109
|
+
});
|
|
110
|
+
test('Codex profiles retain keys required by explicitly configured native providers', async () => {
|
|
111
|
+
const home = mkdtempSync(join(tmpdir(), 'native-codex-provider-'));
|
|
112
|
+
try {
|
|
113
|
+
const profile = await addNativeProfile({ profileId: 'codex', runner: 'codex' }, home);
|
|
114
|
+
const env = nativeProfileEnvironment(profile, {
|
|
115
|
+
OPENAI_API_KEY: 'implicit-override',
|
|
116
|
+
CODEX_API_KEY: 'implicit-override',
|
|
117
|
+
CODEX_LB_API_KEY: 'configured-provider-key',
|
|
118
|
+
});
|
|
119
|
+
assert.equal(env.CODEX_HOME, profile.directory);
|
|
120
|
+
assert.equal(env.OPENAI_API_KEY, undefined);
|
|
121
|
+
assert.equal(env.CODEX_API_KEY, undefined);
|
|
122
|
+
assert.equal(env.CODEX_LB_API_KEY, 'configured-provider-key');
|
|
123
|
+
}
|
|
124
|
+
finally {
|
|
125
|
+
rmSync(home, { recursive: true, force: true });
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
test('additional runner profiles clear native auth overrides and select their native directories', async () => {
|
|
129
|
+
const home = mkdtempSync(join(tmpdir(), 'native-additional-profiles-'));
|
|
130
|
+
try {
|
|
131
|
+
const cursor = await addNativeProfile({ profileId: 'cursor', runner: 'cursor' }, home);
|
|
132
|
+
const defaultCursor = await addNativeProfile({ profileId: 'cursor-default', runner: 'cursor', directory: home }, home);
|
|
133
|
+
const grok = await addNativeProfile({ profileId: 'grok', runner: 'grok' }, home);
|
|
134
|
+
const base = {
|
|
135
|
+
HOME: home,
|
|
136
|
+
CURSOR_API_KEY: 'api-override',
|
|
137
|
+
CURSOR_AUTH_TOKEN: 'login-override',
|
|
138
|
+
CURSOR_CONFIG_DIR: '/other/config',
|
|
139
|
+
CURSOR_DATA_DIR: '/other/data',
|
|
140
|
+
XDG_CONFIG_HOME: '/other/xdg',
|
|
141
|
+
XAI_API_KEY: 'xai-override',
|
|
142
|
+
GROK_API_KEY: 'grok-override',
|
|
143
|
+
GROK_HOME: '/other/grok',
|
|
144
|
+
SERVICE_PORT: '1234',
|
|
145
|
+
};
|
|
146
|
+
const defaultCursorEnv = nativeProfileEnvironment(defaultCursor, base);
|
|
147
|
+
assert.equal(defaultCursorEnv.HOME, home);
|
|
148
|
+
assert.equal(defaultCursorEnv.AGENT_CLI_CREDENTIAL_STORE, undefined, 'The native default backend must remain available');
|
|
149
|
+
assert.equal(defaultCursorEnv.CURSOR_AUTH_TOKEN, undefined);
|
|
150
|
+
const cursorEnv = nativeProfileEnvironment(cursor, base);
|
|
151
|
+
assert.equal(cursorEnv.HOME, cursor.directory);
|
|
152
|
+
assert.equal(cursorEnv.AGENT_CLI_CREDENTIAL_STORE, 'file');
|
|
153
|
+
for (const key of [
|
|
154
|
+
'CURSOR_API_KEY',
|
|
155
|
+
'CURSOR_AUTH_TOKEN',
|
|
156
|
+
'CURSOR_CONFIG_DIR',
|
|
157
|
+
'CURSOR_DATA_DIR',
|
|
158
|
+
'XDG_CONFIG_HOME',
|
|
159
|
+
])
|
|
160
|
+
assert.equal(cursorEnv[key], undefined, `${key} must not override the selected Cursor profile`);
|
|
161
|
+
const grokEnv = nativeProfileEnvironment(grok, base);
|
|
162
|
+
assert.equal(grokEnv.GROK_HOME, grok.directory);
|
|
163
|
+
assert.equal(grokEnv.XAI_API_KEY, undefined);
|
|
164
|
+
assert.equal(grokEnv.GROK_API_KEY, undefined);
|
|
165
|
+
assert.equal(cursorEnv.SERVICE_PORT, '1234');
|
|
166
|
+
assert.equal(grokEnv.SERVICE_PORT, '1234');
|
|
167
|
+
}
|
|
168
|
+
finally {
|
|
169
|
+
rmSync(home, { recursive: true, force: true });
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
//# sourceMappingURL=account-profiles.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-profiles.test.js","sourceRoot":"","sources":["../../src/native/account-profiles.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EACL,UAAU,EACV,SAAS,EACT,WAAW,EACX,YAAY,EACZ,MAAM,EACN,WAAW,EACX,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,MA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H,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NativeAccountObservation } from '@farmslot/protocol';
|
|
2
|
+
export type { NativeAccountObservation } from '@farmslot/protocol';
|
|
3
|
+
export interface NativeAccountProbeOptions {
|
|
4
|
+
/** Probe the actual runner execution context, including its native profile variables. */
|
|
5
|
+
cwd: string;
|
|
6
|
+
executable?: string;
|
|
7
|
+
/** Complete effective profile environment. Defaults to the current process environment. */
|
|
8
|
+
env?: NodeJS.ProcessEnv;
|
|
9
|
+
}
|
|
10
|
+
export type NativeAccountState = Pick<NativeAccountObservation, 'login' | 'mode' | 'identity' | 'identityQuality' | 'reason'>;
|
|
11
|
+
//# sourceMappingURL=account-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-types.d.ts","sourceRoot":"","sources":["../../src/native/account-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEnE,YAAY,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAC;AAEnE,MAAM,WAAW,yBAAyB;IACxC,yFAAyF;IACzF,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,2FAA2F;IAC3F,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;AAED,MAAM,MAAM,kBAAkB,GAAG,IAAI,CACnC,wBAAwB,EACxB,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,iBAAiB,GAAG,QAAQ,CAC7D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-types.js","sourceRoot":"","sources":["../../src/native/account-types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { NativeSessionResponse } from '@farmslot/protocol';
|
|
2
|
+
import { type AcpObject } from './acp-rpc.js';
|
|
3
|
+
import type { NativeEventInput } from './types.js';
|
|
4
|
+
export interface AcpPendingRequest {
|
|
5
|
+
event: NativeEventInput;
|
|
6
|
+
response(value: NativeSessionResponse): AcpObject;
|
|
7
|
+
}
|
|
8
|
+
export declare function acpPermission(params: AcpObject, previous?: NativeEventInput['tool']): AcpPendingRequest;
|
|
9
|
+
/** Documented Cursor ACP extensions; no credential or agent-loop implementation. */
|
|
10
|
+
export declare function cursorRequest(method: string, params: AcpObject): AcpPendingRequest | undefined;
|
|
11
|
+
//# sourceMappingURL=acp-requests.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-requests.d.ts","sourceRoot":"","sources":["../../src/native/acp-requests.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhE,OAAO,EAAE,KAAK,SAAS,EAAwB,MAAM,cAAc,CAAC;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,gBAAgB,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,qBAAqB,GAAG,SAAS,CAAC;CACnD;AAED,wBAAgB,aAAa,CAC3B,MAAM,EAAE,SAAS,EACjB,QAAQ,CAAC,EAAE,gBAAgB,CAAC,MAAM,CAAC,GAClC,iBAAiB,CA+BnB;AAED,oFAAoF;AACpF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,GAAG,iBAAiB,GAAG,SAAS,CAmE9F"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { acpObject, acpString } from './acp-rpc.js';
|
|
2
|
+
export function acpPermission(params, previous) {
|
|
3
|
+
const tool = acpObject(params.toolCall);
|
|
4
|
+
if (!Array.isArray(params.options))
|
|
5
|
+
throw new Error('ACP permission options are missing');
|
|
6
|
+
const options = params.options.map(acpObject);
|
|
7
|
+
const title = typeof tool.title === 'string' ? tool.title : (previous?.name ?? 'Allow runner action?');
|
|
8
|
+
const input = tool.rawInput ?? previous?.input;
|
|
9
|
+
return {
|
|
10
|
+
event: {
|
|
11
|
+
type: 'approval.requested',
|
|
12
|
+
request: {
|
|
13
|
+
id: '',
|
|
14
|
+
title,
|
|
15
|
+
detail: JSON.stringify(input ?? tool.content ?? []),
|
|
16
|
+
tool: { name: title, input },
|
|
17
|
+
},
|
|
18
|
+
data: { toolCall: tool, options },
|
|
19
|
+
},
|
|
20
|
+
response(value) {
|
|
21
|
+
if (!value.decision)
|
|
22
|
+
throw new Error('Approval response requires a decision');
|
|
23
|
+
// Always grant only this operation. Session-wide grants exceed this response's scope.
|
|
24
|
+
const option = options.find((option) => option.kind === (value.decision === 'approve' ? 'allow_once' : 'reject_once'));
|
|
25
|
+
if (!option) {
|
|
26
|
+
if (value.decision === 'deny')
|
|
27
|
+
return { outcome: { outcome: 'cancelled' } };
|
|
28
|
+
throw new Error('Runner did not offer a one-time permission grant');
|
|
29
|
+
}
|
|
30
|
+
return { outcome: { outcome: 'selected', optionId: acpString(option.optionId) } };
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
/** Documented Cursor ACP extensions; no credential or agent-loop implementation. */
|
|
35
|
+
export function cursorRequest(method, params) {
|
|
36
|
+
if (method === 'cursor/create_plan')
|
|
37
|
+
return {
|
|
38
|
+
event: {
|
|
39
|
+
type: 'approval.requested',
|
|
40
|
+
request: {
|
|
41
|
+
id: '',
|
|
42
|
+
title: typeof params.name === 'string' ? params.name : 'Approve plan',
|
|
43
|
+
detail: acpString(params.plan),
|
|
44
|
+
},
|
|
45
|
+
data: params,
|
|
46
|
+
},
|
|
47
|
+
response(value) {
|
|
48
|
+
if (!value.decision)
|
|
49
|
+
throw new Error('Plan approval requires a decision');
|
|
50
|
+
return { outcome: { outcome: value.decision === 'approve' ? 'accepted' : 'rejected' } };
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
if (method !== 'cursor/ask_question')
|
|
54
|
+
return;
|
|
55
|
+
if (!Array.isArray(params.questions))
|
|
56
|
+
throw new Error('Cursor questions are missing');
|
|
57
|
+
const questions = params.questions.map((raw) => {
|
|
58
|
+
const q = acpObject(raw);
|
|
59
|
+
if (!Array.isArray(q.options))
|
|
60
|
+
throw new Error('Cursor question options are missing');
|
|
61
|
+
const options = q.options.map((raw) => {
|
|
62
|
+
const option = acpObject(raw);
|
|
63
|
+
return { id: acpString(option.id), label: acpString(option.label) };
|
|
64
|
+
});
|
|
65
|
+
if (new Set(options.map((option) => option.label)).size !== options.length)
|
|
66
|
+
throw new Error('Cursor question option labels are ambiguous');
|
|
67
|
+
return {
|
|
68
|
+
id: acpString(q.id),
|
|
69
|
+
prompt: acpString(q.prompt),
|
|
70
|
+
multiSelect: q.allowMultiple === true,
|
|
71
|
+
options,
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
return {
|
|
75
|
+
event: {
|
|
76
|
+
type: 'question.requested',
|
|
77
|
+
request: {
|
|
78
|
+
id: '',
|
|
79
|
+
title: typeof params.title === 'string' ? params.title : 'Answer runner questions',
|
|
80
|
+
questions,
|
|
81
|
+
},
|
|
82
|
+
data: params,
|
|
83
|
+
},
|
|
84
|
+
response(value) {
|
|
85
|
+
if (!value.answers)
|
|
86
|
+
throw new Error('Question response requires answers');
|
|
87
|
+
return {
|
|
88
|
+
outcome: {
|
|
89
|
+
outcome: 'answered',
|
|
90
|
+
answers: questions.map((q) => {
|
|
91
|
+
const selected = value.answers[q.id];
|
|
92
|
+
if (!selected?.length || (!q.multiSelect && selected.length !== 1))
|
|
93
|
+
throw new Error('Each question requires a valid selection');
|
|
94
|
+
return {
|
|
95
|
+
questionId: q.id,
|
|
96
|
+
selectedOptionIds: selected.map((label) => {
|
|
97
|
+
const option = q.options.find((option) => option.label === label);
|
|
98
|
+
if (!option)
|
|
99
|
+
throw new Error('Unknown question option');
|
|
100
|
+
return option.id;
|
|
101
|
+
}),
|
|
102
|
+
};
|
|
103
|
+
}),
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=acp-requests.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-requests.js","sourceRoot":"","sources":["../../src/native/acp-requests.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQpE,MAAM,UAAU,aAAa,CAC3B,MAAiB,EACjB,QAAmC;IAEnC,MAAM,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAC1F,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC9C,MAAM,KAAK,GACT,OAAO,IAAI,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,IAAI,IAAI,sBAAsB,CAAC,CAAC;IAC3F,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,IAAI,QAAQ,EAAE,KAAK,CAAC;IAC/C,OAAO;QACL,KAAK,EAAE;YACL,IAAI,EAAE,oBAAoB;YAC1B,OAAO,EAAE;gBACP,EAAE,EAAE,EAAE;gBACN,KAAK;gBACL,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;gBACnD,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE;aAC7B;YACD,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE;SAClC;QACD,QAAQ,CAAC,KAAK;YACZ,IAAI,CAAC,KAAK,CAAC,QAAQ;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|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { NativeAdapterOptions } from './types.js';
|
|
2
|
+
export type AcpObject = Record<string, unknown>;
|
|
3
|
+
export declare function acpObject(value: unknown): AcpObject;
|
|
4
|
+
export declare function acpString(value: unknown): string;
|
|
5
|
+
/** ACP uses JSON-RPC 2.0; a prompt response may take the entire agent turn. */
|
|
6
|
+
export declare class AcpRpc {
|
|
7
|
+
private process;
|
|
8
|
+
private nextId;
|
|
9
|
+
private pending;
|
|
10
|
+
constructor(options: NativeAdapterOptions, args: string[], onMessage: (message: AcpObject) => void, onExit: (error: Error | undefined, stopped: boolean) => void);
|
|
11
|
+
request(method: string, params: unknown, timeoutMs?: number | null): Promise<unknown>;
|
|
12
|
+
write(message: AcpObject): void;
|
|
13
|
+
close(): Promise<void>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=acp-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acp-rpc.d.ts","sourceRoot":"","sources":["../../src/native/acp-rpc.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAChD,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,CAInD;AACD,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAGhD;AAED,+EAA+E;AAC/E,qBAAa,MAAM;IACjB,OAAO,CAAC,OAAO,CAAkB;IACjC,OAAO,CAAC,MAAM,CAAK;IACnB,OAAO,CAAC,OAAO,CAOX;gBAGF,OAAO,EAAE,oBAAoB,EAC7B,IAAI,EAAE,MAAM,EAAE,EACd,SAAS,EAAE,CAAC,OAAO,EAAE,SAAS,KAAK,IAAI,EACvC,MAAM,EAAE,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI;IAoC9D,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,GAAE,MAAM,GAAG,IAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAoB7F,KAAK,CAAC,OAAO,EAAE,SAAS,GAAG,IAAI;IAG/B,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAGvB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { JsonLineProcess } from './process.js';
|
|
2
|
+
export function acpObject(value) {
|
|
3
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
4
|
+
throw new Error('Expected an ACP object');
|
|
5
|
+
return value;
|
|
6
|
+
}
|
|
7
|
+
export function acpString(value) {
|
|
8
|
+
if (typeof value !== 'string')
|
|
9
|
+
throw new Error('Expected an ACP string');
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
/** ACP uses JSON-RPC 2.0; a prompt response may take the entire agent turn. */
|
|
13
|
+
export class AcpRpc {
|
|
14
|
+
constructor(options, args, onMessage, onExit) {
|
|
15
|
+
this.nextId = 0;
|
|
16
|
+
this.pending = new Map();
|
|
17
|
+
this.process = new JsonLineProcess(options.executable, args, options, (message) => {
|
|
18
|
+
if (message.jsonrpc !== '2.0')
|
|
19
|
+
throw new Error('Expected ACP JSON-RPC 2.0');
|
|
20
|
+
const pending = typeof message.id === 'string' && !message.method
|
|
21
|
+
? this.pending.get(message.id)
|
|
22
|
+
: undefined;
|
|
23
|
+
if (!pending) {
|
|
24
|
+
onMessage(message);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
const error = message.error === undefined ? undefined : acpObject(message.error);
|
|
28
|
+
const failure = error
|
|
29
|
+
? new Error(`ACP request failed (${String(error.code)}): ${acpString(error.message)}`)
|
|
30
|
+
: undefined;
|
|
31
|
+
this.pending.delete(message.id);
|
|
32
|
+
clearTimeout(pending.timer);
|
|
33
|
+
if (failure)
|
|
34
|
+
pending.reject(failure);
|
|
35
|
+
else
|
|
36
|
+
pending.resolve(message.result);
|
|
37
|
+
}, (error, stopped) => {
|
|
38
|
+
for (const pending of this.pending.values()) {
|
|
39
|
+
clearTimeout(pending.timer);
|
|
40
|
+
pending.reject(error ?? new Error('ACP process closed'));
|
|
41
|
+
}
|
|
42
|
+
this.pending.clear();
|
|
43
|
+
onExit(error, stopped);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
request(method, params, timeoutMs = 30_000) {
|
|
47
|
+
const id = `farmslot-acp-${++this.nextId}`;
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const timer = timeoutMs === null
|
|
50
|
+
? undefined
|
|
51
|
+
: setTimeout(() => {
|
|
52
|
+
this.pending.delete(id);
|
|
53
|
+
reject(new Error(`ACP request timed out: ${method}; acceptance is unknown`));
|
|
54
|
+
}, timeoutMs);
|
|
55
|
+
this.pending.set(id, { resolve, reject, timer });
|
|
56
|
+
try {
|
|
57
|
+
this.write({ id, method, params });
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
clearTimeout(timer);
|
|
61
|
+
this.pending.delete(id);
|
|
62
|
+
reject(error);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
write(message) {
|
|
67
|
+
this.process.write({ jsonrpc: '2.0', ...message });
|
|
68
|
+
}
|
|
69
|
+
close() {
|
|
70
|
+
return this.process.close();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=acp-rpc.js.map
|