@subshell-ai/plugin-claude-code 2.0.0 → 3.1.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/dist/index.d.ts +269 -11
- package/dist/index.js +189 -9
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region ../../plugin-api/dist/types-
|
|
1
|
+
//#region ../../plugin-api/dist/types-D6R-hjGN.d.ts
|
|
2
2
|
//#region src/types.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* The contract a Subshell plugin implements.
|
|
@@ -20,13 +20,25 @@
|
|
|
20
20
|
* For humans: it groups and labels in the UI and filters the catalog. Code
|
|
21
21
|
* branches on {@link PluginCapability} instead, so adding a type here touches
|
|
22
22
|
* labels while adding a capability touches the launch pipeline.
|
|
23
|
+
*
|
|
24
|
+
* ONE exception, and it is structural rather than a branch on a label: a
|
|
25
|
+
* `network` plugin implements {@link NetworkPlugin} instead of
|
|
26
|
+
* {@link SubshellPlugin}, so the loader picks WHICH members to require by
|
|
27
|
+
* type. A harness drives a thing in a pane; a network plugin connects this
|
|
28
|
+
* host to one network. They share the store, the manifest and the capability
|
|
29
|
+
* vocabulary, and nothing else.
|
|
23
30
|
*/
|
|
24
|
-
type PluginType = "agent-harness" | "terminal";
|
|
31
|
+
type PluginType = "agent-harness" | "terminal" | "network";
|
|
25
32
|
/**
|
|
26
33
|
* What a plugin can DO. The launch pipeline and the UI read this; neither
|
|
27
34
|
* branches on {@link PluginType}.
|
|
35
|
+
*
|
|
36
|
+
* The union is shared across types and the applicable SUBSET is not, so
|
|
37
|
+
* {@link capabilityMismatches} takes the type: a harness claiming `publish`
|
|
38
|
+
* and a network plugin claiming `resume` are both refused at load, for the
|
|
39
|
+
* same reason a claimed-but-unimplemented capability is.
|
|
28
40
|
*/
|
|
29
|
-
type PluginCapability = "mcp" | "resume" | "attention" | "settings";
|
|
41
|
+
type PluginCapability = "mcp" | "resume" | "attention" | "publish" | "supervise" | "guard" | "settings";
|
|
30
42
|
/** A harness preset as defined by the user (decoded JSON blobs). */
|
|
31
43
|
interface PresetDefinition {
|
|
32
44
|
/** Human-friendly preset name */
|
|
@@ -202,10 +214,23 @@ interface SettingsField {
|
|
|
202
214
|
label: string;
|
|
203
215
|
/** Short description for the editor */
|
|
204
216
|
description?: string;
|
|
205
|
-
/**
|
|
206
|
-
|
|
217
|
+
/**
|
|
218
|
+
* One of: string, boolean, number, select, secret.
|
|
219
|
+
*
|
|
220
|
+
* `secret` is WRITE-ONLY and network-only: the host stores it through
|
|
221
|
+
* {@link PluginHost.secrets} rather than in the settings object, reads
|
|
222
|
+
* report only whether one is set, and a plugin never receives the value —
|
|
223
|
+
* it names the secret and the host hydrates it into a process it spawns
|
|
224
|
+
* ({@link SupervisedProcessSpec}). The preset editor does not render this
|
|
225
|
+
* type; a harness declaring one is a bug rather than a second secret store.
|
|
226
|
+
*/
|
|
227
|
+
type: "string" | "boolean" | "number" | "select" | "secret";
|
|
207
228
|
/** Choices when type === "select" */
|
|
208
229
|
choices?: string[];
|
|
230
|
+
/** True when the field must be set before the plugin can act */
|
|
231
|
+
required?: boolean;
|
|
232
|
+
/** Placeholder / example, shown in the editor. Never a real credential. */
|
|
233
|
+
placeholder?: string;
|
|
209
234
|
/** Default value when unset */
|
|
210
235
|
default?: string | boolean | number;
|
|
211
236
|
}
|
|
@@ -248,6 +273,86 @@ interface PluginHost {
|
|
|
248
273
|
debug(message: string): void;
|
|
249
274
|
warn(message: string): void;
|
|
250
275
|
};
|
|
276
|
+
/**
|
|
277
|
+
* Runs a command to completion under the host's bounds and reports it.
|
|
278
|
+
*
|
|
279
|
+
* The one way a plugin executes anything. A plugin does not spawn: the host
|
|
280
|
+
* owns the deadline, the environment allowlist (the process's own
|
|
281
|
+
* environment holds the auth secret and the database path, and is never
|
|
282
|
+
* handed over), the PATH a service-run server would otherwise lack, and the
|
|
283
|
+
* output cap. Two refusals throw rather than returning a result, because
|
|
284
|
+
* both are bugs in the plugin rather than outcomes: `argv[0]` that is not an
|
|
285
|
+
* ABSOLUTE path (resolve it with {@link findBinary} — a bare name would
|
|
286
|
+
* resolve against a PATH the plugin cannot see), and `argv[0]` that is
|
|
287
|
+
* `sudo`. The server has no terminal to answer a password prompt, so a
|
|
288
|
+
* privileged command is a copy-paste instruction for the operator and never
|
|
289
|
+
* something this runs.
|
|
290
|
+
*
|
|
291
|
+
* Long-running processes are NOT this: a plugin that needs one describes it
|
|
292
|
+
* ({@link SupervisedProcessSpec}) and the host supervises it.
|
|
293
|
+
* @since apiVersion 2
|
|
294
|
+
*/
|
|
295
|
+
run(argv: string[], opts?: RunOptions): Promise<RunResult>;
|
|
296
|
+
/**
|
|
297
|
+
* Write-only credential storage, scoped to this plugin.
|
|
298
|
+
*
|
|
299
|
+
* There is deliberately NO `get`. A plugin that could read a credential
|
|
300
|
+
* could put it in an argv (visible in `ps`), a log line or a hint string;
|
|
301
|
+
* every legitimate consumer is a process the HOST spawns, so the host
|
|
302
|
+
* hydrates the value itself from the name the plugin gives it. Values are
|
|
303
|
+
* stored 0600 under the host's data directory, never in the database and
|
|
304
|
+
* never in a settings row.
|
|
305
|
+
* @since apiVersion 2
|
|
306
|
+
*/
|
|
307
|
+
secrets: PluginSecrets;
|
|
308
|
+
/** The operating system this host runs on. */
|
|
309
|
+
readonly platform: PluginPlatform;
|
|
310
|
+
/** The home directory of the user this host runs as. */
|
|
311
|
+
readonly homeDir: string;
|
|
312
|
+
}
|
|
313
|
+
/** Where a plugin can be driven at all. Mirrors the manifest's `platforms`. */
|
|
314
|
+
type PluginPlatform = "darwin" | "linux";
|
|
315
|
+
/** Options for {@link PluginHost.run}. */
|
|
316
|
+
interface RunOptions {
|
|
317
|
+
/** Deadline in milliseconds. Default 30_000; the host caps it at 10 minutes. */
|
|
318
|
+
timeoutMs?: number;
|
|
319
|
+
/** Called per output line, ANSI already stripped, from both streams interleaved. */
|
|
320
|
+
onLine?: (line: string) => void;
|
|
321
|
+
/**
|
|
322
|
+
* Ends the run early without failing it.
|
|
323
|
+
*
|
|
324
|
+
* What an interactive login needs: `tailscale up` with no key blocks until a
|
|
325
|
+
* human finishes in a browser, having already printed the URL — so the
|
|
326
|
+
* plugin reads the URL off {@link onLine} and aborts, leaving the daemon
|
|
327
|
+
* waiting. An aborted run reports `aborted: true` and whatever was captured.
|
|
328
|
+
*/
|
|
329
|
+
signal?: AbortSignal;
|
|
330
|
+
/** Extra environment on top of the host's allowlist. Never overrides PATH. */
|
|
331
|
+
env?: Record<string, string>;
|
|
332
|
+
/** Text to write to stdin. Absent means stdin is /dev/null, so a prompt cannot hang forever. */
|
|
333
|
+
stdin?: string;
|
|
334
|
+
}
|
|
335
|
+
/** What {@link PluginHost.run} reports. Never throws for a non-zero exit. */
|
|
336
|
+
interface RunResult {
|
|
337
|
+
/** Exit code, or null when the process was signalled or never started. */
|
|
338
|
+
code: number | null;
|
|
339
|
+
/** Captured stdout, ANSI stripped, capped. */
|
|
340
|
+
stdout: string;
|
|
341
|
+
/** Captured stderr, ANSI stripped, capped. */
|
|
342
|
+
stderr: string;
|
|
343
|
+
/** True when the deadline ended it. */
|
|
344
|
+
timedOut: boolean;
|
|
345
|
+
/** True when {@link RunOptions.signal} ended it. */
|
|
346
|
+
aborted: boolean;
|
|
347
|
+
}
|
|
348
|
+
/** Write-only, per-plugin credential storage. See {@link PluginHost.secrets}. */
|
|
349
|
+
interface PluginSecrets {
|
|
350
|
+
/** Stores (or replaces) a credential under this name. */
|
|
351
|
+
set(name: string, value: string): Promise<void>;
|
|
352
|
+
/** Whether a credential is stored under this name. The only read there is. */
|
|
353
|
+
has(name: string): Promise<boolean>;
|
|
354
|
+
/** Removes it. Absent is not an error. */
|
|
355
|
+
delete(name: string): Promise<void>;
|
|
251
356
|
}
|
|
252
357
|
/**
|
|
253
358
|
* The plugin itself.
|
|
@@ -305,8 +410,17 @@ interface SubshellPlugin {
|
|
|
305
410
|
description: string;
|
|
306
411
|
}[];
|
|
307
412
|
}
|
|
308
|
-
/**
|
|
309
|
-
|
|
413
|
+
/**
|
|
414
|
+
* A factory that returns a harness, for a plugin that knows which it is.
|
|
415
|
+
*
|
|
416
|
+
* {@link PluginFactory} is the LOADER's view — it must accept either shape,
|
|
417
|
+
* because it decides which to expect from the manifest. A plugin itself has no
|
|
418
|
+
* such ambiguity, and annotating its own factory with the union would widen
|
|
419
|
+
* what its tests can call: `createPlugin(host).buildCommand(...)` stops
|
|
420
|
+
* type-checking on a value that might be a network plugin. So a plugin
|
|
421
|
+
* declares the half it implements and the loader keeps the union.
|
|
422
|
+
*/
|
|
423
|
+
type HarnessPluginFactory = (host: PluginHost) => SubshellPlugin;
|
|
310
424
|
//#endregion
|
|
311
425
|
//#region ../../plugin-api/dist/index.d.ts
|
|
312
426
|
/** How a host finds this plugin's binary, as data, so a scan loads no plugin code. */
|
|
@@ -315,16 +429,158 @@ interface DetectSpec {
|
|
|
315
429
|
binaryName: string;
|
|
316
430
|
/** Env var that overrides the lookup outright, e.g. "CLAUDE_PATH" */
|
|
317
431
|
envOverride: string;
|
|
318
|
-
/**
|
|
432
|
+
/**
|
|
433
|
+
* Well-known locations, tried after PATH and before the version managers.
|
|
434
|
+
*
|
|
435
|
+
* HOME-relative (`.local/bin/mytool`), or ABSOLUTE when the entry starts
|
|
436
|
+
* with `/` — which is how a vendor's GUI install is named, since
|
|
437
|
+
* `/Applications/Tailscale.app/Contents/MacOS/Tailscale` is nobody's HOME.
|
|
438
|
+
* Each is a candidate to search, so an entry that does not resolve costs
|
|
439
|
+
* nothing and the ladder carries on.
|
|
440
|
+
*/
|
|
319
441
|
knownPaths: string[];
|
|
320
442
|
}
|
|
321
443
|
/** Where to send someone whose binary is missing. */
|
|
322
444
|
interface InstallSpec {
|
|
323
|
-
/**
|
|
445
|
+
/**
|
|
446
|
+
* Copy-pasteable install command for the official installer.
|
|
447
|
+
*
|
|
448
|
+
* A command the HOST may run on request, which is why it may not be
|
|
449
|
+
* privileged: `sudo`, `doas` and `pkexec` are refused by the parser at any
|
|
450
|
+
* command boundary (the line is run through a shell — see
|
|
451
|
+
* {@link needsPrivileges}), so an installer that needs root is described
|
|
452
|
+
* under {@link NetworkManifest.privileged} instead and is only ever shown to
|
|
453
|
+
* copy. Without that refusal the two would be one field with two meanings,
|
|
454
|
+
* and the surface offering a button would have to guess.
|
|
455
|
+
*/
|
|
324
456
|
command: string;
|
|
325
|
-
/**
|
|
457
|
+
/**
|
|
458
|
+
* URL of the installation documentation.
|
|
459
|
+
*
|
|
460
|
+
* Rendered as a link on an admin page, so it must be `http:` or `https:`
|
|
461
|
+
* and the parser refuses anything else — see {@link isDocsUrl}.
|
|
462
|
+
*/
|
|
326
463
|
docsUrl: string;
|
|
327
464
|
}
|
|
465
|
+
/** One step an operator must run themselves, because the host may not. */
|
|
466
|
+
interface PrivilegedStep {
|
|
467
|
+
/** What it does, in a few words: "Install the daemon" */
|
|
468
|
+
label: string;
|
|
469
|
+
/** The command to copy. Usually `sudo …`. */
|
|
470
|
+
command: string;
|
|
471
|
+
/** Where the vendor documents it; `http:`/`https:` only, as {@link isDocsUrl} requires. */
|
|
472
|
+
docsUrl?: string;
|
|
473
|
+
/**
|
|
474
|
+
* Which ALTERNATIVE this step belongs to, and the heading it renders under.
|
|
475
|
+
*
|
|
476
|
+
* Steps sharing a group are one sequence to run in order; different groups
|
|
477
|
+
* are different ways to arrive at the same place, and a surface renders an
|
|
478
|
+
* `or` between them rather than continuing the numbering. Steps with no
|
|
479
|
+
* group are one plain sequence, which is what every step was before this
|
|
480
|
+
* existed.
|
|
481
|
+
*
|
|
482
|
+
* It exists because a platform can genuinely offer two routes: on macOS
|
|
483
|
+
* Tailscale ships both a GUI app and a command-line daemon, and a page that
|
|
484
|
+
* numbered those 1..3 told a person to install both. Non-empty when present
|
|
485
|
+
* — it is a heading, so `""` is refused rather than coerced.
|
|
486
|
+
*/
|
|
487
|
+
group?: string;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* The `subshell.network` block. Required when `type` is `network`.
|
|
491
|
+
*
|
|
492
|
+
* Everything here is DATA a host reads without loading plugin code: which
|
|
493
|
+
* machines this plugin can run on at all, whether it can produce a login URL,
|
|
494
|
+
* what publishing it exposes, and which steps only a human with root can
|
|
495
|
+
* perform. A page can therefore say "not available on this platform" or print
|
|
496
|
+
* the two sudo commands before any plugin code has been imported — and before
|
|
497
|
+
* the vendor's CLI is anywhere on the machine.
|
|
498
|
+
*/
|
|
499
|
+
interface NetworkManifest {
|
|
500
|
+
/**
|
|
501
|
+
* Operating systems this plugin can be driven on.
|
|
502
|
+
*
|
|
503
|
+
* Not a hint: a host refuses every act on a platform absent from this list,
|
|
504
|
+
* and the UI renders the row as unavailable rather than offering a button
|
|
505
|
+
* that would 409. Vendors differ here for real reasons — a CLI that talks to
|
|
506
|
+
* a logged-in desktop session cannot be driven from a launchd service.
|
|
507
|
+
*/
|
|
508
|
+
platforms: PluginPlatform[];
|
|
509
|
+
/**
|
|
510
|
+
* True when `join({})` with no credential can yield a URL a human finishes.
|
|
511
|
+
*
|
|
512
|
+
* Data rather than a capability because it describes what a RETURN VALUE may
|
|
513
|
+
* be, and a capability is checked against members. The UI reads it to decide
|
|
514
|
+
* whether to offer "sign in" beside "paste a key".
|
|
515
|
+
*/
|
|
516
|
+
interactiveLogin?: boolean;
|
|
517
|
+
/**
|
|
518
|
+
* True when publishing leaves NOTHING the daemon can later be asked about.
|
|
519
|
+
*
|
|
520
|
+
* NetBird is the case that forced the field: a join is the whole publish,
|
|
521
|
+
* so `status()` can only ever see the join, and a plugin that declared
|
|
522
|
+
* itself `published` would claim a thing its own vendor CLI never told it.
|
|
523
|
+
* The HOST's publish record is the one witness of the transition, and this
|
|
524
|
+
* flag is what lets the host (and only the host) upgrade `joined` to
|
|
525
|
+
* `published` from it. A plugin without the flag is never upgraded: for
|
|
526
|
+
* Tailscale a serve reset outside this app is a real state, and `joined`
|
|
527
|
+
* is the honest reading of it.
|
|
528
|
+
*/
|
|
529
|
+
publishImplicit?: boolean;
|
|
530
|
+
/**
|
|
531
|
+
* What publishing on this network exposes the server to.
|
|
532
|
+
*
|
|
533
|
+
* `private` is a network only invited machines are on. `public-with-gate`
|
|
534
|
+
* reaches the open internet with an identity check in front — a different
|
|
535
|
+
* security posture, stated here so every surface can say so before the act
|
|
536
|
+
* rather than after it.
|
|
537
|
+
*/
|
|
538
|
+
exposure: "private" | "public-with-gate";
|
|
539
|
+
/**
|
|
540
|
+
* Steps the host can never perform, per platform, in the order to run them.
|
|
541
|
+
*
|
|
542
|
+
* Every mesh VPN installs a daemon as root and the server has no terminal to
|
|
543
|
+
* answer a password prompt, so these are printed to copy and never executed.
|
|
544
|
+
* Keeping them out of {@link InstallSpec} is what lets a surface offer a
|
|
545
|
+
* button for one and a copy row for the other without inspecting the string.
|
|
546
|
+
*/
|
|
547
|
+
privileged?: Partial<Record<PluginPlatform, PrivilegedStep[]>>;
|
|
548
|
+
/**
|
|
549
|
+
* What this network calls the two things a person acts on.
|
|
550
|
+
*
|
|
551
|
+
* Vendors name the same act differently and a generic word is wrong rather
|
|
552
|
+
* than merely bland: Tailscale takes an "auth key", NetBird a "setup key",
|
|
553
|
+
* Cloudflare a "tunnel token", and a field labelled "Auth key" on the
|
|
554
|
+
* NetBird row asks for something NetBird does not have. Likewise publishing
|
|
555
|
+
* is "Tailscale Serve" on one network and starting a tunnel on another.
|
|
556
|
+
*
|
|
557
|
+
* MANIFEST data rather than something the plugin returns, for the same
|
|
558
|
+
* reason `platforms` is: a surface renders these before any plugin code has
|
|
559
|
+
* been loaded, and before the vendor's CLI is anywhere on the machine. Both
|
|
560
|
+
* are optional and both have a sensible generic default, so a plugin that
|
|
561
|
+
* says nothing is merely plain rather than broken.
|
|
562
|
+
*/
|
|
563
|
+
labels?: NetworkLabels;
|
|
564
|
+
}
|
|
565
|
+
/** The vendor's own words for the two acts a person takes. See {@link NetworkManifest.labels}. */
|
|
566
|
+
interface NetworkLabels {
|
|
567
|
+
/** What to call the pasted credential: "Auth key", "Setup key", "Tunnel token". */
|
|
568
|
+
credential?: string;
|
|
569
|
+
/** What to call publishing: "Publish with Tailscale Serve", "Start tunnel". */
|
|
570
|
+
publish?: string;
|
|
571
|
+
/**
|
|
572
|
+
* Where the credential named by `credential` comes from — the vendor page
|
|
573
|
+
* that mints one.
|
|
574
|
+
*
|
|
575
|
+
* The credential box asks for an "Auth key" on a card that otherwise says
|
|
576
|
+
* nothing about what an auth key is or where to get it, and every vendor
|
|
577
|
+
* words that differently enough that the SPA cannot write the sentence
|
|
578
|
+
* itself. So the plugin names its page, and the card renders it as a Docs
|
|
579
|
+
* link on the label row. http(s) only, refused at parse like every other
|
|
580
|
+
* URL this contract carries — it lands in an `href` on an admin page.
|
|
581
|
+
*/
|
|
582
|
+
credentialDocsUrl?: string;
|
|
583
|
+
}
|
|
328
584
|
/** The parsed `subshell` block. */
|
|
329
585
|
interface SubshellManifest {
|
|
330
586
|
/** plugin-api version this plugin was built against */
|
|
@@ -359,6 +615,8 @@ interface SubshellManifest {
|
|
|
359
615
|
* fallback, i.e. a resume that quietly never offers itself (§11).
|
|
360
616
|
*/
|
|
361
617
|
hostEnv?: string[];
|
|
618
|
+
/** Network facts. Present exactly when `type` is `network`. */
|
|
619
|
+
network?: NetworkManifest;
|
|
362
620
|
}
|
|
363
621
|
//#endregion
|
|
364
622
|
//#region src/manifest.d.ts
|
|
@@ -382,6 +640,6 @@ declare const manifest: SubshellManifest;
|
|
|
382
640
|
* version probe, shell quoting, a namespaced logger). See
|
|
383
641
|
* `@subshell-ai/plugin-api`.
|
|
384
642
|
*/
|
|
385
|
-
declare const createPlugin:
|
|
643
|
+
declare const createPlugin: HarnessPluginFactory;
|
|
386
644
|
//#endregion
|
|
387
645
|
export { createPlugin as default, manifest };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { join, resolve } from "node:path";
|
|
2
|
-
//#region ../../plugin-api/dist/manifest-
|
|
2
|
+
//#region ../../plugin-api/dist/manifest-DKMceUPh.js
|
|
3
3
|
/** Every {@link PluginType}, for anything that has to iterate or validate them. */
|
|
4
|
-
const PLUGIN_TYPES = [
|
|
4
|
+
const PLUGIN_TYPES = [
|
|
5
|
+
"agent-harness",
|
|
6
|
+
"terminal",
|
|
7
|
+
"network"
|
|
8
|
+
];
|
|
9
|
+
/** Every {@link PluginPlatform}, for validation. */
|
|
10
|
+
const PLUGIN_PLATFORMS = ["darwin", "linux"];
|
|
5
11
|
/**
|
|
6
12
|
* The MCP server name every harness registers the built-in `subshell mcp`
|
|
7
13
|
* server under: the config object key, and the `hermes mcp add|remove`
|
|
@@ -29,6 +35,80 @@ const ID_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
|
|
|
29
35
|
function isRecord(value) {
|
|
30
36
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
31
37
|
}
|
|
38
|
+
/** The privilege wrappers no install command may ever run, by first-word basename. */
|
|
39
|
+
const PRIVILEGED_COMMANDS = [
|
|
40
|
+
"sudo",
|
|
41
|
+
"doas",
|
|
42
|
+
"pkexec"
|
|
43
|
+
];
|
|
44
|
+
/** Shell boundaries that introduce a NEW command word: `;` `|` `&` (so `&&` and `||` too) and newline. */
|
|
45
|
+
const COMMAND_BOUNDARY_RE = /[;&|\n]+/;
|
|
46
|
+
/** A leading `NAME=…` env assignment, which `sh` strips before choosing the command. */
|
|
47
|
+
const ENV_ASSIGNMENT_RE = /^[A-Za-z_][A-Za-z0-9_]*=\S*\s*/;
|
|
48
|
+
/**
|
|
49
|
+
* Whether a shell line runs one of {@link PRIVILEGED_COMMANDS} AS A COMMAND
|
|
50
|
+
* anywhere in it — not merely at the start.
|
|
51
|
+
*
|
|
52
|
+
* `install.command` is the one manifest field a host RUNS, and it runs through
|
|
53
|
+
* `sh -c` (`api/network/install-network.route.ts`), which means any boundary
|
|
54
|
+
* in the line can start the privileged command the start of the line hides:
|
|
55
|
+
* `"apt-get update && sudo apt-get install -y x"` is sudo-without-prompt on a
|
|
56
|
+
* NOPASSWD host. A line-start regex was the first gate and it was not one.
|
|
57
|
+
*
|
|
58
|
+
* The split is CONSERVATIVE, not a shell parser: segments are taken at every
|
|
59
|
+
* boundary character quote-blind (so a `;` inside a quoted string still
|
|
60
|
+
* counts, which can only over-refuse), leading env assignments are stripped
|
|
61
|
+
* (`FOO=bar sudo x` runs sudo), and each segment's first word is compared by
|
|
62
|
+
* BASENAME (`/usr/bin/sudo` is sudo, `pkexec-demo` is not). A word merely
|
|
63
|
+
* CONTAINING the token is fine — the comparison is equality on the basename.
|
|
64
|
+
* The accepted limit is a wrapper hidden inside quotes (`sh -c 'sudo …'`),
|
|
65
|
+
* which is the same limit `PluginHost.run`'s first-word check has, and it is
|
|
66
|
+
* accepted for the same reason: a plugin whose code LOADS can already run
|
|
67
|
+
* anything in this process (`docs/security.md` §11.9) — this rule refuses
|
|
68
|
+
* careless manifests deterministically, it is not a sandbox.
|
|
69
|
+
*/
|
|
70
|
+
function needsPrivileges(command) {
|
|
71
|
+
for (const segment of command.split(COMMAND_BOUNDARY_RE)) {
|
|
72
|
+
let rest = segment.trim();
|
|
73
|
+
while (ENV_ASSIGNMENT_RE.test(rest)) rest = rest.replace(ENV_ASSIGNMENT_RE, "");
|
|
74
|
+
if (rest === "") continue;
|
|
75
|
+
const ws = rest.search(/\s/);
|
|
76
|
+
const firstWord = ws === -1 ? rest : rest.slice(0, ws);
|
|
77
|
+
const base = firstWord.slice(firstWord.lastIndexOf("/") + 1);
|
|
78
|
+
if (PRIVILEGED_COMMANDS.includes(base)) return true;
|
|
79
|
+
}
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Whether a string may be rendered as a link in an operator's browser.
|
|
84
|
+
*
|
|
85
|
+
* Every `docsUrl` in this contract ends up as the `href` of an anchor on an
|
|
86
|
+
* admin page, and an `href` is not inert: a `javascript:` URL in one is script
|
|
87
|
+
* running on the control plane's own origin, in the session of the one person
|
|
88
|
+
* who can install plugins. So a URL this contract carries is restricted to the
|
|
89
|
+
* two schemes that navigate, and both the parser below and the host check it.
|
|
90
|
+
*
|
|
91
|
+
* It is checked in two places on purpose. A manifest is static data, so a bad
|
|
92
|
+
* value there is a plugin defect and is refused at load. A URL a plugin
|
|
93
|
+
* REPORTS at runtime is often something it read off a vendor CLI — Tailscale's
|
|
94
|
+
* `AuthURL` comes from whichever control server the operator pointed the
|
|
95
|
+
* daemon at — so the host drops that one instead, because refusing to load a
|
|
96
|
+
* working plugin over a value its control server chose would be the wrong
|
|
97
|
+
* failure.
|
|
98
|
+
*
|
|
99
|
+
* Not a reachability claim: nothing fetches these, and a docs page that 404s
|
|
100
|
+
* is a broken link rather than a hazard.
|
|
101
|
+
* @param value - the candidate URL, as written in a manifest or returned by a plugin
|
|
102
|
+
*/
|
|
103
|
+
function isDocsUrl(value) {
|
|
104
|
+
let parsed;
|
|
105
|
+
try {
|
|
106
|
+
parsed = new URL(value);
|
|
107
|
+
} catch {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return parsed.protocol === "http:" || parsed.protocol === "https:";
|
|
111
|
+
}
|
|
32
112
|
/**
|
|
33
113
|
* Reads and validates the `subshell` block of a plugin's package.json.
|
|
34
114
|
*
|
|
@@ -44,7 +124,7 @@ function parseManifest(pkgJson) {
|
|
|
44
124
|
if (!isRecord(block)) return { error: "package.json has no `subshell` block, so it is not a Subshell plugin" };
|
|
45
125
|
if (typeof block.apiVersion !== "number" || !Number.isInteger(block.apiVersion)) return { error: "`subshell.apiVersion` must be an integer" };
|
|
46
126
|
if (block.apiVersion < 1) return { error: `this plugin declares plugin-api ${block.apiVersion}, which is not a version; the lowest is 1 and this host implements 2` };
|
|
47
|
-
if (block.apiVersion > 2) return { error: `this plugin needs plugin-api ${block.apiVersion}, but this host implements 2; upgrade
|
|
127
|
+
if (block.apiVersion > 2) return { error: `this plugin needs plugin-api ${block.apiVersion}, but this host implements 2; upgrade Subshell` };
|
|
48
128
|
if (typeof block.id !== "string" || !ID_RE.test(block.id)) return { error: "`subshell.id` must be lowercase letters, digits and hyphens, starting alphanumeric (it becomes a directory name)" };
|
|
49
129
|
if (typeof block.type !== "string" || !PLUGIN_TYPES.includes(block.type)) return { error: `\`subshell.type\` must be one of: ${PLUGIN_TYPES.join(", ")}` };
|
|
50
130
|
if (typeof block.name !== "string" || block.name.trim() === "") return { error: "`subshell.name` must be a non-empty string" };
|
|
@@ -71,6 +151,8 @@ function parseManifest(pkgJson) {
|
|
|
71
151
|
if (block.install !== void 0) {
|
|
72
152
|
const i = block.install;
|
|
73
153
|
if (!isRecord(i) || typeof i.command !== "string" || typeof i.docsUrl !== "string") return { error: "`subshell.install` needs a command and a docsUrl" };
|
|
154
|
+
if (needsPrivileges(i.command)) return { error: "`subshell.install.command` must not need sudo, doas or pkexec — the host runs it through a shell and has no terminal for a password prompt; put privileged steps in `subshell.network.privileged`" };
|
|
155
|
+
if (!isDocsUrl(i.docsUrl)) return { error: "`subshell.install.docsUrl` must be an http(s) URL — it is rendered as a link on an admin page" };
|
|
74
156
|
install = {
|
|
75
157
|
command: i.command,
|
|
76
158
|
docsUrl: i.docsUrl
|
|
@@ -81,17 +163,84 @@ function parseManifest(pkgJson) {
|
|
|
81
163
|
if (!Array.isArray(block.hostEnv) || !block.hostEnv.every((k) => typeof k === "string" && k.trim() !== "")) return { error: "`subshell.hostEnv` must be an array of environment variable names" };
|
|
82
164
|
hostEnv = [...block.hostEnv];
|
|
83
165
|
}
|
|
166
|
+
const type = block.type;
|
|
167
|
+
const parsedNetwork = parseNetworkBlock(block.network, type);
|
|
168
|
+
if (parsedNetwork !== void 0 && "error" in parsedNetwork) return parsedNetwork;
|
|
84
169
|
return {
|
|
85
170
|
apiVersion: block.apiVersion,
|
|
86
171
|
id: block.id,
|
|
87
|
-
type
|
|
172
|
+
type,
|
|
88
173
|
name: block.name,
|
|
89
174
|
description: block.description,
|
|
90
175
|
...typeof block.icon === "string" ? { icon: block.icon } : {},
|
|
91
176
|
entry: block.entry,
|
|
92
177
|
...detect ? { detect } : {},
|
|
93
178
|
...install ? { install } : {},
|
|
94
|
-
...hostEnv ? { hostEnv } : {}
|
|
179
|
+
...hostEnv ? { hostEnv } : {},
|
|
180
|
+
...parsedNetwork ? { network: parsedNetwork } : {}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Parses `subshell.network`, which is required for and exclusive to `network`.
|
|
185
|
+
*
|
|
186
|
+
* Both directions are refused rather than tolerated. A network plugin without
|
|
187
|
+
* the block would be unrenderable — nothing could say which platforms it runs
|
|
188
|
+
* on or what publishing it exposes, and the safe default for "what does this
|
|
189
|
+
* expose" is not a default anyone should pick silently. A harness WITH one
|
|
190
|
+
* declares facts nothing reads, which is how a manifest starts lying.
|
|
191
|
+
* @returns the parsed block, an error, or undefined when there is none to have
|
|
192
|
+
*/
|
|
193
|
+
function parseNetworkBlock(raw, type) {
|
|
194
|
+
if (type !== "network") {
|
|
195
|
+
if (raw !== void 0) return { error: `\`subshell.network\` is only for \`type: "network"\` plugins, and this one is \`${type}\`` };
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (!isRecord(raw)) return { error: "`subshell.network` is required for `type: \"network\"` plugins" };
|
|
199
|
+
if (!Array.isArray(raw.platforms) || raw.platforms.length === 0 || !raw.platforms.every((p) => typeof p === "string" && PLUGIN_PLATFORMS.includes(p))) return { error: `\`subshell.network.platforms\` must be a non-empty array of: ${PLUGIN_PLATFORMS.join(", ")}` };
|
|
200
|
+
if (raw.exposure !== "private" && raw.exposure !== "public-with-gate") return { error: "`subshell.network.exposure` must be \"private\" or \"public-with-gate\"" };
|
|
201
|
+
if (raw.interactiveLogin !== void 0 && typeof raw.interactiveLogin !== "boolean") return { error: "`subshell.network.interactiveLogin` must be a boolean" };
|
|
202
|
+
if (raw.publishImplicit !== void 0 && typeof raw.publishImplicit !== "boolean") return { error: "`subshell.network.publishImplicit` must be a boolean" };
|
|
203
|
+
let privileged;
|
|
204
|
+
if (raw.privileged !== void 0) {
|
|
205
|
+
if (!isRecord(raw.privileged)) return { error: "`subshell.network.privileged` must be an object keyed by platform" };
|
|
206
|
+
privileged = {};
|
|
207
|
+
for (const [platform, steps] of Object.entries(raw.privileged)) {
|
|
208
|
+
if (!PLUGIN_PLATFORMS.includes(platform)) return { error: `\`subshell.network.privileged\` has an unknown platform "${platform}"` };
|
|
209
|
+
if (!Array.isArray(steps) || !steps.every((s) => isRecord(s) && typeof s.label === "string" && s.label.trim() !== "" && typeof s.command === "string" && s.command.trim() !== "" && (s.docsUrl === void 0 || typeof s.docsUrl === "string") && (s.group === void 0 || typeof s.group === "string"))) return { error: `\`subshell.network.privileged.${platform}\` must be an array of { label, command, docsUrl?, group? }` };
|
|
210
|
+
const badGroup = steps.find((s) => s.group !== void 0 && s.group.trim() === "");
|
|
211
|
+
if (badGroup) return { error: `\`subshell.network.privileged.${platform}\` has an empty \`group\`, which is a heading with no words: "${badGroup.label}"` };
|
|
212
|
+
const badDocs = steps.find((s) => s.docsUrl !== void 0 && !isDocsUrl(s.docsUrl));
|
|
213
|
+
if (badDocs) return { error: `\`subshell.network.privileged.${platform}\` has a docsUrl that is not an http(s) URL: "${badDocs.label}"` };
|
|
214
|
+
privileged[platform] = steps.map((s) => ({
|
|
215
|
+
label: s.label,
|
|
216
|
+
command: s.command,
|
|
217
|
+
...s.docsUrl ? { docsUrl: s.docsUrl } : {},
|
|
218
|
+
...s.group ? { group: s.group } : {}
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
let labels;
|
|
223
|
+
if (raw.labels !== void 0) {
|
|
224
|
+
if (!isRecord(raw.labels)) return { error: "`subshell.network.labels` must be an object" };
|
|
225
|
+
for (const key of ["credential", "publish"]) {
|
|
226
|
+
const value = raw.labels[key];
|
|
227
|
+
if (value !== void 0 && (typeof value !== "string" || value.trim() === "")) return { error: `\`subshell.network.labels.${key}\` must be a non-empty string` };
|
|
228
|
+
}
|
|
229
|
+
const credDocs = raw.labels.credentialDocsUrl;
|
|
230
|
+
if (credDocs !== void 0 && (typeof credDocs !== "string" || !isDocsUrl(credDocs))) return { error: "`subshell.network.labels.credentialDocsUrl` must be an http(s) URL — it is rendered as a link on an admin page" };
|
|
231
|
+
labels = {
|
|
232
|
+
...typeof raw.labels.credential === "string" ? { credential: raw.labels.credential } : {},
|
|
233
|
+
...typeof raw.labels.publish === "string" ? { publish: raw.labels.publish } : {},
|
|
234
|
+
...typeof raw.labels.credentialDocsUrl === "string" ? { credentialDocsUrl: raw.labels.credentialDocsUrl } : {}
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
return {
|
|
238
|
+
platforms: [...raw.platforms],
|
|
239
|
+
exposure: raw.exposure,
|
|
240
|
+
...raw.interactiveLogin === true ? { interactiveLogin: true } : {},
|
|
241
|
+
...raw.publishImplicit === true ? { publishImplicit: true } : {},
|
|
242
|
+
...privileged ? { privileged } : {},
|
|
243
|
+
...labels && Object.keys(labels).length > 0 ? { labels } : {}
|
|
95
244
|
};
|
|
96
245
|
}
|
|
97
246
|
//#endregion
|
|
@@ -135,7 +284,7 @@ function validateGenericPreset(preset) {
|
|
|
135
284
|
const parsed = parseManifest({
|
|
136
285
|
name: "@subshell-ai/plugin-claude-code",
|
|
137
286
|
description: "Claude Code harness plugin for Subshell",
|
|
138
|
-
version: "
|
|
287
|
+
version: "3.1.0",
|
|
139
288
|
license: "Apache-2.0",
|
|
140
289
|
type: "module",
|
|
141
290
|
main: "dist/index.js",
|
|
@@ -284,6 +433,10 @@ const SUGGESTED_ENV = [
|
|
|
284
433
|
key: "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC",
|
|
285
434
|
description: "Disable telemetry/update traffic (1)"
|
|
286
435
|
},
|
|
436
|
+
{
|
|
437
|
+
key: "CLAUDE_CODE_DISABLE_ALTERNATE_SCREEN",
|
|
438
|
+
description: "Classic renderer: appends to scrollback so the pane shows a scrollbar (1)"
|
|
439
|
+
},
|
|
287
440
|
{
|
|
288
441
|
key: "CLAUDE_CODE_SSE_URL",
|
|
289
442
|
description: "Anthropic SSE URL override (e.g. http://localhost:8080/anthropic)"
|
|
@@ -395,13 +548,29 @@ const reporterHook = (host, reporter, ...verb) => [
|
|
|
395
548
|
* - `Stop` / `Notification` — fire-and-forget attention reporting. The server
|
|
396
549
|
* gates delivery on the subshell's bell and derives the "waiting for you"
|
|
397
550
|
* state; a missed event costs one notification, never a broken turn.
|
|
551
|
+
* `Notification` carries a matcher because the unfiltered hook rang
|
|
552
|
+
* "Needs your approval" for EVERY notification type — `idle_prompt`,
|
|
553
|
+
* `auth_success`, `elicitation_complete` after the human had already
|
|
554
|
+
* answered (spec 2026-09-23). `Stop` reports `turn_complete` blind here:
|
|
555
|
+
* the reporter reads the hook payload and stays silent for a session
|
|
556
|
+
* parked on background work (`packages/mcp-core/src/report.ts`).
|
|
557
|
+
* - `UserPromptSubmit` / `PreToolUse` — the waiting CLEAR (`resumed`). The
|
|
558
|
+
* plane's idle-watcher can only clear what it can stat, so an agent-node
|
|
559
|
+
* pane — log on the node's disk — stayed "waiting for you" for its whole
|
|
560
|
+
* next turn (2026-09-24). The pane knows better: work has resumed when the
|
|
561
|
+
* human's prompt is submitted, AND when a tool starts after an approval
|
|
562
|
+
* answered in the dialog (approving is not a prompt, so
|
|
563
|
+
* UserPromptSubmit alone misses that path). PreToolUse fires on every tool
|
|
564
|
+
* call; the endpoint's clear is conditional, so the common stamp-less case
|
|
565
|
+
* is a silent no-op. Neither hook's stdin is read — their payloads are the
|
|
566
|
+
* prompt text and the tool input, and the report is only ever the fact.
|
|
398
567
|
* - `SessionStart` — conversation identity. The restart-resume pin
|
|
399
568
|
* (`--session-id` at launch) only survives while the pane keeps that ONE
|
|
400
569
|
* conversation, but /clear, /resume <other> and /fork start a DIFFERENT
|
|
401
570
|
* transcript id in-pane and nothing else tells the server, so the next
|
|
402
571
|
* restart would resurrect a stale conversation (observed 2026-09-03). This
|
|
403
572
|
* fires on every such transition (source: startup|resume|clear|compact|fork)
|
|
404
|
-
* and
|
|
573
|
+
* and reads stdin like `Stop` now does — the reporter forwards `session_id`
|
|
405
574
|
* from that payload and nothing else.
|
|
406
575
|
*/
|
|
407
576
|
const attentionHooks = (host, reporter) => ({
|
|
@@ -409,9 +578,20 @@ const attentionHooks = (host, reporter) => ({
|
|
|
409
578
|
type: "command",
|
|
410
579
|
command: reporterHook(host, reporter, "attention", "turn_complete")
|
|
411
580
|
}] }],
|
|
412
|
-
Notification: [{
|
|
581
|
+
Notification: [{
|
|
582
|
+
matcher: "permission_prompt|agent_needs_input|elicitation_dialog|elicitation_url_dialog",
|
|
583
|
+
hooks: [{
|
|
584
|
+
type: "command",
|
|
585
|
+
command: reporterHook(host, reporter, "attention", "needs_attention")
|
|
586
|
+
}]
|
|
587
|
+
}],
|
|
588
|
+
UserPromptSubmit: [{ hooks: [{
|
|
589
|
+
type: "command",
|
|
590
|
+
command: reporterHook(host, reporter, "attention", "resumed")
|
|
591
|
+
}] }],
|
|
592
|
+
PreToolUse: [{ hooks: [{
|
|
413
593
|
type: "command",
|
|
414
|
-
command: reporterHook(host, reporter, "attention", "
|
|
594
|
+
command: reporterHook(host, reporter, "attention", "resumed")
|
|
415
595
|
}] }],
|
|
416
596
|
SessionStart: [{ hooks: [{
|
|
417
597
|
type: "command",
|