forest-cli 5.22.1 → 5.24.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.
@@ -0,0 +1,181 @@
1
+ /**
2
+ * Shared logic for `skills:init` / `skills:update`.
3
+ *
4
+ * Two distribution routes, because coding agents split in two families:
5
+ *
6
+ * - Agents with a native plugin system (Claude Code, Codex) → we drive THEIR CLI
7
+ * (`claude plugin …` / `codex plugin …`). They fetch, version, auto-update and wire the
8
+ * Forest docs MCP themselves, and the user gets the plugin's slash commands too. Nothing
9
+ * is copied into the repo.
10
+ * - Agents that only discover `SKILL.md` files (Cursor, OpenCode, …) → we copy the same
11
+ * plugins' skills into `.agents/skills/`, the cross-agent convention they all read, so both
12
+ * routes deliver the same set.
13
+ *
14
+ * The marketplace repo is PUBLIC → no auth needed for the fetch, and both plugin CLIs read
15
+ * the same `.claude-plugin/marketplace.json` (verified against codex-cli 0.147.0), so one
16
+ * catalog serves every agent.
17
+ */
18
+ export declare const MARKETPLACE_REPO = "ForestAdmin/ai-marketplace";
19
+ export declare const MARKETPLACE_NAME = "forest-admin-ai";
20
+ /**
21
+ * The Forest plugins this command ships — the ONLY thing it decides, and it decides it once for
22
+ * both routes. These three are what "knowing Forest" means: how to build a back-office (`forest`),
23
+ * how to write agent code (`forest-code`), and how to look things up (`forest-docs`).
24
+ *
25
+ * `forest-mcp` is not one of them: it is a data-access server for querying a live project's
26
+ * records, not help for the developer, so it has no place in a command whose job is to teach the
27
+ * agent Forest. Anyone who wants it installs it themselves.
28
+ *
29
+ * Nothing below the plugin is filtered. There used to be a hand-picked list of skill NAMES, and it
30
+ * did real damage: the plugin route installs whole plugins, so a name left out still shipped
31
+ * there, and the skills cross-reference each other — `onboard` hands the production step to
32
+ * `deploy-heroku`, which the list excluded — leaving copy-route users with an `onboard` skill
33
+ * pointing at something never installed. A plugin is the unit of distribution and is coherent only
34
+ * as a whole; what it contains is the marketplace's call, not ours. Choosing plugins is a product
35
+ * decision, choosing their contents is drift waiting to happen.
36
+ */
37
+ export declare const FOREST_PLUGINS: string[];
38
+ /**
39
+ * The single skills dir on the copy route. `.agents/skills/` is the cross-agent convention:
40
+ * Cursor and OpenCode both read it (alongside their own `.cursor/`, `.opencode/`), and so does
41
+ * Codex. Claude Code is the one agent that does NOT read it — it reads `.claude/skills/` — but
42
+ * it is served by the plugin route, so a second copy would only duplicate its skills.
43
+ */
44
+ export declare const SKILLS_DIR = ".agents/skills";
45
+ /** Agents served by driving their own plugin CLI. */
46
+ export declare const PLUGIN_AGENTS: readonly ["claude", "codex"];
47
+ /** Agents served by copying SKILL.md files into SKILLS_DIR. */
48
+ export declare const COPY_AGENTS: readonly ["cursor", "opencode", "other"];
49
+ export declare const ALL_AGENTS: readonly ["claude", "codex", "cursor", "opencode", "other"];
50
+ export type PluginAgent = (typeof PLUGIN_AGENTS)[number];
51
+ export type Agent = (typeof ALL_AGENTS)[number];
52
+ export declare const AGENT_LABELS: Record<Agent, string>;
53
+ export declare const isPluginAgent: (agent: string) => agent is "claude" | "codex";
54
+ export declare const MANIFEST_PATH = ".forest/skills-manifest.json";
55
+ /** Context files, per agent. AGENTS.md is the cross-agent standard (Codex, Cursor, OpenCode). */
56
+ export declare function contextFileFor(agent: Agent): string;
57
+ /**
58
+ * The Forest block merged into a context file, describing every route that feeds THAT file.
59
+ *
60
+ * Takes the agents rather than one agent because a single file often serves both routes: AGENTS.md
61
+ * is Codex's (plugin) and Cursor's and OpenCode's (copy). Writing one block per agent would have
62
+ * the second merge replace the first — same delimiters — leaving the file describing only whichever
63
+ * route ran last.
64
+ */
65
+ export declare function forestBlock(agents: Agent[]): string;
66
+ /** Group agents by the context file they write to, so each file gets exactly one merged block. */
67
+ export declare function contextFileGroups(agents: Agent[]): Map<string, Agent[]>;
68
+ export type Manifest = {
69
+ ref: string;
70
+ installedAt: string;
71
+ /** Absent on manifests written before the field existed — those are copy-route installs. */
72
+ agents?: string[];
73
+ /** The ref each agent's content came from. Absent on manifests that predate it, whose agents all
74
+ * came from `ref`. */
75
+ refs?: Record<string, string>;
76
+ files: string[];
77
+ };
78
+ /**
79
+ * Download + extract the marketplace tarball at `ref`. Returns the extracted root dir and a
80
+ * `cleanup` the caller must run (in a finally) to delete the temp dir — otherwise every
81
+ * init/update leaks a full copy of the marketplace under the OS temp dir.
82
+ *
83
+ * Only the copy route needs this: the plugin CLIs do their own fetching.
84
+ */
85
+ export declare function fetchMarketplace(ref?: string): Promise<{
86
+ root: string;
87
+ cleanup: () => void;
88
+ }>;
89
+ /** What a copy produced: files we wrote, and files we refused to overwrite because the user
90
+ * wrote them (same path as a bundle file, but never managed by us). */
91
+ export type CopyResult = {
92
+ written: string[];
93
+ skipped: string[];
94
+ };
95
+ /**
96
+ * Recursively copy a directory. Never follows a symlink at the destination — it's replaced — so a
97
+ * planted link can't redirect a write outside the project.
98
+ *
99
+ * `isManaged` decides whether an EXISTING destination file may be overwritten. A file that is on
100
+ * disk but was never written by us is user-authored content that happens to share a bundle path:
101
+ * we leave it alone and report it, rather than silently destroying it.
102
+ */
103
+ export declare function copyDir(src: string, dest: string, isManaged?: (file: string) => boolean): CopyResult;
104
+ /**
105
+ * Copy the skills of every shipped plugin from the extracted repo into `SKILLS_DIR`.
106
+ *
107
+ * The same `FOREST_PLUGINS` the plugin route installs — one list, so the two routes cannot drift.
108
+ * A plugin with no `skills/` is simply skipped rather than rejected: `forest-docs` legitimately
109
+ * carries only an MCP config, which this route cannot wire anyway. What must not pass silently is a
110
+ * bundle carrying no skill at all, so that is what the guard checks — a marketplace whose layout
111
+ * moved under us.
112
+ *
113
+ * `previousFiles` is the file list from the previous manifest (`null` on a first run). It bounds
114
+ * what we may claim as managed AND what we may overwrite: a file we never wrote is the user's,
115
+ * both on the skip path (claiming it would let a later prune delete it) and on the force path
116
+ * (overwriting it would destroy it outright).
117
+ */
118
+ export declare function installSkills(srcRoot: string, force: boolean, previousFiles: string[] | null): CopyResult;
119
+ /** From a manifest file list, the entries that live under the skills dir (normalized for Windows,
120
+ * where manifest paths use backslashes). These are the candidates for stale-pruning on a refresh. */
121
+ export declare function skillDirEntries(files: string[]): string[];
122
+ /**
123
+ * Delete managed skill files that existed before but are no longer produced (removed upstream).
124
+ * Set-diff of previous vs current, deleting only paths that still exist *and* are safely contained
125
+ * within the skills dir. Returns what it removed.
126
+ */
127
+ export declare function removeStaleSkillFiles(previousFiles: string[], currentFiles: string[]): string[];
128
+ /** Merge a delimited Forest block into a context file (CLAUDE.md / AGENTS.md) without
129
+ * clobbering the user's own content. Creates the file if absent. */
130
+ export declare function mergeBlock(file: string, content: string): void;
131
+ /** True if the agent's CLI is installed and runnable. */
132
+ export declare function hasPluginCli(agent: PluginAgent): boolean;
133
+ /** The exact command that installs one Forest plugin, for a user retrying a failure by hand. */
134
+ export declare function pluginInstallCommand(agent: PluginAgent, plugin: string): string;
135
+ export type PluginInstallResult = {
136
+ agent: PluginAgent;
137
+ installed: string[];
138
+ failed: string[];
139
+ };
140
+ /**
141
+ * Register the Forest marketplace with the agent's CLI and install the Forest plugins.
142
+ * Throws when the marketplace cannot be added at all (nothing else can work); a single plugin
143
+ * that fails to install is reported, not fatal — the others are still worth having.
144
+ */
145
+ export declare function installPlugins(agent: PluginAgent, ref?: string): PluginInstallResult;
146
+ /**
147
+ * Refresh already-installed plugins (the plugin-route equivalent of re-copying files).
148
+ *
149
+ * Re-running `install` is not a refresh on Claude Code: it answers "already installed", exits 0 and
150
+ * fetches nothing. So its catalog is pulled first, then each plugin is installed (a no-op unless it
151
+ * was removed by hand) and updated. Codex keeps the re-install path.
152
+ */
153
+ export declare function upgradePlugins(agent: PluginAgent, ref?: string): PluginInstallResult;
154
+ /**
155
+ * Best-effort guess of which agents THIS REPO uses, so the prompt comes pre-checked and `--agent`
156
+ * stays optional in scripted runs. A missing signal is not an error: the user can always tick a
157
+ * box or pass the flag.
158
+ *
159
+ * Repo signals win over an installed binary, and deliberately so: a developer who has every agent
160
+ * CLI on their machine would otherwise get all of them pre-checked in every repo, and confirming
161
+ * the prompt would install plugins they never asked for. The PATH is consulted only when the repo
162
+ * says nothing at all — the fresh-project case (`npx create-forest`), where "what you have
163
+ * installed" is the only signal there is.
164
+ */
165
+ export declare function detectAgents(): Agent[];
166
+ /**
167
+ * The agents a manifest records. One with no `agents` predates the field, when only the copy route
168
+ * existed. An empty list is recorded, not missing: reading it as a copy install would copy skills
169
+ * nobody picked.
170
+ */
171
+ export declare function manifestAgents(manifest: Manifest): Agent[];
172
+ /**
173
+ * The ref each recorded agent's content was installed from. `ref` alone cannot say it: a run that
174
+ * adds one agent leaves the others' content where it was, at whatever ref they came from.
175
+ */
176
+ export declare function manifestRefs(manifest: Manifest): Record<string, string>;
177
+ /** Copy-route agents share one skills dir, so refreshing it moves every one of them to `ref`. */
178
+ export declare function refsAfter(previous: Record<string, string>, refreshed: Agent[], recorded: Agent[], ref: string): Record<string, string>;
179
+ export declare function readManifest(): Manifest | null;
180
+ export declare function writeManifest(manifest: Manifest): void;
181
+ //# sourceMappingURL=skills-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"skills-manager.d.ts","sourceRoot":"","sources":["../../../src/services/skills/skills-manager.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;;;GAgBG;AAEH,eAAO,MAAM,gBAAgB,+BAA+B,CAAC;AAC7D,eAAO,MAAM,gBAAgB,oBAAoB,CAAC;AAElD;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,UAA2C,CAAC;AAEvE;;;;;GAKG;AACH,eAAO,MAAM,UAAU,mBAAmB,CAAC;AAE3C,qDAAqD;AACrD,eAAO,MAAM,aAAa,8BAA+B,CAAC;AAC1D,+DAA+D;AAC/D,eAAO,MAAM,WAAW,0CAA2C,CAAC;AACpE,eAAO,MAAM,UAAU,6DAA8C,CAAC;AAEtE,MAAM,MAAM,WAAW,GAAG,CAAC,OAAO,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC;AACzD,MAAM,MAAM,KAAK,GAAG,CAAC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