@quadient/skillshare 1.17.1 → 1.18.1
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/README.md +13 -7
- package/dist/agents-claude.js +110 -9
- package/dist/agents-codex.js +171 -12
- package/dist/agents-detect.js +84 -12
- package/dist/agents-form-worker.js +33 -0
- package/dist/agents-forms.js +79 -0
- package/dist/agents-process.js +12 -1
- package/dist/agents-request-upload.js +55 -0
- package/dist/agents-response-hash.js +31 -0
- package/dist/agents-service.js +17 -1
- package/dist/agents-session.js +152 -5
- package/dist/agents-settings.js +133 -0
- package/dist/agents.js +106 -22
- package/dist/cli-args.js +3 -0
- package/dist/help.js +4 -4
- package/package.json +4 -2
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { link, lstat, mkdir, open, readFile, rename, rm } from 'node:fs/promises';
|
|
3
|
+
import { dirname } from 'node:path';
|
|
4
|
+
export const APPROVAL_MODES = ['supervised', 'autoEdits', 'auto', 'fullAccess'];
|
|
5
|
+
export function withoutLegacySandboxArgs(args) {
|
|
6
|
+
return args.filter((arg, index) => !/^--sandbox(?:=(?:true|false))?$/.test(arg)
|
|
7
|
+
&& !(args[index - 1] === '--sandbox' && (arg === 'true' || arg === 'false')));
|
|
8
|
+
}
|
|
9
|
+
/** Update only a regular file, retaining unknown fields and refusing concurrent changes. Never start on a failed migration. */
|
|
10
|
+
export async function updateAgentJson(path, transform) {
|
|
11
|
+
await mkdir(dirname(path), { recursive: true, mode: 0o700 });
|
|
12
|
+
const lock = await open(`${path}.migration.lock`, 'wx', 0o600).catch(error => {
|
|
13
|
+
throw new Error(`Cannot acquire settings migration lock ${path}.migration.lock. Check for another listener or a lock left by an interrupted migration: ${error.message}`);
|
|
14
|
+
});
|
|
15
|
+
const temporary = `${path}.${randomUUID()}.tmp`;
|
|
16
|
+
const backup = `${path}.${randomUUID()}.migration-backup`;
|
|
17
|
+
let movedOriginal = false;
|
|
18
|
+
try {
|
|
19
|
+
const before = await lstat(path).catch(error => { if (error.code === 'ENOENT')
|
|
20
|
+
return null; throw error; });
|
|
21
|
+
if (before && (!before.isFile() || before.isSymbolicLink()))
|
|
22
|
+
throw new Error(`Cannot migrate non-regular agent settings: ${path}`);
|
|
23
|
+
const original = before ? await readFile(path, 'utf8') : null;
|
|
24
|
+
const value = original === null ? {} : JSON.parse(original);
|
|
25
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
26
|
+
throw new Error(`Agent settings must be an object: ${path}`);
|
|
27
|
+
const previous = JSON.stringify(value);
|
|
28
|
+
transform(value);
|
|
29
|
+
if (JSON.stringify(value) === previous)
|
|
30
|
+
return value;
|
|
31
|
+
await writeTemporary();
|
|
32
|
+
const current = await lstat(path).catch(error => { if (error.code === 'ENOENT')
|
|
33
|
+
return null; throw error; });
|
|
34
|
+
if (Boolean(current) !== Boolean(before) || current && (!current.isFile() || current.isSymbolicLink()
|
|
35
|
+
|| current.ino !== before.ino || current.mtimeMs !== before.mtimeMs || await readFile(path, 'utf8') !== original))
|
|
36
|
+
throw new Error(`Agent settings changed during migration; retry: ${path}`);
|
|
37
|
+
if (before) {
|
|
38
|
+
// Move the actual original first: checking before a replacing rename cannot protect a last-moment user edit.
|
|
39
|
+
await rename(path, backup);
|
|
40
|
+
movedOriginal = true;
|
|
41
|
+
const moved = await lstat(backup);
|
|
42
|
+
if (!moved.isFile() || moved.isSymbolicLink() || moved.ino !== before.ino || moved.mtimeMs !== before.mtimeMs
|
|
43
|
+
|| await readFile(backup, 'utf8') !== original)
|
|
44
|
+
throw new Error('Agent settings changed during migration.');
|
|
45
|
+
}
|
|
46
|
+
// Hard-link publication is create-if-absent: a concurrently created path is never overwritten.
|
|
47
|
+
await link(temporary, path);
|
|
48
|
+
// Keep the old inode available: an editor may still hold it open and write into it after publication.
|
|
49
|
+
return value;
|
|
50
|
+
async function writeTemporary() {
|
|
51
|
+
const file = await open(temporary, 'wx', before ? before.mode & 0o777 : 0o600);
|
|
52
|
+
try {
|
|
53
|
+
await file.writeFile(`${JSON.stringify(value, null, 2)}\n`);
|
|
54
|
+
await file.sync();
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
await file.close();
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
let recovery = '';
|
|
63
|
+
if (movedOriginal) {
|
|
64
|
+
recovery = ` Original settings are preserved at ${backup}.`;
|
|
65
|
+
try {
|
|
66
|
+
await link(backup, path);
|
|
67
|
+
}
|
|
68
|
+
catch (restoreError) {
|
|
69
|
+
if (restoreError.code !== 'EEXIST')
|
|
70
|
+
recovery += ' Restore that file after resolving the filesystem error.';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
throw new Error(`Could not load or migrate agent settings ${path}: ${error instanceof Error ? error.message : String(error)}${recovery}`);
|
|
74
|
+
}
|
|
75
|
+
finally {
|
|
76
|
+
await rm(temporary, { force: true });
|
|
77
|
+
await lock.close();
|
|
78
|
+
await rm(`${path}.migration.lock`, { force: true });
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** Local values seed web defaults once; they never constrain a session selected in Skillshare. */
|
|
82
|
+
export function migrateAgentSettings(value, legacySandbox = false) {
|
|
83
|
+
const migrate = (settings) => {
|
|
84
|
+
if (settings.sandbox !== undefined && typeof settings.sandbox !== 'boolean')
|
|
85
|
+
throw new Error('sandbox must be true or false.');
|
|
86
|
+
if (settings.sandbox === true)
|
|
87
|
+
settings.approvalMode = 'auto';
|
|
88
|
+
delete settings.sandbox;
|
|
89
|
+
if (settings.approvalMode !== undefined && !APPROVAL_MODES.includes(settings.approvalMode))
|
|
90
|
+
throw new Error('Invalid approvalMode.');
|
|
91
|
+
};
|
|
92
|
+
migrate(value);
|
|
93
|
+
if (legacySandbox && value.approvalMode === undefined)
|
|
94
|
+
value.approvalMode = 'auto';
|
|
95
|
+
if (Array.isArray(value.profiles))
|
|
96
|
+
value.profiles.forEach(profile => {
|
|
97
|
+
if (profile && typeof profile === 'object' && !Array.isArray(profile))
|
|
98
|
+
migrate(profile);
|
|
99
|
+
});
|
|
100
|
+
return value;
|
|
101
|
+
}
|
|
102
|
+
export async function loadAgentSettings(path, legacySandbox = false) {
|
|
103
|
+
const assertUnlocked = async () => {
|
|
104
|
+
if (await lstat(`${path}.migration.lock`).catch(error => { if (error.code === 'ENOENT')
|
|
105
|
+
return null; throw error; }))
|
|
106
|
+
throw new Error(`Agent settings migration is in progress or was interrupted. Check ${path}.migration.lock before retrying.`);
|
|
107
|
+
};
|
|
108
|
+
await assertUnlocked();
|
|
109
|
+
const file = await lstat(path).catch(error => { if (error.code === 'ENOENT')
|
|
110
|
+
return null; throw error; });
|
|
111
|
+
if (file && (!file.isFile() || file.isSymbolicLink()))
|
|
112
|
+
throw new Error(`Cannot migrate non-regular agent settings: ${path}`);
|
|
113
|
+
let value;
|
|
114
|
+
try {
|
|
115
|
+
value = file ? JSON.parse(await readFile(path, 'utf8')) : {};
|
|
116
|
+
await assertUnlocked();
|
|
117
|
+
const current = await lstat(path).catch(error => { if (error.code === 'ENOENT')
|
|
118
|
+
return null; throw error; });
|
|
119
|
+
if (Boolean(current) !== Boolean(file) || current && (!current.isFile() || current.isSymbolicLink()
|
|
120
|
+
|| current.ino !== file.ino || current.mtimeMs !== file.mtimeMs))
|
|
121
|
+
throw new Error('Agent settings changed while reading; retry.');
|
|
122
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
123
|
+
throw new Error('Agent settings must be an object.');
|
|
124
|
+
const previous = JSON.stringify(value);
|
|
125
|
+
migrateAgentSettings(value, legacySandbox);
|
|
126
|
+
if (JSON.stringify(value) === previous)
|
|
127
|
+
return value;
|
|
128
|
+
}
|
|
129
|
+
catch (error) {
|
|
130
|
+
throw new Error(`Could not load or migrate agent settings ${path}: ${error instanceof Error ? error.message : String(error)}`);
|
|
131
|
+
}
|
|
132
|
+
return updateAgentJson(path, settings => { migrateAgentSettings(settings, legacySandbox); });
|
|
133
|
+
}
|
package/dist/agents.js
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { createHash, randomBytes } from 'node:crypto';
|
|
2
|
-
import { mkdir, readFile, rm, writeFile } from 'node:fs/promises';
|
|
3
|
-
import { hostname, platform, tmpdir } from 'node:os';
|
|
4
|
-
import { dirname, join } from 'node:path';
|
|
2
|
+
import { mkdir, readFile, readdir, rm, stat, writeFile } from 'node:fs/promises';
|
|
3
|
+
import { hostname, homedir, platform, tmpdir } from 'node:os';
|
|
4
|
+
import { dirname, isAbsolute, join } from 'node:path';
|
|
5
5
|
import { setTimeout as delay } from 'node:timers/promises';
|
|
6
6
|
import { createClaudeDriver } from './agents-claude.js';
|
|
7
|
-
import { defaultServiceEnvironment, detectServiceAgents, installService, renderServiceStatus, serviceLogs, serviceStatus, uninstallService, } from './agents-service.js';
|
|
7
|
+
import { defaultServiceEnvironment, detectServiceAgents, installService, migrateServiceApprovalOptions, renderServiceStatus, serviceLogs, serviceStatus, uninstallService, } from './agents-service.js';
|
|
8
8
|
import { createCodexDriver } from './agents-codex.js';
|
|
9
9
|
import { detectAgents, expandHome, profilesPath } from './agents-detect.js';
|
|
10
|
+
import { loadAgentSettings, withoutLegacySandboxArgs } from './agents-settings.js';
|
|
10
11
|
import { SessionRunner, errorMessage, } from './agents-session.js';
|
|
11
12
|
import { RESTART_FOR_UPDATE, SERVICE_ENV, WORKER_ENV, acquireListenerLock, compareVersions, describeOtherListener, installVersion, isReleaseVersion, releaseListenerLock, superviseListener, } from './agents-update.js';
|
|
12
13
|
import { readCliVersion } from './help.js';
|
|
14
|
+
import { uploadSessionEvents } from './agents-request-upload.js';
|
|
15
|
+
import { responseFingerprint } from './agents-response-hash.js';
|
|
13
16
|
const root = '/api/agents';
|
|
14
17
|
const PROFILE_HINT = 'Declare named profiles in ' + profilesPath() + ' to set a working directory or extra arguments.';
|
|
15
18
|
export class AgentsHttpError extends Error {
|
|
@@ -101,9 +104,16 @@ export async function runAgentsCommand(client, args, flags, appDirectory, teamsW
|
|
|
101
104
|
const max = maxConcurrency(flags);
|
|
102
105
|
const worker = process.env[WORKER_ENV] === '1';
|
|
103
106
|
const service = process.env[SERVICE_ENV] === '1';
|
|
107
|
+
if (service)
|
|
108
|
+
await migrateServiceApprovalOptions(appDirectory);
|
|
109
|
+
if (flags.sandbox === 'true') {
|
|
110
|
+
await loadAgentSettings(profilesPath(), true);
|
|
111
|
+
console.log('--sandbox was migrated to the Auto approval default. Change approval modes in Skillshare.');
|
|
112
|
+
}
|
|
104
113
|
// The listener runs under a supervisor that starts it again on a newer CLI, unless updates are turned off.
|
|
105
114
|
if (!worker && flags['no-update'] !== 'true') {
|
|
106
|
-
const
|
|
115
|
+
const args = withoutLegacySandboxArgs(process.argv.slice(2));
|
|
116
|
+
const code = await superviseListener({ appDir: appDirectory, args, ownVersion: readCliVersion(), logFile: flags['log-file'], service });
|
|
107
117
|
if (code !== 0)
|
|
108
118
|
process.exitCode = code;
|
|
109
119
|
return;
|
|
@@ -114,7 +124,6 @@ export async function runAgentsCommand(client, args, flags, appDirectory, teamsW
|
|
|
114
124
|
throw new Error(describeOtherListener(other));
|
|
115
125
|
}
|
|
116
126
|
const workdir = expandHome(flags.workdir ?? process.cwd());
|
|
117
|
-
const sandbox = flags.sandbox === 'true';
|
|
118
127
|
const user = await client.get('/api/auth/me');
|
|
119
128
|
const listenerId = await loadListenerId(appDirectory, client.baseUrl, user.id);
|
|
120
129
|
const abort = new AbortController();
|
|
@@ -122,9 +131,7 @@ export async function runAgentsCommand(client, args, flags, appDirectory, teamsW
|
|
|
122
131
|
const stop = () => abort.abort();
|
|
123
132
|
process.on('SIGINT', stop);
|
|
124
133
|
process.on('SIGTERM', stop);
|
|
125
|
-
console.log(
|
|
126
|
-
? 'Sandboxed: agents may read files, search and use the Skillshare MCP tools, but cannot change files or run commands that modify anything.'
|
|
127
|
-
: 'Agents run with your full local permissions and configuration, without permission prompts. Use --sandbox to keep them read-only.');
|
|
134
|
+
console.log('Sessions use the approval mode selected in Skillshare. Already-created sessions retain their permissions.');
|
|
128
135
|
console.log('Sessions keep their agent running between messages and close it after 15 quiet minutes; the next message resumes it.');
|
|
129
136
|
// Teams 👀 sessions need a live Teams session, so the listener keeps it renewed unless told not to.
|
|
130
137
|
const teams = teamsWatch && flags['no-teams-watch'] !== 'true'
|
|
@@ -134,7 +141,7 @@ export async function runAgentsCommand(client, args, flags, appDirectory, teamsW
|
|
|
134
141
|
let result = 'stopped';
|
|
135
142
|
try {
|
|
136
143
|
result = await listen({
|
|
137
|
-
client, listenerId, name: flags.name, workdir, maxConcurrency: max,
|
|
144
|
+
client, listenerId, name: flags.name, workdir, maxConcurrency: max, signal: abort.signal, onProgress: console.log, service,
|
|
138
145
|
detect: service ? () => detectServiceAgents(appDirectory) : undefined,
|
|
139
146
|
updater: worker ? { currentVersion: readCliVersion(), prepare: version => installVersion(appDirectory, version) } : undefined,
|
|
140
147
|
});
|
|
@@ -165,7 +172,7 @@ export function serviceListenArgs(flags) {
|
|
|
165
172
|
for (const key of ['name', 'max-concurrency', 'browser', 'browser-profile'])
|
|
166
173
|
if (flags[key] !== undefined)
|
|
167
174
|
args.push(`--${key}`, flags[key]);
|
|
168
|
-
for (const key of ['
|
|
175
|
+
for (const key of ['no-teams-watch', 'headless'])
|
|
169
176
|
if (flags[key] === 'true')
|
|
170
177
|
args.push(`--${key}`);
|
|
171
178
|
return args;
|
|
@@ -178,6 +185,10 @@ export async function runServiceCommand(action, flags, appDirectory, server) {
|
|
|
178
185
|
if (!server)
|
|
179
186
|
throw new Error('agents service install needs a Skillshare server.');
|
|
180
187
|
maxConcurrency(flags);
|
|
188
|
+
if (flags.sandbox === 'true') {
|
|
189
|
+
await loadAgentSettings(profilesPath(), true);
|
|
190
|
+
console.log('--sandbox was migrated to the Auto approval default. Change approval modes in Skillshare.');
|
|
191
|
+
}
|
|
181
192
|
const workdir = expandHome(flags.workdir ?? process.cwd());
|
|
182
193
|
const version = readCliVersion();
|
|
183
194
|
console.log(`Installing Skillshare CLI ${version} for the agents service…`);
|
|
@@ -224,7 +235,7 @@ export function renderDetected(listenerId, server, detected) {
|
|
|
224
235
|
if (detected.profiles.length === 0)
|
|
225
236
|
lines.push(PROFILE_HINT);
|
|
226
237
|
for (const profile of detected.profiles)
|
|
227
|
-
lines.push(`Profile ${profile.name}: ${profile.agent}${profile.model ? ' ' + profile.model : ''}${profile.reasoning ? ' ' + profile.reasoning : ''}${profile.workdir ? ' in ' + profile.workdir : ''}${profile.
|
|
238
|
+
lines.push(`Profile ${profile.name}: ${profile.agent}${profile.model ? ' ' + profile.model : ''}${profile.reasoning ? ' ' + profile.reasoning : ''}${profile.workdir ? ' in ' + profile.workdir : ''}${profile.defaultApprovalMode ? ` (${profile.defaultApprovalMode})` : ''}`);
|
|
228
239
|
for (const problem of detected.problems)
|
|
229
240
|
lines.push(`! ${problem}`);
|
|
230
241
|
return lines.join('\n');
|
|
@@ -236,8 +247,10 @@ export async function listen(options) {
|
|
|
236
247
|
const driver = options.driver ?? (start => start.configuration.agent === 'codex' ? codex : claude);
|
|
237
248
|
const wait = options.wait ?? (async (ms, signal) => { await delay(ms, undefined, { signal }); });
|
|
238
249
|
const now = options.now ?? Date.now;
|
|
250
|
+
const leaseNow = () => performance.now();
|
|
239
251
|
const log = options.onProgress ?? (() => { });
|
|
240
252
|
const sessions = new Map();
|
|
253
|
+
const browsing = new Map();
|
|
241
254
|
// Messages reach a session in order even while earlier ones still download their images.
|
|
242
255
|
const deliveries = new Map();
|
|
243
256
|
const imageRoot = options.imageDirectory ?? join(tmpdir(), 'skillshare-agents');
|
|
@@ -274,13 +287,22 @@ export async function listen(options) {
|
|
|
274
287
|
log(`! Could not download Skillshare CLI ${version} (${error instanceof Error ? error.message : String(error)}). Trying again in 30 minutes.`);
|
|
275
288
|
}).finally(() => { updating = null; });
|
|
276
289
|
}
|
|
277
|
-
const capabilities = () =>
|
|
290
|
+
const capabilities = () => ({ ...detected.capabilities, sessionApprovals: true });
|
|
278
291
|
async function register() {
|
|
279
292
|
const fingerprint = JSON.stringify(capabilities());
|
|
280
|
-
const
|
|
293
|
+
const requiresApprovalDefaults = Boolean(capabilities().defaultApprovalMode || capabilities().profiles.some(profile => profile.defaultApprovalMode));
|
|
294
|
+
// A dedicated route rejects an older server before it can overwrite restrictions or dispatch queued work.
|
|
295
|
+
const path = `${root}/listeners/${options.listenerId}${requiresApprovalDefaults ? '/register' : ''}`;
|
|
296
|
+
const registered = await send(options.client, 'PUT', path, {
|
|
281
297
|
name: options.name ?? hostname(), host: hostname(), os: platform(), cliVersion: readCliVersion(), maxConcurrency: options.maxConcurrency,
|
|
282
298
|
capabilities: capabilities(), service: options.service === true, autoUpdate: options.updater !== undefined,
|
|
283
|
-
}, options.signal)
|
|
299
|
+
}, options.signal).catch(error => {
|
|
300
|
+
if (requiresApprovalDefaults && error instanceof AgentsHttpError && error.status === 404)
|
|
301
|
+
throw new Error('Update Skillshare before connecting this listener; this server does not support safe approval-default registration.');
|
|
302
|
+
throw error;
|
|
303
|
+
});
|
|
304
|
+
if (requiresApprovalDefaults && (registered?.approvalDefaultsVersion ?? 0) < 1)
|
|
305
|
+
throw new Error('Update Skillshare before using migrated approval defaults; this server cannot acknowledge them safely.');
|
|
284
306
|
registeredFingerprint = fingerprint;
|
|
285
307
|
for (const problem of detected.problems)
|
|
286
308
|
log(`! ${problem}`);
|
|
@@ -288,30 +310,48 @@ export async function listen(options) {
|
|
|
288
310
|
}
|
|
289
311
|
/** Posts a batch of session events: a rejected lease means the server moved on and the agent must stop. */
|
|
290
312
|
function uploader(sessionId, leaseToken) {
|
|
313
|
+
const acknowledged = new WeakSet();
|
|
291
314
|
return async (events) => {
|
|
292
315
|
try {
|
|
293
|
-
await send(options.client, 'POST', `${root}/sessions/${sessionId}
|
|
316
|
+
await uploadSessionEvents(events, leaseToken, (suffix, body) => send(options.client, 'POST', `${root}/sessions/${sessionId}${suffix}`, body), acknowledged);
|
|
294
317
|
return 'ok';
|
|
295
318
|
}
|
|
296
319
|
catch (error) {
|
|
297
|
-
if (error instanceof AgentsHttpError && error.status >= 400 && error.status < 500)
|
|
320
|
+
if (error instanceof AgentsHttpError && error.status >= 400 && error.status < 500 && error.status !== 413)
|
|
298
321
|
return 'gone';
|
|
299
322
|
return 'retry';
|
|
300
323
|
}
|
|
301
324
|
};
|
|
302
325
|
}
|
|
303
|
-
function start(command) {
|
|
326
|
+
function start(command, polledAt) {
|
|
304
327
|
if (!command.start || !command.leaseToken)
|
|
305
328
|
return;
|
|
329
|
+
if (!Number.isFinite(command.leaseRemainingMs) || command.leaseRemainingMs <= 0 || polledAt + command.leaseRemainingMs <= leaseNow()) {
|
|
330
|
+
log('! Ignored a start without a current lease. Update Skillshare if this persists.');
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
306
333
|
// A start for a session already held replaces its agent, for example to hand it fresh credentials.
|
|
307
334
|
const previous = sessions.get(command.sessionId);
|
|
308
335
|
if (previous)
|
|
309
336
|
void previous.stop();
|
|
310
337
|
const profile = command.start.configuration.profile ? detected.profiles.find(p => p.name === command.start.configuration.profile) : undefined;
|
|
338
|
+
const mode = command.start.configuration.approvalMode;
|
|
339
|
+
const supported = detected.capabilities.agents.find(agent => agent.kind === command.start.configuration.agent)?.approvalModes;
|
|
340
|
+
if (mode && !supported?.includes(mode)) {
|
|
341
|
+
void uploader(command.sessionId, command.leaseToken)([{ type: 'closed', error: `The installed ${command.start.configuration.agent} does not advertise support for approval mode ${mode}. Update the agent and let the listener refresh its capabilities.` }]);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
311
344
|
const runner = new SessionRunner({
|
|
312
|
-
sessionId: command.sessionId, leaseToken: command.leaseToken, start: command.start, workdir: options.workdir, profile, sandbox:
|
|
345
|
+
sessionId: command.sessionId, leaseToken: command.leaseToken, start: command.start, workdir: options.workdir, profile, sandbox: false,
|
|
313
346
|
driver: driver(command.start), upload: uploader(command.sessionId, command.leaseToken), idleMs: options.idleMs, flushIntervalMs: options.flushIntervalMs,
|
|
314
347
|
now,
|
|
348
|
+
leaseNow, leaseDeadline: polledAt + command.leaseRemainingMs,
|
|
349
|
+
authorizeResponse: async (response) => {
|
|
350
|
+
const result = await send(options.client, 'POST', `${root}/listeners/${options.listenerId}/sessions/${command.sessionId}/authorize-response`, {
|
|
351
|
+
leaseToken: command.leaseToken, requestId: response.requestId, revision: response.revision ?? 0, responseHash: responseFingerprint(response),
|
|
352
|
+
}, options.signal);
|
|
353
|
+
return result?.authorized === true;
|
|
354
|
+
},
|
|
315
355
|
});
|
|
316
356
|
sessions.set(command.sessionId, runner);
|
|
317
357
|
log(`${command.start.resumeThreadId ? 'Resumed' : 'Started'} session ${command.sessionId} "${command.start.title}" with ${label(command.start)}.`);
|
|
@@ -336,14 +376,24 @@ export async function listen(options) {
|
|
|
336
376
|
void next.finally(() => { if (deliveries.get(runner.sessionId) === next)
|
|
337
377
|
deliveries.delete(runner.sessionId); });
|
|
338
378
|
}
|
|
339
|
-
function handle(command) {
|
|
379
|
+
function handle(command, polledAt) {
|
|
380
|
+
if (command.type === 'browse' && command.requestId) {
|
|
381
|
+
if (browsing.has(command.requestId))
|
|
382
|
+
return;
|
|
383
|
+
const task = browseDirectories(command.path ?? '').then(result => send(options.client, 'POST', `${root}/listeners/${options.listenerId}/directories/${encodeURIComponent(command.requestId)}`, result)).then(() => { })
|
|
384
|
+
.catch(error => log(`! Directory browsing failed: ${errorMessage(error)}`))
|
|
385
|
+
.finally(() => { browsing.delete(command.requestId); });
|
|
386
|
+
browsing.set(command.requestId, task);
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
340
389
|
// The id names a local directory that is later deleted, so it must not be able to point elsewhere.
|
|
341
390
|
if (!isSessionId(command.sessionId))
|
|
342
391
|
return log(`! Ignored a command for an invalid session id.`);
|
|
343
392
|
const runner = sessions.get(command.sessionId);
|
|
344
393
|
switch (command.type) {
|
|
345
|
-
case 'start': return start(command);
|
|
394
|
+
case 'start': return start(command, polledAt);
|
|
346
395
|
case 'send': return runner && deliver(runner, command.messages ?? []);
|
|
396
|
+
case 'respond': return command.response && runner?.respond(command.response);
|
|
347
397
|
case 'interrupt': return void runner?.interrupt();
|
|
348
398
|
case 'close': return void runner?.close();
|
|
349
399
|
}
|
|
@@ -363,14 +413,20 @@ export async function listen(options) {
|
|
|
363
413
|
if (registeredFingerprint !== JSON.stringify(capabilities()))
|
|
364
414
|
await register();
|
|
365
415
|
const polledAt = now();
|
|
416
|
+
const leasePolledAt = leaseNow();
|
|
366
417
|
const response = await send(options.client, 'POST', `${root}/listeners/${options.listenerId}/poll`, {
|
|
367
418
|
// A session that is already closing is not reported, so the server treats its agent as gone.
|
|
368
419
|
sessions: [...sessions.values()].filter(r => !r.stopping).map(r => ({ sessionId: r.sessionId, leaseToken: r.leaseToken })),
|
|
369
420
|
waitSeconds: options.pollWaitSeconds ?? 25,
|
|
370
421
|
}, options.signal);
|
|
371
422
|
failures = 0;
|
|
423
|
+
for (const snapshot of response.leases ?? []) {
|
|
424
|
+
const runner = sessions.get(snapshot.sessionId);
|
|
425
|
+
if (runner?.leaseToken === snapshot.leaseToken && Number.isFinite(snapshot.remainingMs))
|
|
426
|
+
runner.renewLease(leasePolledAt + Math.max(0, snapshot.remainingMs));
|
|
427
|
+
}
|
|
372
428
|
for (const command of response.commands)
|
|
373
|
-
handle(command);
|
|
429
|
+
handle(command, leasePolledAt);
|
|
374
430
|
considerUpdate(response.cliVersion);
|
|
375
431
|
if (response.commands.length === 0 && now() - polledAt < 1000)
|
|
376
432
|
await wait(1000, options.signal).catch(() => { });
|
|
@@ -400,6 +456,34 @@ export async function listen(options) {
|
|
|
400
456
|
}
|
|
401
457
|
return result;
|
|
402
458
|
}
|
|
459
|
+
/** Browse the listener's filesystem without starting an agent or passing a path through a shell. */
|
|
460
|
+
export async function browseDirectories(path) {
|
|
461
|
+
try {
|
|
462
|
+
if (!path) {
|
|
463
|
+
const roots = process.platform === 'win32'
|
|
464
|
+
? (await Promise.all(Array.from({ length: 26 }, (_, i) => `${String.fromCharCode(65 + i)}:\\`).map(async (root) => {
|
|
465
|
+
try {
|
|
466
|
+
return (await stat(root)).isDirectory() ? root : null;
|
|
467
|
+
}
|
|
468
|
+
catch {
|
|
469
|
+
return null;
|
|
470
|
+
}
|
|
471
|
+
}))).filter((value) => value !== null) : ['/'];
|
|
472
|
+
const directories = [...new Set([homedir(), ...roots])].map(value => ({ name: value, path: value }));
|
|
473
|
+
return { path: '', directories };
|
|
474
|
+
}
|
|
475
|
+
if (!isAbsolute(path))
|
|
476
|
+
throw new Error('Choose an absolute directory on the connected computer.');
|
|
477
|
+
const entries = await readdir(path, { withFileTypes: true });
|
|
478
|
+
const directories = entries.filter(entry => entry.isDirectory()).sort((a, b) => a.name.localeCompare(b.name)).slice(0, 1000)
|
|
479
|
+
.map(entry => ({ name: entry.name, path: join(path, entry.name) }))
|
|
480
|
+
.filter(entry => entry.name.length <= 500 && entry.path.length <= 2000);
|
|
481
|
+
return { path, ...(dirname(path) !== path ? { parent: dirname(path) } : {}), directories };
|
|
482
|
+
}
|
|
483
|
+
catch (error) {
|
|
484
|
+
return { path, directories: [], error: errorMessage(error).slice(0, 2000) };
|
|
485
|
+
}
|
|
486
|
+
}
|
|
403
487
|
function label(start) {
|
|
404
488
|
const { configuration } = start;
|
|
405
489
|
if (configuration.profile)
|
package/dist/cli-args.js
CHANGED
|
@@ -51,6 +51,9 @@ function assertKnownFlag(commandName, name) {
|
|
|
51
51
|
const command = findCommand(commandName);
|
|
52
52
|
if (!command)
|
|
53
53
|
return;
|
|
54
|
+
// Compatibility only: old service launchers and scripts still reach the approval-default migration.
|
|
55
|
+
if (command.name === 'agents' && name === 'sandbox')
|
|
56
|
+
return;
|
|
54
57
|
const allowed = [...GLOBAL_FLAGS, ...command.flags];
|
|
55
58
|
if (allowed.includes(name))
|
|
56
59
|
return;
|
package/dist/help.js
CHANGED
|
@@ -132,14 +132,14 @@ export const COMMANDS = [
|
|
|
132
132
|
name: 'agents',
|
|
133
133
|
summary: 'Run Claude Code or Codex sessions from Skillshare on this computer',
|
|
134
134
|
usage: [
|
|
135
|
-
'agents listen [local] [--name <name>] [--workdir <directory>] [--max-concurrency <1-4>] [--
|
|
135
|
+
'agents listen [local] [--name <name>] [--workdir <directory>] [--max-concurrency <1-4>] [--no-teams-watch] [--no-update]',
|
|
136
136
|
'agents status [local] [--json]',
|
|
137
|
-
'agents service install [local] [--name <name>] [--workdir <directory>] [--max-concurrency <1-4>] [--
|
|
137
|
+
'agents service install [local] [--name <name>] [--workdir <directory>] [--max-concurrency <1-4>] [--no-teams-watch]',
|
|
138
138
|
'agents service status | logs [--lines <n>] | uninstall',
|
|
139
139
|
],
|
|
140
|
-
description: 'A listener reports the installed agents, their models and reasoning levels, and the local profiles from ~/.config/skillshare/agents.json. It runs Claude Code and Codex sessions that you start and continue under Sessions in Skillshare; under Connected agents you choose which listener and configuration runs Teams 👀 sessions. Agents use your own login and
|
|
140
|
+
description: 'A listener reports the installed agents, their models and reasoning levels, and the local profiles from ~/.config/skillshare/agents.json. It runs Claude Code and Codex sessions that you start and continue under Sessions in Skillshare; under Connected agents you choose which listener and configuration runs Teams 👀 sessions. Agents use your own login and the approval mode chosen in Skillshare: Supervised, Auto-accept edits, Auto or Full access. Already-created sessions retain their permissions. An idle agent is stopped after 15 minutes and resumed by the next message. With a Teams connection, the listener also keeps the Teams session renewed through local browser SSO, as skillshare teams watch does; --no-teams-watch turns that off. The listener updates itself: when Skillshare releases a newer CLI, it downloads it and restarts on it once no turn is running (--no-update turns that off). agents service install runs the listener in the background, started at every login (a launchd agent on macOS, a systemd user service on Linux, a scheduled task on Windows); status, logs and uninstall manage it.',
|
|
141
141
|
examples: ['skillshare agents status', 'skillshare agents listen --workdir ~/Research', 'skillshare agents service install --workdir ~/Research'],
|
|
142
|
-
flags: ['name', 'workdir', 'max-concurrency', '
|
|
142
|
+
flags: ['name', 'workdir', 'max-concurrency', 'no-teams-watch', 'no-update', 'log-file', 'lines', 'browser', 'headless', 'browser-profile', 'json'],
|
|
143
143
|
},
|
|
144
144
|
{
|
|
145
145
|
name: 'git',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quadient/skillshare",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.18.1",
|
|
4
4
|
"description": "Skillshare CLI for installing and publishing Quadient skills",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"build": "rm -rf dist && tsc -p tsconfig.build.json && node -e \"require('node:fs').copyFileSync('page-browser-client.js', 'dist/page-browser-client.js')\"",
|
|
17
17
|
"start": "node ./dist/index.js",
|
|
18
18
|
"prepublishOnly": "npm run build",
|
|
19
|
-
"test": "tsx --test session-auth.test.ts cli-args.test.ts install-files.test.ts removed-skills.test.ts output.test.ts pages.test.ts page-links.test.ts pages-secrets.test.ts pages-comments.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-update.test.ts login-callback.test.ts"
|
|
19
|
+
"test": "tsx --test session-auth.test.ts cli-args.test.ts install-files.test.ts removed-skills.test.ts output.test.ts pages.test.ts page-links.test.ts pages-secrets.test.ts pages-comments.test.ts pages-dev.test.ts teams-auth.test.ts teams-watch.test.ts teams-browser.test.ts salesforce.test.ts agents.test.ts agents-approvals.test.ts agents-native-forms.test.ts agents-delivery.test.ts agents-request-upload.test.ts agents-update.test.ts login-callback.test.ts"
|
|
20
20
|
},
|
|
21
21
|
"publishConfig": {
|
|
22
22
|
"access": "public"
|
|
@@ -32,6 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@clack/prompts": "^1.7.0",
|
|
35
|
+
"ajv": "8.17.1",
|
|
36
|
+
"ajv-formats": "3.0.1",
|
|
35
37
|
"chokidar": "4.0.3",
|
|
36
38
|
"cross-spawn": "7.0.6",
|
|
37
39
|
"esbuild": "0.28.2",
|