agents-inc 0.176.0 → 0.177.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 +65 -0
- package/README.md +2 -2
- package/dist/{chunk-FACDJH6O.js → chunk-2FE4AJNC.js} +20 -26
- package/dist/chunk-2FE4AJNC.js.map +1 -0
- package/dist/{chunk-U46LYYRA.js → chunk-4SIBDIIO.js} +49 -13
- package/dist/chunk-4SIBDIIO.js.map +1 -0
- package/dist/chunk-5ZK4IND4.js +30 -0
- package/dist/chunk-5ZK4IND4.js.map +1 -0
- package/dist/{chunk-MQZNDK5F.js → chunk-77SHXTDD.js} +137 -56
- package/dist/chunk-77SHXTDD.js.map +1 -0
- package/dist/{chunk-U672FZVC.js → chunk-7OJ2SS4E.js} +10 -86
- package/dist/chunk-7OJ2SS4E.js.map +1 -0
- package/dist/{chunk-C2BSCEDN.js → chunk-7WN6TUZP.js} +7 -8
- package/dist/chunk-7WN6TUZP.js.map +1 -0
- package/dist/chunk-AVKX3IXF.js +117 -0
- package/dist/chunk-AVKX3IXF.js.map +1 -0
- package/dist/{chunk-ENET4IF6.js → chunk-D2PC7NIR.js} +1653 -1734
- package/dist/chunk-D2PC7NIR.js.map +1 -0
- package/dist/{chunk-JTMSFBCA.js → chunk-E6W3PYGF.js} +823 -72
- package/dist/chunk-E6W3PYGF.js.map +1 -0
- package/dist/chunk-H33ZAEKH.js +147 -0
- package/dist/chunk-H33ZAEKH.js.map +1 -0
- package/dist/{chunk-B7AVWSK2.js → chunk-JEFVFZAR.js} +39 -151
- package/dist/chunk-JEFVFZAR.js.map +1 -0
- package/dist/{chunk-UE4Z3YMB.js → chunk-KKGJH46C.js} +3 -21
- package/dist/chunk-KKGJH46C.js.map +1 -0
- package/dist/chunk-OIQKRXHH.js +142 -0
- package/dist/chunk-OIQKRXHH.js.map +1 -0
- package/dist/{chunk-CKBWEWHZ.js → chunk-TNN72UL6.js} +264 -247
- package/dist/chunk-TNN72UL6.js.map +1 -0
- package/dist/{chunk-XMQIWPIR.js → chunk-V3WJMNBF.js} +45 -18
- package/dist/chunk-V3WJMNBF.js.map +1 -0
- package/dist/chunk-VFD2XYM7.js +14 -0
- package/dist/chunk-VFD2XYM7.js.map +1 -0
- package/dist/{chunk-XYBHH3M5.js → chunk-WH7JXGDA.js} +2 -2
- package/dist/{chunk-JNRACLNS.js → chunk-XSR4WRXJ.js} +3 -3
- package/dist/{chunk-3F5LT433.js → chunk-Y5VMB73R.js} +202 -116
- package/dist/chunk-Y5VMB73R.js.map +1 -0
- package/dist/chunk-ZIBWVTLN.js +18 -0
- package/dist/chunk-ZIBWVTLN.js.map +1 -0
- package/dist/commands/build/marketplace.js +6 -10
- package/dist/commands/build/marketplace.js.map +1 -1
- package/dist/commands/build/plugins.js +10 -39
- package/dist/commands/build/plugins.js.map +1 -1
- package/dist/commands/compile.js +60 -81
- package/dist/commands/compile.js.map +1 -1
- package/dist/commands/doctor.js +234 -145
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/edit.js +64 -159
- package/dist/commands/edit.js.map +1 -1
- package/dist/commands/eject.js +64 -54
- package/dist/commands/eject.js.map +1 -1
- package/dist/commands/init.js +19 -17
- package/dist/commands/list.js +10 -12
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/new/marketplace.js +5 -5
- package/dist/commands/search.js +14 -13
- package/dist/commands/search.js.map +1 -1
- package/dist/commands/share.js +21 -44
- package/dist/commands/share.js.map +1 -1
- package/dist/commands/uninstall.js +139 -56
- package/dist/commands/uninstall.js.map +1 -1
- package/dist/commands/update.js +22 -37
- package/dist/commands/update.js.map +1 -1
- package/dist/components/common/header-row.js +9 -0
- package/dist/components/common/select-list.js +2 -2
- package/dist/components/common/skill-agent-summary.js +4 -4
- package/dist/components/common/summary-panel.js +6 -5
- package/dist/hooks/init.js +35 -22
- package/dist/hooks/init.js.map +1 -1
- package/dist/load-agent-defs-OCFWOZD2.js +14 -0
- package/dist/{recompile-project-agents-U3UGHPWG.js → recompile-project-agents-CXZBPIUS.js} +9 -9
- package/dist/{recompile-project-agents-U3UGHPWG.js.map → recompile-project-agents-CXZBPIUS.js.map} +1 -1
- package/dist/{source-loader-E2Y5MMN5.js → source-loader-GGDQDMN4.js} +6 -4
- package/dist/source-loader-GGDQDMN4.js.map +1 -0
- package/package.json +1 -1
- package/src/schemas/stacks.schema.json +105 -1
- package/dist/chunk-3F5LT433.js.map +0 -1
- package/dist/chunk-5CFHP6Z5.js +0 -109
- package/dist/chunk-5CFHP6Z5.js.map +0 -1
- package/dist/chunk-B7AVWSK2.js.map +0 -1
- package/dist/chunk-C2BSCEDN.js.map +0 -1
- package/dist/chunk-CKBWEWHZ.js.map +0 -1
- package/dist/chunk-EC3JXT23.js +0 -160
- package/dist/chunk-EC3JXT23.js.map +0 -1
- package/dist/chunk-ENET4IF6.js.map +0 -1
- package/dist/chunk-FACDJH6O.js.map +0 -1
- package/dist/chunk-H6WUOW5F.js +0 -35
- package/dist/chunk-H6WUOW5F.js.map +0 -1
- package/dist/chunk-JTMSFBCA.js.map +0 -1
- package/dist/chunk-MQZNDK5F.js.map +0 -1
- package/dist/chunk-SN64WNWE.js +0 -428
- package/dist/chunk-SN64WNWE.js.map +0 -1
- package/dist/chunk-U46LYYRA.js.map +0 -1
- package/dist/chunk-U672FZVC.js.map +0 -1
- package/dist/chunk-UE4Z3YMB.js.map +0 -1
- package/dist/chunk-XMQIWPIR.js.map +0 -1
- package/dist/chunk-ZBI6GFJD.js +0 -39
- package/dist/chunk-ZBI6GFJD.js.map +0 -1
- package/dist/load-agent-defs-5BSECHE6.js +0 -14
- /package/dist/{chunk-XYBHH3M5.js.map → chunk-WH7JXGDA.js.map} +0 -0
- /package/dist/{chunk-JNRACLNS.js.map → chunk-XSR4WRXJ.js.map} +0 -0
- /package/dist/{load-agent-defs-5BSECHE6.js.map → components/common/header-row.js.map} +0 -0
- /package/dist/{source-loader-E2Y5MMN5.js.map → load-agent-defs-OCFWOZD2.js.map} +0 -0
package/dist/commands/share.js
CHANGED
|
@@ -1,39 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
-
publishSeedConfig,
|
|
4
3
|
seedPayloadForInstallation
|
|
5
|
-
} from "../chunk-
|
|
6
|
-
import
|
|
7
|
-
unofferablePlacementsFound
|
|
8
|
-
} from "../chunk-ZBI6GFJD.js";
|
|
9
|
-
import "../chunk-SN64WNWE.js";
|
|
10
|
-
import "../chunk-MQZNDK5F.js";
|
|
4
|
+
} from "../chunk-JEFVFZAR.js";
|
|
5
|
+
import "../chunk-77SHXTDD.js";
|
|
11
6
|
import {
|
|
12
7
|
BaseCommand,
|
|
13
8
|
EXIT_CODES,
|
|
9
|
+
externalIdsLackingThePrefix,
|
|
10
|
+
lacksThePrefixError,
|
|
14
11
|
providerFlag,
|
|
15
|
-
providerNamedBy
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
import "../chunk-FACDJH6O.js";
|
|
12
|
+
providerNamedBy
|
|
13
|
+
} from "../chunk-E6W3PYGF.js";
|
|
14
|
+
import "../chunk-2FE4AJNC.js";
|
|
19
15
|
import {
|
|
20
16
|
formatZodErrors,
|
|
21
17
|
getErrorMessage,
|
|
22
18
|
isLocalSource,
|
|
23
19
|
shareRefusesEjectedSkills,
|
|
24
|
-
sharedConfigDestinations,
|
|
25
20
|
sharedIdNamesAFolder,
|
|
26
21
|
sharedSkillsLeftBehind,
|
|
27
22
|
warn
|
|
28
|
-
} from "../chunk-
|
|
23
|
+
} from "../chunk-D2PC7NIR.js";
|
|
29
24
|
import {
|
|
25
|
+
plural,
|
|
30
26
|
stripTerminalControls,
|
|
31
|
-
truncateText
|
|
32
|
-
|
|
33
|
-
} from "../chunk-UE4Z3YMB.js";
|
|
27
|
+
truncateText
|
|
28
|
+
} from "../chunk-KKGJH46C.js";
|
|
34
29
|
import {
|
|
35
|
-
installableSeedPayloadSchema
|
|
36
|
-
|
|
30
|
+
installableSeedPayloadSchema,
|
|
31
|
+
typedEntries
|
|
32
|
+
} from "../chunk-4SIBDIIO.js";
|
|
37
33
|
import "../chunk-GHHJYNAN.js";
|
|
38
34
|
|
|
39
35
|
// src/cli/commands/share.ts
|
|
@@ -52,6 +48,8 @@ function readPipedPayload(body) {
|
|
|
52
48
|
if (!result.success) {
|
|
53
49
|
return { ok: false, error: refusedByContract(formatZodErrors(result.error)) };
|
|
54
50
|
}
|
|
51
|
+
const unprefixed = externalIdsLackingThePrefix(result.data);
|
|
52
|
+
if (unprefixed.length > 0) return { ok: false, error: lacksThePrefixError(unprefixed) };
|
|
55
53
|
return { ok: true, payload: result.data };
|
|
56
54
|
}
|
|
57
55
|
function readJson(body) {
|
|
@@ -117,36 +115,21 @@ var Share = class _Share extends BaseCommand {
|
|
|
117
115
|
const { flags } = await this.parse(_Share);
|
|
118
116
|
if (!flags.stdin) {
|
|
119
117
|
const namedProvider = providerNamedBy(flags.provider);
|
|
120
|
-
await this.
|
|
121
|
-
await refuseAnAmbiguousInstallation(
|
|
122
|
-
process.cwd(),
|
|
123
|
-
"share",
|
|
124
|
-
namedProvider,
|
|
125
|
-
(message) => this.error(message, { exit: EXIT_CODES.INVALID_ARGS })
|
|
126
|
-
);
|
|
127
|
-
await this.ensureConfigReadable(process.cwd());
|
|
128
|
-
await this.refuseUnofferablePlacements(process.cwd());
|
|
118
|
+
await this.checkTheInstallationBeforeActing(process.cwd(), "share", namedProvider);
|
|
129
119
|
}
|
|
130
120
|
const { payload, caveats } = flags.stdin ? await this.payloadFromPipe() : await this.payloadFromInstallation();
|
|
131
|
-
|
|
132
|
-
if (!published.ok) {
|
|
133
|
-
this.error(published.error, { exit: EXIT_CODES.ERROR });
|
|
134
|
-
}
|
|
135
|
-
this.reportShared(published.id);
|
|
121
|
+
await this.publishSharedConfigOrFail(payload);
|
|
136
122
|
for (const caveat of caveats) warn(caveat);
|
|
137
123
|
}
|
|
138
|
-
/** A placement the host cannot fill was never installed here, so the id would misdescribe it. */
|
|
139
|
-
async refuseUnofferablePlacements(cwd) {
|
|
140
|
-
const [finding] = await unofferablePlacementsFound(cwd);
|
|
141
|
-
if (finding !== void 0) this.error(finding, { exit: EXIT_CODES.ERROR });
|
|
142
|
-
}
|
|
143
124
|
async payloadFromInstallation() {
|
|
144
125
|
const prepared = await seedPayloadForInstallation(process.cwd());
|
|
145
126
|
if (!prepared.ok) {
|
|
146
127
|
this.error(prepared.error, { exit: EXIT_CODES.ERROR });
|
|
147
128
|
}
|
|
148
129
|
this.refuseEjectedSkills(prepared);
|
|
149
|
-
this.log(
|
|
130
|
+
this.log(
|
|
131
|
+
`Sharing ${plural(prepared.skills, "skill")} across ${plural(prepared.agents, "sub-agent")}...`
|
|
132
|
+
);
|
|
150
133
|
return { payload: prepared.payload, caveats: caveatsAbout(prepared) };
|
|
151
134
|
}
|
|
152
135
|
/** A share carries plugins only: an ejected skill is a local copy the user may have edited. */
|
|
@@ -167,12 +150,6 @@ var Share = class _Share extends BaseCommand {
|
|
|
167
150
|
}
|
|
168
151
|
return { payload: read.payload, caveats: [] };
|
|
169
152
|
}
|
|
170
|
-
reportShared(id) {
|
|
171
|
-
this.logSuccess(`Shared as ${id}`);
|
|
172
|
-
for (const destination of sharedConfigDestinations(id)) {
|
|
173
|
-
this.log(destination);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
153
|
};
|
|
177
154
|
export {
|
|
178
155
|
Share as default
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/cli/commands/share.ts","../../src/cli/lib/seed/read-piped-payload.ts","../../src/cli/utils/read-stream.ts"],"sourcesContent":["import { Flags } from \"@oclif/core\";\n\nimport { BaseCommand } from \"../base-command.js\";\nimport { isLocalSource } from \"../lib/configuration/config.js\";\nimport { EXIT_CODES } from \"../lib/exit-codes.js\";\nimport { unofferablePlacementsFound } from \"../lib/hosts/configured-placements.js\";\nimport {\n seedPayloadForInstallation,\n type InstallationPayload,\n} from \"../lib/seed/installation-payload.js\";\nimport { publishSeedConfig } from \"../lib/seed/publish-seed.js\";\nimport {\n readPipedPayload,\n STDIN_IS_A_TERMINAL,\n type PipedPayload,\n} from \"../lib/seed/read-piped-payload.js\";\nimport {\n providerFlag,\n providerNamedBy,\n refuseAnAmbiguousInstallation,\n} from \"../lib/installation/provider-flag.js\";\nimport { warn } from \"../utils/logger.js\";\nimport { readAllOf } from \"../utils/read-stream.js\";\nimport {\n sharedConfigDestinations,\n sharedIdNamesAFolder,\n sharedSkillsLeftBehind,\n shareRefusesEjectedSkills,\n} from \"../utils/messages.js\";\nimport { typedEntries } from \"../utils/typed-object.js\";\nimport type { SkillId } from \"../types/index.js\";\nimport type { SeedPayload, SeedSkill } from \"@workspace/matrix/seed\";\n\ntype ShareablePayload = { payload: SeedPayload; caveats: string[] };\n\ntype PreparedPayload = Pick<\n Extract<InstallationPayload, { ok: true }>,\n \"payload\" | \"leftBehind\" | \"namedBy\"\n>;\n\n/** What the id will not do everywhere — warned after the id rather than refused. */\nfunction caveatsAbout({ payload, leftBehind, namedBy }: PreparedPayload): string[] {\n const { marketplace } = payload;\n return [\n ...(isAFolder(marketplace) ? [sharedIdNamesAFolder(marketplace)] : []),\n ...(leftBehind.length > 0 ? [sharedSkillsLeftBehind(leftBehind, namedBy)] : []),\n ];\n}\n\nfunction isAFolder(marketplace: string | undefined): marketplace is string {\n return marketplace !== undefined && isLocalSource(marketplace);\n}\n\nfunction ejectedSkillsIn(payload: SeedPayload): SkillId[] {\n // Keys are the config's own skill ids: this payload was drawn from the installation's entries.\n return typedEntries<SkillId, SeedSkill>(payload.skills)\n .filter(([, skill]) => skill.install === \"eject\")\n .map(([id]) => id);\n}\n\nexport default class Share extends BaseCommand {\n static summary = \"Share this installation as an id anyone can install\";\n\n static description =\n \"Turns the skills, sub-agents and per-agent curation installed here into a configuration the agentsinc.sh store holds, and prints the id it was given. Install it elsewhere with 'init --from <id>', or open it in the editor. The id is the configuration's own hash, so sharing an unchanged installation returns the id it already had.\";\n\n static flags = {\n stdin: Flags.boolean({\n description:\n \"Share a configuration piped in on standard input instead of the one installed here\",\n default: false,\n }),\n provider: providerFlag(),\n };\n\n static examples = [\n \"<%= config.bin %> <%= command.id %>\",\n \"cat proposal.json | <%= config.bin %> <%= command.id %> --stdin\",\n ];\n\n /** Everything that can fail locally fails before the POST: store writes are the scarce quota. */\n async run(): Promise<void> {\n const { flags } = await this.parse(Share);\n\n // A piped payload never reads this directory, so its state must not refuse it.\n if (!flags.stdin) {\n const namedProvider = providerNamedBy(flags.provider);\n await this.sayWhenTheGlobalInstallationStandsIn(namedProvider);\n await refuseAnAmbiguousInstallation(process.cwd(), \"share\", namedProvider, (message) =>\n this.error(message, { exit: EXIT_CODES.INVALID_ARGS }),\n );\n await this.ensureConfigReadable(process.cwd());\n await this.refuseUnofferablePlacements(process.cwd());\n }\n\n const { payload, caveats } = flags.stdin\n ? await this.payloadFromPipe()\n : await this.payloadFromInstallation();\n\n const published = await publishSeedConfig(payload);\n if (!published.ok) {\n this.error(published.error, { exit: EXIT_CODES.ERROR });\n }\n\n this.reportShared(published.id);\n // Not `this.warn`: oclif hard-wraps, which breaks the folder paths caveats name.\n for (const caveat of caveats) warn(caveat);\n }\n\n /** A placement the host cannot fill was never installed here, so the id would misdescribe it. */\n private async refuseUnofferablePlacements(cwd: string): Promise<void> {\n const [finding] = await unofferablePlacementsFound(cwd);\n if (finding !== undefined) this.error(finding, { exit: EXIT_CODES.ERROR });\n }\n\n private async payloadFromInstallation(): Promise<ShareablePayload> {\n const prepared = await seedPayloadForInstallation(process.cwd());\n if (!prepared.ok) {\n this.error(prepared.error, { exit: EXIT_CODES.ERROR });\n }\n\n this.refuseEjectedSkills(prepared);\n this.log(`Sharing ${prepared.skills} skill(s) across ${prepared.agents} sub-agent(s)...`);\n\n return { payload: prepared.payload, caveats: caveatsAbout(prepared) };\n }\n\n /** A share carries plugins only: an ejected skill is a local copy the user may have edited. */\n private refuseEjectedSkills({ payload, namedBy }: PreparedPayload): void {\n const ejected = ejectedSkillsIn(payload);\n if (ejected.length > 0) {\n this.error(shareRefusesEjectedSkills(ejected, namedBy), { exit: EXIT_CODES.ERROR });\n }\n }\n\n /** The caller's configuration; no installation is read, so it owes no caveats. */\n private async payloadFromPipe(): Promise<ShareablePayload> {\n if (process.stdin.isTTY) {\n this.error(STDIN_IS_A_TERMINAL, { exit: EXIT_CODES.ERROR });\n }\n\n const read: PipedPayload = readPipedPayload(await readAllOf(process.stdin));\n if (!read.ok) {\n this.error(read.error, { exit: EXIT_CODES.ERROR });\n }\n\n return { payload: read.payload, caveats: [] };\n }\n\n private reportShared(id: string): void {\n this.logSuccess(`Shared as ${id}`);\n for (const destination of sharedConfigDestinations(id)) {\n this.log(destination);\n }\n }\n}\n","import { installableSeedPayloadSchema, type SeedPayload } from \"@workspace/matrix/seed\";\n\nimport { formatZodErrors } from \"../schema-validator.js\";\nimport { getErrorMessage } from \"../../utils/errors.js\";\nimport { stripTerminalControls, truncateText } from \"../../utils/string.js\";\n\nexport type PipedPayload =\n | { readonly ok: true; readonly payload: SeedPayload }\n | { readonly ok: false; readonly error: string };\n\nexport const NOTHING_PIPED =\n \"--stdin expects a configuration on standard input and none arrived. Pipe one in, as 'cat proposal.json | agents-inc share --stdin'.\";\n\nexport const STDIN_IS_A_TERMINAL =\n \"--stdin expects a configuration on standard input, but standard input is a terminal. Pipe one in rather than typing it.\";\n\n/** Characters of a non-JSON body to quote back, enough for the caller to recognise it. */\nconst EXCERPT = 80;\n\n/**\n * The scope rule raises one issue per (skill, sub-agent) pair, so the list can run to hundreds.\n * A count, not a character cut, so no name is left half-printed.\n */\nconst PROBLEMS_NAMED = 4;\n\n/**\n * Fails locally before a write is spent. Uses the installable schema the store's POST validates\n * with, not the lenient read schema, so nothing passes here and fails at the edge.\n */\nexport function readPipedPayload(body: string): PipedPayload {\n if (body.trim() === \"\") return { ok: false, error: NOTHING_PIPED };\n\n const read = readJson(body);\n if (!read.parsed) return { ok: false, error: notJsonMessage(body, read.reason) };\n\n const result = installableSeedPayloadSchema.safeParse(read.value);\n if (!result.success) {\n return { ok: false, error: refusedByContract(formatZodErrors(result.error)) };\n }\n\n return { ok: true, payload: result.data };\n}\n\ntype JsonRead =\n | { readonly parsed: true; readonly value: unknown }\n | { readonly parsed: false; readonly reason: string };\n\nfunction readJson(body: string): JsonRead {\n try {\n return { parsed: true, value: JSON.parse(body) };\n } catch (error) {\n return { parsed: false, reason: getErrorMessage(error) };\n }\n}\n\n/** The parse reason is stripped too: V8 quotes the offending input verbatim in it. */\nfunction notJsonMessage(body: string, reason: string): string {\n const opening = truncateText(body.trim(), EXCERPT);\n const said = stripTerminalControls(reason);\n return `What arrived on standard input is not JSON: ${said}. It began: ${opening}`;\n}\n\nfunction refusedByContract(problems: string[]): string {\n return `The configuration on standard input is not one this store accepts: ${namedProblems(problems)}`;\n}\n\n/** The count tells a clipped list from a complete one. */\nfunction namedProblems(problems: string[]): string {\n const named = problems.slice(0, PROBLEMS_NAMED).join(\"; \");\n const elided = problems.length - PROBLEMS_NAMED;\n return elided > 0 ? `${named} (and ${elided} more)` : named;\n}\n","import type { Readable } from \"node:stream\";\n\n/** Async iteration rather than `readFileSync(\"/dev/stdin\")`, which is not portable. */\nexport async function readAllOf(stream: Readable): Promise<string> {\n const chunks: Buffer[] = [];\n for await (const chunk of stream) {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));\n }\n\n return Buffer.concat(chunks).toString(\"utf-8\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;;;ACUf,IAAM,gBACX;AAEK,IAAM,sBACX;AAGF,IAAM,UAAU;AAMhB,IAAM,iBAAiB;AAMhB,SAAS,iBAAiB,MAA4B;AAC3D,MAAI,KAAK,KAAK,MAAM,GAAI,QAAO,EAAE,IAAI,OAAO,OAAO,cAAc;AAEjE,QAAM,OAAO,SAAS,IAAI;AAC1B,MAAI,CAAC,KAAK,OAAQ,QAAO,EAAE,IAAI,OAAO,OAAO,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AO,EAAE,SAAS,KAAK,SAAS,SAAS,CAAC,EAAE;AAAA,EAC9C;AAAA,EAEQ,aAAa,IAAkB;AACrC,SAAK,WAAW,aAAa,EAAE,EAAE;AACjC,eAAW,eAAe,yBAAyB,EAAE,GAAG;AACtD,WAAK,IAAI,WAAW;AAAA,IACtB;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/cli/commands/share.ts","../../src/cli/lib/seed/read-piped-payload.ts","../../src/cli/utils/read-stream.ts"],"sourcesContent":["import { Flags } from \"@oclif/core\";\n\nimport { BaseCommand } from \"../base-command.js\";\nimport { isLocalSource } from \"../lib/configuration/config.js\";\nimport { EXIT_CODES } from \"../lib/exit-codes.js\";\nimport {\n seedPayloadForInstallation,\n type InstallationPayload,\n} from \"../lib/seed/installation-payload.js\";\nimport {\n readPipedPayload,\n STDIN_IS_A_TERMINAL,\n type PipedPayload,\n} from \"../lib/seed/read-piped-payload.js\";\nimport { providerFlag, providerNamedBy } from \"../lib/installation/provider-flag.js\";\nimport { warn } from \"../utils/logger.js\";\nimport { readAllOf } from \"../utils/read-stream.js\";\nimport {\n sharedIdNamesAFolder,\n sharedSkillsLeftBehind,\n shareRefusesEjectedSkills,\n} from \"../utils/messages.js\";\nimport { plural } from \"../utils/string.js\";\nimport { typedEntries } from \"../utils/typed-object.js\";\nimport type { SkillId } from \"../types/index.js\";\nimport type { SeedPayload, SeedSkill } from \"@workspace/matrix/seed\";\n\ntype ShareablePayload = { payload: SeedPayload; caveats: string[] };\n\ntype PreparedPayload = Pick<\n Extract<InstallationPayload, { ok: true }>,\n \"payload\" | \"leftBehind\" | \"namedBy\"\n>;\n\n/** What the id will not do everywhere — warned after the id rather than refused. */\nfunction caveatsAbout({ payload, leftBehind, namedBy }: PreparedPayload): string[] {\n const { marketplace } = payload;\n return [\n ...(isAFolder(marketplace) ? [sharedIdNamesAFolder(marketplace)] : []),\n ...(leftBehind.length > 0 ? [sharedSkillsLeftBehind(leftBehind, namedBy)] : []),\n ];\n}\n\nfunction isAFolder(marketplace: string | undefined): marketplace is string {\n return marketplace !== undefined && isLocalSource(marketplace);\n}\n\nfunction ejectedSkillsIn(payload: SeedPayload): SkillId[] {\n // Keys are the config's own skill ids: this payload was drawn from the installation's entries.\n return typedEntries<SkillId, SeedSkill>(payload.skills)\n .filter(([, skill]) => skill.install === \"eject\")\n .map(([id]) => id);\n}\n\nexport default class Share extends BaseCommand {\n static summary = \"Share this installation as an id anyone can install\";\n\n static description =\n \"Turns the skills, sub-agents and per-agent curation installed here into a configuration the agentsinc.sh store holds, and prints the id it was given. Install it elsewhere with 'init --from <id>', or open it in the editor. The id is the configuration's own hash, so sharing an unchanged installation returns the id it already had.\";\n\n static flags = {\n stdin: Flags.boolean({\n description:\n \"Share a configuration piped in on standard input instead of the one installed here\",\n default: false,\n }),\n provider: providerFlag(),\n };\n\n static examples = [\n \"<%= config.bin %> <%= command.id %>\",\n \"cat proposal.json | <%= config.bin %> <%= command.id %> --stdin\",\n ];\n\n /** Everything that can fail locally fails before the POST: store writes are the scarce quota. */\n async run(): Promise<void> {\n const { flags } = await this.parse(Share);\n\n // A piped payload never reads this directory, so its state must not refuse it.\n if (!flags.stdin) {\n const namedProvider = providerNamedBy(flags.provider);\n await this.checkTheInstallationBeforeActing(process.cwd(), \"share\", namedProvider);\n }\n\n const { payload, caveats } = flags.stdin\n ? await this.payloadFromPipe()\n : await this.payloadFromInstallation();\n\n await this.publishSharedConfigOrFail(payload);\n // Not `this.warn`: oclif hard-wraps, which breaks the folder paths caveats name.\n for (const caveat of caveats) warn(caveat);\n }\n\n private async payloadFromInstallation(): Promise<ShareablePayload> {\n const prepared = await seedPayloadForInstallation(process.cwd());\n if (!prepared.ok) {\n this.error(prepared.error, { exit: EXIT_CODES.ERROR });\n }\n\n this.refuseEjectedSkills(prepared);\n this.log(\n `Sharing ${plural(prepared.skills, \"skill\")} across ${plural(prepared.agents, \"sub-agent\")}...`,\n );\n\n return { payload: prepared.payload, caveats: caveatsAbout(prepared) };\n }\n\n /** A share carries plugins only: an ejected skill is a local copy the user may have edited. */\n private refuseEjectedSkills({ payload, namedBy }: PreparedPayload): void {\n const ejected = ejectedSkillsIn(payload);\n if (ejected.length > 0) {\n this.error(shareRefusesEjectedSkills(ejected, namedBy), { exit: EXIT_CODES.ERROR });\n }\n }\n\n /** The caller's configuration; no installation is read, so it owes no caveats. */\n private async payloadFromPipe(): Promise<ShareablePayload> {\n if (process.stdin.isTTY) {\n this.error(STDIN_IS_A_TERMINAL, { exit: EXIT_CODES.ERROR });\n }\n\n const read: PipedPayload = readPipedPayload(await readAllOf(process.stdin));\n if (!read.ok) {\n this.error(read.error, { exit: EXIT_CODES.ERROR });\n }\n\n return { payload: read.payload, caveats: [] };\n }\n}\n","import { installableSeedPayloadSchema, type SeedPayload } from \"@workspace/matrix/seed\";\n\nimport { externalIdsLackingThePrefix, lacksThePrefixError } from \"./external-skills.js\";\nimport { formatZodErrors } from \"../schema-validator.js\";\nimport { getErrorMessage } from \"../../utils/errors.js\";\nimport { stripTerminalControls, truncateText } from \"../../utils/string.js\";\n\nexport type PipedPayload =\n | { readonly ok: true; readonly payload: SeedPayload }\n | { readonly ok: false; readonly error: string };\n\nexport const NOTHING_PIPED =\n \"--stdin expects a configuration on standard input and none arrived. Pipe one in, as 'cat proposal.json | agents-inc share --stdin'.\";\n\nexport const STDIN_IS_A_TERMINAL =\n \"--stdin expects a configuration on standard input, but standard input is a terminal. Pipe one in rather than typing it.\";\n\n/** Characters of a non-JSON body to quote back, enough for the caller to recognise it. */\nconst EXCERPT = 80;\n\n/**\n * The scope rule raises one issue per (skill, sub-agent) pair, so the list can run to hundreds.\n * A count, not a character cut, so no name is left half-printed.\n */\nconst PROBLEMS_NAMED = 4;\n\n/**\n * Fails locally before a write is spent. Uses the installable schema the store's POST validates\n * with, not the lenient read schema, so nothing passes here and fails at the edge. The installer's\n * id-prefix rule runs here rather than in that schema, every refusal of which the editor reports\n * as an unwritable assignment.\n */\nexport function readPipedPayload(body: string): PipedPayload {\n if (body.trim() === \"\") return { ok: false, error: NOTHING_PIPED };\n\n const read = readJson(body);\n if (!read.parsed) return { ok: false, error: notJsonMessage(body, read.reason) };\n\n const result = installableSeedPayloadSchema.safeParse(read.value);\n if (!result.success) {\n return { ok: false, error: refusedByContract(formatZodErrors(result.error)) };\n }\n\n const unprefixed = externalIdsLackingThePrefix(result.data);\n if (unprefixed.length > 0) return { ok: false, error: lacksThePrefixError(unprefixed) };\n\n return { ok: true, payload: result.data };\n}\n\ntype JsonRead =\n | { readonly parsed: true; readonly value: unknown }\n | { readonly parsed: false; readonly reason: string };\n\nfunction readJson(body: string): JsonRead {\n try {\n return { parsed: true, value: JSON.parse(body) };\n } catch (error) {\n return { parsed: false, reason: getErrorMessage(error) };\n }\n}\n\n/** The parse reason is stripped too: V8 quotes the offending input verbatim in it. */\nfunction notJsonMessage(body: string, reason: string): string {\n const opening = truncateText(body.trim(), EXCERPT);\n const said = stripTerminalControls(reason);\n return `What arrived on standard input is not JSON: ${said}. It began: ${opening}`;\n}\n\nfunction refusedByContract(problems: string[]): string {\n return `The configuration on standard input is not one this store accepts: ${namedProblems(problems)}`;\n}\n\n/** The count tells a clipped list from a complete one. */\nfunction namedProblems(problems: string[]): string {\n const named = problems.slice(0, PROBLEMS_NAMED).join(\"; \");\n const elided = problems.length - PROBLEMS_NAMED;\n return elided > 0 ? `${named} (and ${elided} more)` : named;\n}\n","import type { Readable } from \"node:stream\";\n\n/** Async iteration rather than `readFileSync(\"/dev/stdin\")`, which is not portable. */\nexport async function readAllOf(stream: Readable): Promise<string> {\n const chunks: Buffer[] = [];\n for await (const chunk of stream) {\n chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(String(chunk)));\n }\n\n return Buffer.concat(chunks).toString(\"utf-8\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;;;ACWf,IAAM,gBACX;AAEK,IAAM,sBACX;AAGF,IAAM,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{
|
|
3
|
+
projectFoldersAnUninstallMayEmpty,
|
|
4
|
+
removeIfHoldingNothing
|
|
5
|
+
} from "../chunk-AVKX3IXF.js";
|
|
2
6
|
import {
|
|
3
7
|
Confirm
|
|
4
8
|
} from "../chunk-OZXAJNLA.js";
|
|
@@ -7,31 +11,40 @@ import {
|
|
|
7
11
|
} from "../chunk-P6CYS4JK.js";
|
|
8
12
|
import {
|
|
9
13
|
summaryPanelBlock
|
|
10
|
-
} from "../chunk-
|
|
14
|
+
} from "../chunk-7WN6TUZP.js";
|
|
15
|
+
import {
|
|
16
|
+
codexProjectUntrustMessage,
|
|
17
|
+
untrustCodexProject
|
|
18
|
+
} from "../chunk-H33ZAEKH.js";
|
|
11
19
|
import {
|
|
20
|
+
blankGlobalConfig,
|
|
12
21
|
lazyGateDeps,
|
|
13
22
|
mutateGlobal,
|
|
14
23
|
propagateGlobalRemoval
|
|
15
|
-
} from "../chunk-
|
|
16
|
-
import
|
|
24
|
+
} from "../chunk-TNN72UL6.js";
|
|
25
|
+
import {
|
|
26
|
+
SCOPE_OF_AN_UNRECORDED_SKILL
|
|
27
|
+
} from "../chunk-V3WJMNBF.js";
|
|
17
28
|
import {
|
|
18
29
|
loadAgentDefs
|
|
19
|
-
} from "../chunk-
|
|
20
|
-
import "../chunk-
|
|
30
|
+
} from "../chunk-XSR4WRXJ.js";
|
|
31
|
+
import "../chunk-VFD2XYM7.js";
|
|
32
|
+
import "../chunk-5ZK4IND4.js";
|
|
21
33
|
import {
|
|
34
|
+
filterExcludedEntries,
|
|
22
35
|
listAgentFilesOf,
|
|
23
36
|
splitAgentsByProvenance
|
|
24
|
-
} from "../chunk-
|
|
37
|
+
} from "../chunk-77SHXTDD.js";
|
|
25
38
|
import "../chunk-KIK5EZYD.js";
|
|
26
|
-
import "../chunk-
|
|
39
|
+
import "../chunk-ZIBWVTLN.js";
|
|
40
|
+
import "../chunk-OIQKRXHH.js";
|
|
27
41
|
import {
|
|
28
42
|
BaseCommand,
|
|
29
43
|
EXIT_CODES,
|
|
30
44
|
providerFlag,
|
|
31
|
-
providerNamedBy
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
import "../chunk-FACDJH6O.js";
|
|
45
|
+
providerNamedBy
|
|
46
|
+
} from "../chunk-E6W3PYGF.js";
|
|
47
|
+
import "../chunk-2FE4AJNC.js";
|
|
35
48
|
import {
|
|
36
49
|
ConfigLoadError,
|
|
37
50
|
INFO_MESSAGES,
|
|
@@ -47,9 +60,11 @@ import {
|
|
|
47
60
|
hostAt,
|
|
48
61
|
isAgentName,
|
|
49
62
|
isHomeDirectory,
|
|
63
|
+
jsonFileMatches,
|
|
50
64
|
listDirectories,
|
|
51
65
|
listPluginNames,
|
|
52
66
|
loadProjectConfigAt,
|
|
67
|
+
loadProjectConfigFromDir,
|
|
53
68
|
loadSkillsMatrixFromSource,
|
|
54
69
|
notInstalledHere,
|
|
55
70
|
parseMarketplacePluginRef,
|
|
@@ -62,29 +77,31 @@ import {
|
|
|
62
77
|
remove,
|
|
63
78
|
removeDirIfEmpty,
|
|
64
79
|
resolveInstallPaths,
|
|
80
|
+
scopeAt,
|
|
65
81
|
sourceFolderInUse,
|
|
66
82
|
sourceRootOf,
|
|
67
83
|
uninstallConfigUnreadable,
|
|
68
84
|
uninstallNeedsTerminal,
|
|
69
85
|
uninstallSkillMetadataUnreadable,
|
|
70
86
|
unmarkedAgentsKept
|
|
71
|
-
} from "../chunk-
|
|
87
|
+
} from "../chunk-D2PC7NIR.js";
|
|
72
88
|
import {
|
|
73
89
|
plural
|
|
74
|
-
} from "../chunk-
|
|
90
|
+
} from "../chunk-KKGJH46C.js";
|
|
75
91
|
import {
|
|
76
|
-
CLAUDE_DIR,
|
|
77
92
|
DEFAULT_BRANDING,
|
|
78
93
|
EJECT_SOURCE,
|
|
79
94
|
STANDARD_FILES,
|
|
80
95
|
isActiveAt
|
|
81
|
-
} from "../chunk-
|
|
96
|
+
} from "../chunk-4SIBDIIO.js";
|
|
82
97
|
import "../chunk-GHHJYNAN.js";
|
|
83
98
|
|
|
84
99
|
// src/cli/commands/uninstall.tsx
|
|
85
100
|
import "react";
|
|
86
|
-
import { unique, uniqueBy } from "remeda";
|
|
101
|
+
import { isDeepEqual, unique, uniqueBy } from "remeda";
|
|
102
|
+
import os from "os";
|
|
87
103
|
import path from "path";
|
|
104
|
+
import { z } from "zod";
|
|
88
105
|
import { Flags } from "@oclif/core";
|
|
89
106
|
import { jsx } from "react/jsx-runtime";
|
|
90
107
|
function buildRemovalPlan(target) {
|
|
@@ -100,7 +117,7 @@ function buildRemovalPlan(target) {
|
|
|
100
117
|
};
|
|
101
118
|
}
|
|
102
119
|
function removalPanel(plan, target) {
|
|
103
|
-
const kept = target.scope === "project" ? globalEntriesOf(target.config) :
|
|
120
|
+
const kept = target.scope === "project" ? globalEntriesOf(target.config) : nothingKept();
|
|
104
121
|
const removed = removedSkills(plan, target);
|
|
105
122
|
return {
|
|
106
123
|
skillConfigs: kept.skills,
|
|
@@ -112,9 +129,11 @@ function removalPanel(plan, target) {
|
|
|
112
129
|
headerSkillConfigs: removed.length > 0 ? removed : kept.skills
|
|
113
130
|
};
|
|
114
131
|
}
|
|
115
|
-
|
|
132
|
+
function nothingKept() {
|
|
133
|
+
return { skills: [], agents: [] };
|
|
134
|
+
}
|
|
116
135
|
function globalEntriesOf(config) {
|
|
117
|
-
if (config === null) return
|
|
136
|
+
if (config === null) return nothingKept();
|
|
118
137
|
return {
|
|
119
138
|
skills: config.skills.filter((skill) => isActiveAt(skill, "global")),
|
|
120
139
|
agents: config.agents.filter((agent) => isActiveAt(agent, "global"))
|
|
@@ -224,12 +243,7 @@ var Uninstall = class _Uninstall extends BaseCommand {
|
|
|
224
243
|
const { flags } = await this.parse(_Uninstall);
|
|
225
244
|
const projectDir = process.cwd();
|
|
226
245
|
const namedProvider = providerNamedBy(flags.provider);
|
|
227
|
-
await refuseAnAmbiguousInstallation(
|
|
228
|
-
projectDir,
|
|
229
|
-
"uninstall",
|
|
230
|
-
namedProvider,
|
|
231
|
-
(message) => this.error(message, { exit: EXIT_CODES.INVALID_ARGS })
|
|
232
|
-
);
|
|
246
|
+
await this.refuseAnAmbiguousInstallation(projectDir, "uninstall", namedProvider);
|
|
233
247
|
this.brandingName = await this.resolveBrandingName(projectDir);
|
|
234
248
|
this.printHeader();
|
|
235
249
|
const target = await detectUninstallTarget(projectDir, {
|
|
@@ -293,14 +307,40 @@ var Uninstall = class _Uninstall extends BaseCommand {
|
|
|
293
307
|
async executeUninstall(plan, target, projectDir) {
|
|
294
308
|
const isGlobalUninstall = isHomeDirectory(projectDir);
|
|
295
309
|
const propagation = isGlobalUninstall ? await this.prepareGlobalPropagation(target, projectDir) : null;
|
|
296
|
-
await this.removePlannedPlugins(planEntry(plan, "plugins"), target
|
|
310
|
+
await this.removePlannedPlugins(planEntry(plan, "plugins"), target, projectDir);
|
|
297
311
|
await this.removeLocalFilesOrFail(plan, target);
|
|
298
312
|
if (!isGlobalUninstall) {
|
|
313
|
+
if (target.provider === "codex") await this.untrustTheCodexProject(projectDir);
|
|
299
314
|
await this.deregisterProject(projectDir, target.provider);
|
|
300
315
|
return;
|
|
301
316
|
}
|
|
302
317
|
if (propagation) await this.updateRegisteredProjects(propagation);
|
|
303
318
|
}
|
|
319
|
+
/** Degrades as {@link deregisterProject} does: the installation is already gone. */
|
|
320
|
+
async untrustTheCodexProject(projectDir) {
|
|
321
|
+
try {
|
|
322
|
+
const removal = await untrustCodexProject(projectDir);
|
|
323
|
+
const said = codexProjectUntrustMessage(projectDir, removal);
|
|
324
|
+
if (said !== void 0) this.log(said);
|
|
325
|
+
if (removal.kind === "trust removed") {
|
|
326
|
+
await this.removeCodexConfigLeftEmpty(removal.configFile);
|
|
327
|
+
}
|
|
328
|
+
} catch (error) {
|
|
329
|
+
this.warn(
|
|
330
|
+
`Could not remove this project's trust from your Codex configuration: ${getErrorMessage(error)}`
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
/** Its own degrade, since the trust is already out. */
|
|
335
|
+
async removeCodexConfigLeftEmpty(configFile) {
|
|
336
|
+
try {
|
|
337
|
+
await removeIfHoldingNothing(configFile);
|
|
338
|
+
} catch (error) {
|
|
339
|
+
this.warn(
|
|
340
|
+
`Could not remove ${configFile}, which now holds nothing: ${getErrorMessage(error)}`
|
|
341
|
+
);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
304
344
|
/** Degrades: a missing or corrupt global config must never fail the uninstall. */
|
|
305
345
|
async deregisterProject(projectDir, provider) {
|
|
306
346
|
try {
|
|
@@ -308,6 +348,7 @@ var Uninstall = class _Uninstall extends BaseCommand {
|
|
|
308
348
|
{ kind: "deregister-project", projectDir, provider },
|
|
309
349
|
lazyGateDeps(projectDir)
|
|
310
350
|
);
|
|
351
|
+
await removeTheHomeConfigListingNothing(provider);
|
|
311
352
|
} catch (error) {
|
|
312
353
|
this.warn(`Could not update the global project registry: ${getErrorMessage(error)}`);
|
|
313
354
|
}
|
|
@@ -389,7 +430,9 @@ var Uninstall = class _Uninstall extends BaseCommand {
|
|
|
389
430
|
const cleanup = await cleanupEmptyDirs(target, planEntries(plan, "config"));
|
|
390
431
|
this.reportSourceFolderCleanup(cleanup.sourceFolder);
|
|
391
432
|
this.reportDirCleanup(target.sourceRoot.relName, cleanup.sourceRoot);
|
|
392
|
-
|
|
433
|
+
for (const { dir, outcome } of cleanup.hostFolders) {
|
|
434
|
+
this.reportDirCleanup(path.basename(dir), outcome);
|
|
435
|
+
}
|
|
393
436
|
}
|
|
394
437
|
reportSourceFolderCleanup({ relName, outcome }) {
|
|
395
438
|
if (outcome === "config-removed") {
|
|
@@ -414,11 +457,11 @@ var Uninstall = class _Uninstall extends BaseCommand {
|
|
|
414
457
|
}
|
|
415
458
|
}
|
|
416
459
|
}
|
|
417
|
-
async removePlannedPlugins(entry,
|
|
460
|
+
async removePlannedPlugins(entry, target, projectDir) {
|
|
418
461
|
if (!entry) return;
|
|
419
462
|
this.log("Uninstalling plugins...");
|
|
420
463
|
try {
|
|
421
|
-
const pluginResult = await uninstallPlugins(entry,
|
|
464
|
+
const pluginResult = await uninstallPlugins(entry, target, projectDir, {
|
|
422
465
|
onUninstalled: (name) => this.log(` Uninstalled plugin '${name}'`),
|
|
423
466
|
onLeftRegistered: (name, provider) => this.warn(pluginLeftRegistered(name, provider))
|
|
424
467
|
});
|
|
@@ -498,23 +541,15 @@ async function manifestFilesIn(dir) {
|
|
|
498
541
|
);
|
|
499
542
|
return manifest.filter((_, index) => present[index]);
|
|
500
543
|
}
|
|
501
|
-
function activeConfigOf(config) {
|
|
502
|
-
return {
|
|
503
|
-
...config,
|
|
504
|
-
skills: config.skills.filter((s) => !s.excluded),
|
|
505
|
-
agents: config.agents.filter((a) => !a.excluded)
|
|
506
|
-
};
|
|
507
|
-
}
|
|
508
544
|
async function detectUninstallTarget(projectDir, handlers) {
|
|
509
545
|
const pluginsDir = getProjectPluginsDir(projectDir);
|
|
510
|
-
const scope =
|
|
546
|
+
const scope = scopeAt(projectDir);
|
|
511
547
|
const { skillsDir, agentsDir } = resolveInstallPaths(projectDir, scope);
|
|
512
|
-
const claudeDir = path.join(projectDir, CLAUDE_DIR);
|
|
513
548
|
const provider = providerInUse(projectDir);
|
|
514
549
|
const codec = agentCodec(provider);
|
|
515
|
-
const [cliSkills,
|
|
550
|
+
const [cliSkills, hostFolders, sourceFolder, agentProvenance] = await Promise.all([
|
|
516
551
|
skillsThisCliInstalled(skillsDir, handlers.onSkillMetadataUnreadable),
|
|
517
|
-
|
|
552
|
+
hostFoldersAt(projectDir, provider),
|
|
518
553
|
readSourceFolder(
|
|
519
554
|
sourceFolderInUse(projectDir, provider),
|
|
520
555
|
projectDir,
|
|
@@ -524,7 +559,7 @@ async function detectUninstallTarget(projectDir, handlers) {
|
|
|
524
559
|
splitAgentsByProvenance(agentsDir, codec)
|
|
525
560
|
]);
|
|
526
561
|
const { config } = sourceFolder;
|
|
527
|
-
const activeConfig = config === null ? null :
|
|
562
|
+
const activeConfig = config === null ? null : filterExcludedEntries(config);
|
|
528
563
|
const cliPluginNames = await pluginsThisRunRemoves(projectDir, activeConfig);
|
|
529
564
|
return {
|
|
530
565
|
scope,
|
|
@@ -532,11 +567,16 @@ async function detectUninstallTarget(projectDir, handlers) {
|
|
|
532
567
|
hasPlugins: cliPluginNames.length > 0,
|
|
533
568
|
cliPluginNames,
|
|
534
569
|
cliSkills,
|
|
535
|
-
|
|
570
|
+
pluginsTheGlobalHolds: await pluginsTheGlobalInstallationHolds(
|
|
571
|
+
projectDir,
|
|
572
|
+
provider,
|
|
573
|
+
cliPluginNames,
|
|
574
|
+
handlers.onConfigLoadFailed
|
|
575
|
+
),
|
|
536
576
|
pluginsDir,
|
|
537
577
|
skillsDir,
|
|
538
578
|
agentsDir,
|
|
539
|
-
|
|
579
|
+
hostFolders,
|
|
540
580
|
sourceFolder,
|
|
541
581
|
sourceRoot: sourceRootOf(projectDir),
|
|
542
582
|
config,
|
|
@@ -557,6 +597,24 @@ function thisRunOwnsAnyPlugin(projectDir) {
|
|
|
557
597
|
if (isHomeDirectory(projectDir)) return true;
|
|
558
598
|
return hostAt(projectDir).installsProjectScopedPlugins;
|
|
559
599
|
}
|
|
600
|
+
async function pluginsTheGlobalInstallationHolds(projectDir, provider, pluginNames, onConfigLoadFailed) {
|
|
601
|
+
if (isHomeDirectory(projectDir) || pluginNames.length === 0) return /* @__PURE__ */ new Set();
|
|
602
|
+
try {
|
|
603
|
+
const global = await loadProjectConfigFromDir(os.homedir(), provider);
|
|
604
|
+
if (global === null) return /* @__PURE__ */ new Set();
|
|
605
|
+
const held = getCliInstalledPluginKeys(filterExcludedEntries(global.config));
|
|
606
|
+
return new Set(pluginNames.filter((name) => held.has(name)));
|
|
607
|
+
} catch (error) {
|
|
608
|
+
if (!(error instanceof ConfigLoadError)) throw error;
|
|
609
|
+
onConfigLoadFailed(error);
|
|
610
|
+
return new Set(pluginNames);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
async function hostFoldersAt(projectDir, provider) {
|
|
614
|
+
const folders = projectFoldersAnUninstallMayEmpty(provider, projectDir);
|
|
615
|
+
const present = await Promise.all(folders.map(directoryExists));
|
|
616
|
+
return folders.filter((_, at) => present[at]);
|
|
617
|
+
}
|
|
560
618
|
async function skillsThisCliInstalled(skillsDir, onMetadataUnreadable) {
|
|
561
619
|
const dirNames = await listDirectories(skillsDir);
|
|
562
620
|
const skills = await Promise.all(
|
|
@@ -598,15 +656,18 @@ async function removeMatchingAgents(entry, onRemoved) {
|
|
|
598
656
|
}
|
|
599
657
|
return removedNames;
|
|
600
658
|
}
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
const offered = host.offeredPlacements.filter((placement) => placement.mode === "plugin").map((placement) => placement.scope);
|
|
659
|
+
function pluginScopesToSweep(host, target, pluginName) {
|
|
660
|
+
const primary = scopeThePluginIsFiledUnder(target.config, pluginName);
|
|
661
|
+
const offered = host.offeredPlacements.filter((placement) => placement.mode === "plugin").map((placement) => placement.scope).filter((scope) => !theGlobalStillHoldsItAt(scope, target, pluginName));
|
|
604
662
|
if (!offered.includes(primary)) return offered;
|
|
605
663
|
return [primary, ...offered.filter((scope) => scope !== primary)];
|
|
606
664
|
}
|
|
607
|
-
|
|
665
|
+
function theGlobalStillHoldsItAt(scope, target, pluginName) {
|
|
666
|
+
return scope === "global" && target.pluginsTheGlobalHolds.has(pluginName);
|
|
667
|
+
}
|
|
668
|
+
async function removePluginWhereverItIsFiled(host, pluginRef, scopes, projectDir) {
|
|
608
669
|
let outcome = "absent";
|
|
609
|
-
for (const scope of
|
|
670
|
+
for (const scope of scopes) {
|
|
610
671
|
try {
|
|
611
672
|
const swept = await host.uninstallPlugin(pluginRef, scope, projectDir);
|
|
612
673
|
if (swept === "removed") outcome = "removed";
|
|
@@ -615,7 +676,7 @@ async function removePluginWhereverItIsFiled(host, pluginRef, primaryScope, proj
|
|
|
615
676
|
}
|
|
616
677
|
return outcome;
|
|
617
678
|
}
|
|
618
|
-
async function uninstallPlugins(entry,
|
|
679
|
+
async function uninstallPlugins(entry, target, projectDir, { onUninstalled, onLeftRegistered } = {}) {
|
|
619
680
|
const host = hostAt(projectDir);
|
|
620
681
|
const hostAvailable = await host.isAvailable();
|
|
621
682
|
const observed = [];
|
|
@@ -626,7 +687,7 @@ async function uninstallPlugins(entry, config, projectDir, { onUninstalled, onLe
|
|
|
626
687
|
const removal = hostAvailable ? await removePluginWhereverItIsFiled(
|
|
627
688
|
host,
|
|
628
689
|
pluginName,
|
|
629
|
-
|
|
690
|
+
pluginScopesToSweep(host, target, pluginName),
|
|
630
691
|
projectDir
|
|
631
692
|
) : nothingWasObserved();
|
|
632
693
|
await remove(path.join(entry.pluginsDir, pluginName));
|
|
@@ -639,7 +700,8 @@ async function uninstallPlugins(entry, config, projectDir, { onUninstalled, onLe
|
|
|
639
700
|
}
|
|
640
701
|
function scopeThePluginIsFiledUnder(config, pluginName) {
|
|
641
702
|
const skillId = parseMarketplacePluginRef(pluginName);
|
|
642
|
-
|
|
703
|
+
const filed = config?.skills.find((skill) => skill.id === skillId && !skill.excluded);
|
|
704
|
+
return filed?.scope ?? SCOPE_OF_AN_UNRECORDED_SKILL;
|
|
643
705
|
}
|
|
644
706
|
function nothingWasObserved() {
|
|
645
707
|
return "absent";
|
|
@@ -659,8 +721,24 @@ async function cleanupEmptyDirs(target, manifestEntries) {
|
|
|
659
721
|
manifestEntries.find((entry) => entry.sourceDir === target.sourceFolder.dir)
|
|
660
722
|
);
|
|
661
723
|
const sourceRoot = await cleanupSourceRoot(target.sourceRoot, sourceFolder.outcome === "removed");
|
|
662
|
-
const
|
|
663
|
-
|
|
724
|
+
const hostFolders = await Promise.all(
|
|
725
|
+
target.hostFolders.map((dir) => cleanupHostFolder(dir, target.provider))
|
|
726
|
+
);
|
|
727
|
+
return { sourceFolder, sourceRoot, hostFolders };
|
|
728
|
+
}
|
|
729
|
+
async function removeTheHomeConfigListingNothing(provider) {
|
|
730
|
+
const home = os.homedir();
|
|
731
|
+
const loaded = await loadProjectConfigFromDir(home, provider);
|
|
732
|
+
if (loaded === null || !listsNothing(loaded.config)) return;
|
|
733
|
+
const folder = sourceFolderInUse(home, provider);
|
|
734
|
+
const { outcome } = await cleanupSourceFolder(folder, await manifestRemovalIn(folder.dir));
|
|
735
|
+
await cleanupSourceRoot(sourceRootOf(home), outcome === "removed");
|
|
736
|
+
}
|
|
737
|
+
function listsNothing({ projects = [], ...rest }) {
|
|
738
|
+
return projects.length === 0 && isDeepEqual(rest, blankGlobalConfig());
|
|
739
|
+
}
|
|
740
|
+
async function manifestRemovalIn(sourceDir) {
|
|
741
|
+
return { kind: "config", sourceDir, fileNames: await manifestFilesIn(sourceDir) };
|
|
664
742
|
}
|
|
665
743
|
async function cleanupSourceFolder(folder, entry) {
|
|
666
744
|
const manifestRemoved = await removeConfigManifest(entry);
|
|
@@ -672,10 +750,15 @@ async function cleanupSourceRoot(sourceRoot, providerDirRemoved) {
|
|
|
672
750
|
if (!providerDirRemoved) return "untouched";
|
|
673
751
|
return removeDirUnlessUserContent(sourceRoot.dir);
|
|
674
752
|
}
|
|
675
|
-
async function
|
|
676
|
-
if (
|
|
677
|
-
return removeDirUnlessUserContent(
|
|
753
|
+
async function cleanupHostFolder(dir, provider) {
|
|
754
|
+
if (provider === "claude") await removeAnEmptyPluginList(dir);
|
|
755
|
+
return { dir, outcome: await removeDirUnlessUserContent(dir) };
|
|
756
|
+
}
|
|
757
|
+
async function removeAnEmptyPluginList(claudeDir) {
|
|
758
|
+
const settings = path.join(claudeDir, STANDARD_FILES.SETTINGS_JSON);
|
|
759
|
+
if (await jsonFileMatches(settings, EMPTY_PLUGIN_LIST)) await remove(settings);
|
|
678
760
|
}
|
|
761
|
+
var EMPTY_PLUGIN_LIST = z.strictObject({ enabledPlugins: z.strictObject({}) });
|
|
679
762
|
async function removeDirUnlessUserContent(dir) {
|
|
680
763
|
if (await removeDirIfEmpty(dir)) return "removed";
|
|
681
764
|
return await directoryExists(dir) ? "kept" : "untouched";
|