@agentex/agent 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/instructions.d.ts +140 -0
- package/dist/utils/instructions.d.ts.map +1 -1
- package/dist/utils/instructions.js +248 -0
- package/dist/utils/instructions.js.map +1 -1
- package/dist/utils/runtime-homes.d.ts +4 -1
- package/dist/utils/runtime-homes.d.ts.map +1 -1
- package/dist/utils/runtime-homes.js +14 -10
- package/dist/utils/runtime-homes.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -693,6 +693,33 @@ await removeSkills(skillDirs, { location: "workspace", cwd: process.cwd() });
|
|
|
693
693
|
|
|
694
694
|
Channels and locations follow the emerging `.agents/skills/` + `.claude/skills/` convention — see the `SkillRuntime`, `SkillLocation`, and `SkillChannel` types.
|
|
695
695
|
|
|
696
|
+
### Install Instruction Files
|
|
697
|
+
|
|
698
|
+
`installInstructions` is the instruction-file twin of `installSkills`: it drops an orientation brief into the right per-runtime file(s), merging into a **managed region** so any content the user wrote outside the markers is preserved.
|
|
699
|
+
|
|
700
|
+
```typescript
|
|
701
|
+
import { installInstructions, removeInstructions } from "@agentex/agent";
|
|
702
|
+
|
|
703
|
+
// Workspace (repo-root) install — the common case.
|
|
704
|
+
// Writes the brief into {cwd}/CLAUDE.md and {cwd}/AGENTS.md (deduped by filename).
|
|
705
|
+
await installInstructions(brief, {
|
|
706
|
+
location: "workspace", // or "global"
|
|
707
|
+
cwd: process.cwd(), // required for workspace installs
|
|
708
|
+
includeNativeFiles: false, // true also writes Gemini's native GEMINI.md
|
|
709
|
+
managed: true, // wrap in markers + merge (default); false overwrites the file
|
|
710
|
+
managedTag: "agentex", // marker tag → <!-- agentex:managed:start -->
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
// Global install — per-runtime home files (~/.claude/CLAUDE.md, ~/.codex/AGENTS.md,
|
|
714
|
+
// ~/.gemini/GEMINI.md, ~/.config/opencode/AGENTS.md, ~/.pi/AGENTS.md).
|
|
715
|
+
await installInstructions(brief, { location: "global" });
|
|
716
|
+
|
|
717
|
+
// Remove only the managed region; user-authored content (and user-owned files) survive.
|
|
718
|
+
await removeInstructions({ location: "workspace", cwd: process.cwd() });
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
Every runtime except Claude reads `AGENTS.md`; Claude reads `CLAUDE.md`. Gemini reads `GEMINI.md` by default (only reads `AGENTS.md` when configured), so it gets a native escape hatch via `includeNativeFiles`. Re-installing unchanged content is idempotent (reported as `skipped`). Use `resolveInstructionTargets(opts)` to see which files *would* be written without touching disk, and `upsertManagedBlock` / `stripManagedBlock` for the low-level merge.
|
|
722
|
+
|
|
696
723
|
### Discover Slash-Invokable Skills
|
|
697
724
|
|
|
698
725
|
Use `discoverSkillCommands(...)` to parse local `SKILL.md` files into UI-ready descriptors. It reads frontmatter fields such as `description`, `argument-hint`, and `user-invocable`; if no description is present, it falls back to the first non-empty body paragraph.
|
|
@@ -901,6 +928,10 @@ registerProvider(myProvider);
|
|
|
901
928
|
- `renderTemplate(template, ctx)` — `{{var}}` interpolation.
|
|
902
929
|
- `redactEnvForLogs(env)` — redact sensitive values before logging.
|
|
903
930
|
- `resolveInstructions(path?)` — read an instructions file, or `null` if no path.
|
|
931
|
+
- `installInstructions(content, opts?)` / `removeInstructions(opts?)` — write/remove a managed instruction brief across per-runtime files (`CLAUDE.md` / `AGENTS.md` / native `GEMINI.md`), workspace or global.
|
|
932
|
+
- `resolveInstructionTargets(opts?)` — list which instruction files would be written, without touching disk.
|
|
933
|
+
- `upsertManagedBlock(existing, content, opts?)` / `stripManagedBlock(existing, opts?)` — low-level managed-region merge/strip (preserves content outside the markers).
|
|
934
|
+
- `getDefaultRuntimeHome(runtime, homeDir?)` — pass `homeDir` to resolve against a sandboxed base instead of `os.homedir()`.
|
|
904
935
|
- `parseAskUserQuestion(req)` — extract structured question/option data from a `UserInputRequest`.
|
|
905
936
|
- `parseExitPlanMode(req)` — extract the proposed plan text from an `ExitPlanMode` permission request (Claude plan mode).
|
|
906
937
|
|
package/dist/index.d.ts
CHANGED
|
@@ -11,7 +11,8 @@ export { redactEnvForLogs } from "./utils/env.js";
|
|
|
11
11
|
export { parseAskUserQuestion } from "./utils/ask-user-question.js";
|
|
12
12
|
export { parseExitPlanMode } from "./utils/exit-plan-mode.js";
|
|
13
13
|
export { aggregateUsage } from "./types.js";
|
|
14
|
-
export { resolveInstructions } from "./utils/instructions.js";
|
|
14
|
+
export { resolveInstructions, installInstructions, removeInstructions, resolveInstructionTargets, upsertManagedBlock, stripManagedBlock, } from "./utils/instructions.js";
|
|
15
|
+
export type { InstallInstructionsOptions, InstructionStatus, InstructionInstallEntry, InstructionInstallResult, InstructionTarget, RemoveInstructionsOptions, InstructionRemoveStatus, InstructionRemoveEntry, InstructionRemoveResult, ManagedBlockOptions, } from "./utils/instructions.js";
|
|
15
16
|
export { getRuntimeHomeEnvVar, getDefaultRuntimeHome } from "./utils/runtime-homes.js";
|
|
16
17
|
export { findBinary, ensureCommandResolvable, clearBinaryCache } from "./utils/binary.js";
|
|
17
18
|
export type { ResolvedBinary } from "./utils/binary.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YA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AAU,EACV,WAAW,EACX,YAAY,EACZ,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,eAAe,EACf,cAAc,EACd,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,YAAY,EACV,eAAe,EACf,cAAc,GACf,MAAM,8BAA8B,CAAC;AAEtC,YAAY,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,YAAY,EACV,YAAY,EACZ,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,sBAAsB,EACtB,4BAA4B,EAC5B,2BAA2B,EAC3B,6BAA6B,EAC7B,kBAAkB,GACnB,MAAM,2BAA2B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { redactEnvForLogs } from "./utils/env.js";
|
|
|
8
8
|
export { parseAskUserQuestion } from "./utils/ask-user-question.js";
|
|
9
9
|
export { parseExitPlanMode } from "./utils/exit-plan-mode.js";
|
|
10
10
|
export { aggregateUsage } from "./types.js";
|
|
11
|
-
export { resolveInstructions } from "./utils/instructions.js";
|
|
11
|
+
export { resolveInstructions, installInstructions, removeInstructions, resolveInstructionTargets, upsertManagedBlock, stripManagedBlock, } from "./utils/instructions.js";
|
|
12
12
|
export { getRuntimeHomeEnvVar, getDefaultRuntimeHome } from "./utils/runtime-homes.js";
|
|
13
13
|
export { findBinary, ensureCommandResolvable, clearBinaryCache } from "./utils/binary.js";
|
|
14
14
|
export { detectAuth, resolveAuthForProvider, clearAuthCache, hasSubscription, hasApiKey, hasBedrock, isLoggedIn, loginCommandFor, } from "./utils/auth.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY;AACZ,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,kBAAkB,EAClB,4BAA4B,GAC7B,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,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ACrB,sBAAsB,EACtB,qBAAqB,EACrB,WAAW,EACX,wBAAwB,GACzB,MAAM,2BAA2B,CAAC"}
|
|
@@ -1,7 +1,147 @@
|
|
|
1
|
+
import type { SkillRuntime, SkillLocation } from "./skills.js";
|
|
1
2
|
/**
|
|
2
3
|
* Read an instructions file and return its content.
|
|
3
4
|
* Returns null if no path is provided.
|
|
4
5
|
* Throws a clear error if the file doesn't exist.
|
|
5
6
|
*/
|
|
6
7
|
export declare function resolveInstructions(filePath?: string): Promise<string | null>;
|
|
8
|
+
export interface InstallInstructionsOptions {
|
|
9
|
+
/** Which runtimes to write instruction files for. Defaults to all known runtimes. */
|
|
10
|
+
runtimes?: SkillRuntime[];
|
|
11
|
+
/** "workspace" ({cwd}/) — default — or "global" (each runtime's home dir). */
|
|
12
|
+
location?: SkillLocation;
|
|
13
|
+
/** Working directory. Required for "workspace". */
|
|
14
|
+
cwd?: string;
|
|
15
|
+
/**
|
|
16
|
+
* Also write each runtime's native file when it differs from the shared
|
|
17
|
+
* standard (currently only Gemini's GEMINI.md). Only affects "workspace";
|
|
18
|
+
* "global" always uses native files. Default: false.
|
|
19
|
+
*/
|
|
20
|
+
includeNativeFiles?: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Wrap `content` in managed markers and merge into any existing file,
|
|
23
|
+
* replacing only the previously-managed region and preserving everything the
|
|
24
|
+
* user wrote outside it. Default: true. When false, the file is overwritten
|
|
25
|
+
* with raw `content` (escape hatch for fully-owned files).
|
|
26
|
+
*/
|
|
27
|
+
managed?: boolean;
|
|
28
|
+
/** Marker tag, so the comment reads `<!-- <tag>:managed:start -->`. Default: "agentex". */
|
|
29
|
+
managedTag?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Override the home-directory base for "global" installs (sandboxes / tests).
|
|
32
|
+
* Defaults to os.homedir().
|
|
33
|
+
*/
|
|
34
|
+
homeDir?: string;
|
|
35
|
+
}
|
|
36
|
+
export type InstructionStatus = "created" | "updated" | "skipped" | "error";
|
|
37
|
+
export interface InstructionInstallEntry {
|
|
38
|
+
/** The filename written, e.g. "AGENTS.md", "CLAUDE.md", "GEMINI.md". */
|
|
39
|
+
filename: string;
|
|
40
|
+
/** Absolute path written. */
|
|
41
|
+
targetPath: string;
|
|
42
|
+
/** Which requested runtimes this file serves. */
|
|
43
|
+
runtimes: SkillRuntime[];
|
|
44
|
+
status: InstructionStatus;
|
|
45
|
+
error?: string;
|
|
46
|
+
}
|
|
47
|
+
export interface InstructionInstallResult {
|
|
48
|
+
entries: InstructionInstallEntry[];
|
|
49
|
+
installed: number;
|
|
50
|
+
updated: number;
|
|
51
|
+
skipped: number;
|
|
52
|
+
errors: number;
|
|
53
|
+
}
|
|
54
|
+
export interface InstructionTarget {
|
|
55
|
+
filename: string;
|
|
56
|
+
targetPath: string;
|
|
57
|
+
runtimes: SkillRuntime[];
|
|
58
|
+
}
|
|
59
|
+
export interface RemoveInstructionsOptions {
|
|
60
|
+
runtimes?: SkillRuntime[];
|
|
61
|
+
location?: SkillLocation;
|
|
62
|
+
cwd?: string;
|
|
63
|
+
/** Marker tag whose managed region should be removed. Default: "agentex". */
|
|
64
|
+
managedTag?: string;
|
|
65
|
+
homeDir?: string;
|
|
66
|
+
}
|
|
67
|
+
export type InstructionRemoveStatus = "removed" | "not_found" | "skipped" | "error";
|
|
68
|
+
export interface InstructionRemoveEntry {
|
|
69
|
+
filename: string;
|
|
70
|
+
targetPath: string;
|
|
71
|
+
runtimes: SkillRuntime[];
|
|
72
|
+
status: InstructionRemoveStatus;
|
|
73
|
+
error?: string;
|
|
74
|
+
}
|
|
75
|
+
export interface InstructionRemoveResult {
|
|
76
|
+
entries: InstructionRemoveEntry[];
|
|
77
|
+
removed: number;
|
|
78
|
+
}
|
|
79
|
+
export interface ManagedBlockOptions {
|
|
80
|
+
/** Marker tag. Default: "agentex". */
|
|
81
|
+
tag?: string;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Resolve which instruction files would be written for the given options,
|
|
85
|
+
* without touching disk.
|
|
86
|
+
*
|
|
87
|
+
* - "workspace": files dedupe by name under {cwd}/ (the default writes
|
|
88
|
+
* CLAUDE.md + AGENTS.md once each). `includeNativeFiles` adds GEMINI.md.
|
|
89
|
+
* - "global": one file per runtime in each runtime's home dir. Runtimes without
|
|
90
|
+
* a file-based global config (Cursor) are omitted.
|
|
91
|
+
*/
|
|
92
|
+
export declare function resolveInstructionTargets(options?: {
|
|
93
|
+
runtimes?: SkillRuntime[];
|
|
94
|
+
location?: SkillLocation;
|
|
95
|
+
cwd?: string;
|
|
96
|
+
includeNativeFiles?: boolean;
|
|
97
|
+
homeDir?: string;
|
|
98
|
+
}): InstructionTarget[];
|
|
99
|
+
/**
|
|
100
|
+
* Install an instruction brief into the right per-runtime files.
|
|
101
|
+
*
|
|
102
|
+
* By default merges `content` into a managed region of `{cwd}/CLAUDE.md` and
|
|
103
|
+
* `{cwd}/AGENTS.md`, preserving any user-authored content outside the markers.
|
|
104
|
+
* Idempotent: a re-install with unchanged content reports every entry as
|
|
105
|
+
* "skipped".
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* // Workspace (repo-root) install — the common case.
|
|
110
|
+
* await installInstructions(brief, { location: "workspace", cwd: projectDir });
|
|
111
|
+
* // → {cwd}/CLAUDE.md + {cwd}/AGENTS.md
|
|
112
|
+
*
|
|
113
|
+
* // Also drop Gemini's native GEMINI.md (it doesn't read AGENTS.md by default).
|
|
114
|
+
* await installInstructions(brief, { location: "workspace", cwd, includeNativeFiles: true });
|
|
115
|
+
*
|
|
116
|
+
* // Global install — per-runtime home files.
|
|
117
|
+
* await installInstructions(brief, { location: "global" });
|
|
118
|
+
* // → ~/.claude/CLAUDE.md, ~/.codex/AGENTS.md, ~/.gemini/GEMINI.md, ...
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
export declare function installInstructions(content: string, options?: InstallInstructionsOptions): Promise<InstructionInstallResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Remove the managed region installed by {@link installInstructions}, preserving
|
|
124
|
+
* any user-authored content outside the markers. If the file contains nothing
|
|
125
|
+
* but the managed block, it is deleted. User-owned files (no managed region) are
|
|
126
|
+
* left untouched and reported as "skipped".
|
|
127
|
+
*/
|
|
128
|
+
export declare function removeInstructions(options?: RemoveInstructionsOptions): Promise<InstructionRemoveResult>;
|
|
129
|
+
/**
|
|
130
|
+
* Merge `content` into `existing` as a managed region, preserving everything the
|
|
131
|
+
* user wrote outside the markers.
|
|
132
|
+
*
|
|
133
|
+
* - `existing` has a managed region → replace only the bytes between the markers.
|
|
134
|
+
* - `existing` has no markers → prepend the managed block, keep prior content below.
|
|
135
|
+
* - `existing` is null/empty → return just the managed block.
|
|
136
|
+
*
|
|
137
|
+
* The start marker embeds a short content hash, so re-running with identical
|
|
138
|
+
* content produces a byte-identical result (enabling cheap skip detection).
|
|
139
|
+
*/
|
|
140
|
+
export declare function upsertManagedBlock(existing: string | null, content: string, options?: ManagedBlockOptions): string;
|
|
141
|
+
/**
|
|
142
|
+
* Remove the managed region (if any) from `existing`, preserving user content.
|
|
143
|
+
* Returns the cleaned string, the original string if there was no managed
|
|
144
|
+
* region, or null if nothing but the managed block remained.
|
|
145
|
+
*/
|
|
146
|
+
export declare function stripManagedBlock(existing: string, options?: ManagedBlockOptions): string | null;
|
|
7
147
|
//# sourceMappingURL=instructions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/utils/instructions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instructions.d.ts","sourceRoot":"","sources":["../../src/utils/instructions.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG/D;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAWnF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ED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI,CAOhG"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import * as fs from "node:fs/promises";
|
|
2
|
+
import * as path from "node:path";
|
|
3
|
+
import { createHash } from "node:crypto";
|
|
4
|
+
import { getDefaultRuntimeHome } from "./runtime-homes.js";
|
|
2
5
|
/**
|
|
3
6
|
* Read an instructions file and return its content.
|
|
4
7
|
* Returns null if no path is provided.
|
|
@@ -18,4 +21,249 @@ export async function resolveInstructions(filePath) {
|
|
|
18
21
|
throw err;
|
|
19
22
|
}
|
|
20
23
|
}
|
|
24
|
+
const RUNTIME_INSTRUCTIONS = {
|
|
25
|
+
claude: { projectFile: "CLAUDE.md", nativeFile: "CLAUDE.md", hasGlobalFile: true },
|
|
26
|
+
codex: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", hasGlobalFile: true },
|
|
27
|
+
opencode: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", hasGlobalFile: true },
|
|
28
|
+
gemini: { projectFile: "AGENTS.md", nativeFile: "GEMINI.md", hasGlobalFile: true },
|
|
29
|
+
cursor: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", hasGlobalFile: false },
|
|
30
|
+
pi: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", hasGlobalFile: true },
|
|
31
|
+
};
|
|
32
|
+
const ALL_RUNTIMES = ["claude", "codex", "gemini", "cursor", "opencode", "pi"];
|
|
33
|
+
const DEFAULT_MANAGED_TAG = "agentex";
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Path resolution
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
/**
|
|
38
|
+
* Resolve which instruction files would be written for the given options,
|
|
39
|
+
* without touching disk.
|
|
40
|
+
*
|
|
41
|
+
* - "workspace": files dedupe by name under {cwd}/ (the default writes
|
|
42
|
+
* CLAUDE.md + AGENTS.md once each). `includeNativeFiles` adds GEMINI.md.
|
|
43
|
+
* - "global": one file per runtime in each runtime's home dir. Runtimes without
|
|
44
|
+
* a file-based global config (Cursor) are omitted.
|
|
45
|
+
*/
|
|
46
|
+
export function resolveInstructionTargets(options) {
|
|
47
|
+
const location = options?.location ?? "workspace";
|
|
48
|
+
const runtimes = dedupeRuntimes(options?.runtimes ?? ALL_RUNTIMES);
|
|
49
|
+
if (location === "workspace") {
|
|
50
|
+
const cwd = options?.cwd;
|
|
51
|
+
if (!cwd)
|
|
52
|
+
throw new Error("cwd is required when location is 'workspace'");
|
|
53
|
+
const byFile = new Map();
|
|
54
|
+
const add = (filename, runtime) => {
|
|
55
|
+
const list = byFile.get(filename) ?? [];
|
|
56
|
+
list.push(runtime);
|
|
57
|
+
byFile.set(filename, list);
|
|
58
|
+
};
|
|
59
|
+
for (const runtime of runtimes) {
|
|
60
|
+
const spec = RUNTIME_INSTRUCTIONS[runtime];
|
|
61
|
+
add(spec.projectFile, runtime);
|
|
62
|
+
if (options?.includeNativeFiles && spec.nativeFile !== spec.projectFile) {
|
|
63
|
+
add(spec.nativeFile, runtime);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return [...byFile.entries()].map(([filename, rts]) => ({
|
|
67
|
+
filename,
|
|
68
|
+
targetPath: path.join(cwd, filename),
|
|
69
|
+
runtimes: dedupeRuntimes(rts),
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
// global: each runtime reads its own native file in its own home dir.
|
|
73
|
+
const targets = [];
|
|
74
|
+
for (const runtime of runtimes) {
|
|
75
|
+
const spec = RUNTIME_INSTRUCTIONS[runtime];
|
|
76
|
+
if (!spec.hasGlobalFile)
|
|
77
|
+
continue; // e.g. cursor global = app User Rules, not a file
|
|
78
|
+
const home = getDefaultRuntimeHome(runtime, options?.homeDir);
|
|
79
|
+
targets.push({
|
|
80
|
+
filename: spec.nativeFile,
|
|
81
|
+
targetPath: path.join(home, spec.nativeFile),
|
|
82
|
+
runtimes: [runtime],
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return targets;
|
|
86
|
+
}
|
|
87
|
+
function dedupeRuntimes(runtimes) {
|
|
88
|
+
return [...new Set(runtimes)];
|
|
89
|
+
}
|
|
90
|
+
// ---------------------------------------------------------------------------
|
|
91
|
+
// Public API
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
/**
|
|
94
|
+
* Install an instruction brief into the right per-runtime files.
|
|
95
|
+
*
|
|
96
|
+
* By default merges `content` into a managed region of `{cwd}/CLAUDE.md` and
|
|
97
|
+
* `{cwd}/AGENTS.md`, preserving any user-authored content outside the markers.
|
|
98
|
+
* Idempotent: a re-install with unchanged content reports every entry as
|
|
99
|
+
* "skipped".
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* // Workspace (repo-root) install — the common case.
|
|
104
|
+
* await installInstructions(brief, { location: "workspace", cwd: projectDir });
|
|
105
|
+
* // → {cwd}/CLAUDE.md + {cwd}/AGENTS.md
|
|
106
|
+
*
|
|
107
|
+
* // Also drop Gemini's native GEMINI.md (it doesn't read AGENTS.md by default).
|
|
108
|
+
* await installInstructions(brief, { location: "workspace", cwd, includeNativeFiles: true });
|
|
109
|
+
*
|
|
110
|
+
* // Global install — per-runtime home files.
|
|
111
|
+
* await installInstructions(brief, { location: "global" });
|
|
112
|
+
* // → ~/.claude/CLAUDE.md, ~/.codex/AGENTS.md, ~/.gemini/GEMINI.md, ...
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
export async function installInstructions(content, options) {
|
|
116
|
+
const managed = options?.managed ?? true;
|
|
117
|
+
const tag = options?.managedTag ?? DEFAULT_MANAGED_TAG;
|
|
118
|
+
const targets = resolveInstructionTargets(options);
|
|
119
|
+
const entries = [];
|
|
120
|
+
for (const target of targets) {
|
|
121
|
+
try {
|
|
122
|
+
const existing = await readFileOrNull(target.targetPath);
|
|
123
|
+
const next = managed
|
|
124
|
+
? upsertManagedBlock(existing, content, { tag })
|
|
125
|
+
: ensureTrailingNewline(content);
|
|
126
|
+
let status;
|
|
127
|
+
if (existing === null) {
|
|
128
|
+
status = "created";
|
|
129
|
+
}
|
|
130
|
+
else if (existing === next) {
|
|
131
|
+
status = "skipped";
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
status = "updated";
|
|
135
|
+
}
|
|
136
|
+
if (status !== "skipped") {
|
|
137
|
+
await fs.mkdir(path.dirname(target.targetPath), { recursive: true });
|
|
138
|
+
await fs.writeFile(target.targetPath, next, { mode: 0o644 });
|
|
139
|
+
}
|
|
140
|
+
entries.push({ ...target, status });
|
|
141
|
+
}
|
|
142
|
+
catch (err) {
|
|
143
|
+
entries.push({
|
|
144
|
+
...target,
|
|
145
|
+
status: "error",
|
|
146
|
+
error: err instanceof Error ? err.message : String(err),
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
entries,
|
|
152
|
+
installed: entries.filter((e) => e.status === "created").length,
|
|
153
|
+
updated: entries.filter((e) => e.status === "updated").length,
|
|
154
|
+
skipped: entries.filter((e) => e.status === "skipped").length,
|
|
155
|
+
errors: entries.filter((e) => e.status === "error").length,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Remove the managed region installed by {@link installInstructions}, preserving
|
|
160
|
+
* any user-authored content outside the markers. If the file contains nothing
|
|
161
|
+
* but the managed block, it is deleted. User-owned files (no managed region) are
|
|
162
|
+
* left untouched and reported as "skipped".
|
|
163
|
+
*/
|
|
164
|
+
export async function removeInstructions(options) {
|
|
165
|
+
const tag = options?.managedTag ?? DEFAULT_MANAGED_TAG;
|
|
166
|
+
const targets = resolveInstructionTargets({
|
|
167
|
+
runtimes: options?.runtimes,
|
|
168
|
+
location: options?.location,
|
|
169
|
+
cwd: options?.cwd,
|
|
170
|
+
homeDir: options?.homeDir,
|
|
171
|
+
});
|
|
172
|
+
const entries = [];
|
|
173
|
+
for (const target of targets) {
|
|
174
|
+
try {
|
|
175
|
+
const existing = await readFileOrNull(target.targetPath);
|
|
176
|
+
if (existing === null) {
|
|
177
|
+
entries.push({ ...target, status: "not_found" });
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const stripped = stripManagedBlock(existing, { tag });
|
|
181
|
+
if (stripped === existing) {
|
|
182
|
+
// No managed region present — never touch user-owned files.
|
|
183
|
+
entries.push({ ...target, status: "skipped" });
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if (stripped === null) {
|
|
187
|
+
await fs.rm(target.targetPath, { force: true });
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
await fs.writeFile(target.targetPath, stripped, { mode: 0o644 });
|
|
191
|
+
}
|
|
192
|
+
entries.push({ ...target, status: "removed" });
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
entries.push({
|
|
196
|
+
...target,
|
|
197
|
+
status: "error",
|
|
198
|
+
error: err instanceof Error ? err.message : String(err),
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return { entries, removed: entries.filter((e) => e.status === "removed").length };
|
|
203
|
+
}
|
|
204
|
+
// ---------------------------------------------------------------------------
|
|
205
|
+
// Managed-region merge (exported for low-level use / hosts with custom layouts)
|
|
206
|
+
// ---------------------------------------------------------------------------
|
|
207
|
+
/**
|
|
208
|
+
* Merge `content` into `existing` as a managed region, preserving everything the
|
|
209
|
+
* user wrote outside the markers.
|
|
210
|
+
*
|
|
211
|
+
* - `existing` has a managed region → replace only the bytes between the markers.
|
|
212
|
+
* - `existing` has no markers → prepend the managed block, keep prior content below.
|
|
213
|
+
* - `existing` is null/empty → return just the managed block.
|
|
214
|
+
*
|
|
215
|
+
* The start marker embeds a short content hash, so re-running with identical
|
|
216
|
+
* content produces a byte-identical result (enabling cheap skip detection).
|
|
217
|
+
*/
|
|
218
|
+
export function upsertManagedBlock(existing, content, options) {
|
|
219
|
+
const tag = options?.tag ?? DEFAULT_MANAGED_TAG;
|
|
220
|
+
const block = buildManagedBlock(content, tag);
|
|
221
|
+
if (existing === null || existing.length === 0) {
|
|
222
|
+
return `${block}\n`;
|
|
223
|
+
}
|
|
224
|
+
const re = managedBlockRegex(tag);
|
|
225
|
+
if (re.test(existing)) {
|
|
226
|
+
return existing.replace(re, block);
|
|
227
|
+
}
|
|
228
|
+
// No managed region yet — prepend it, keep the user's file below.
|
|
229
|
+
return `${block}\n\n${existing.replace(/^\n+/, "")}`;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Remove the managed region (if any) from `existing`, preserving user content.
|
|
233
|
+
* Returns the cleaned string, the original string if there was no managed
|
|
234
|
+
* region, or null if nothing but the managed block remained.
|
|
235
|
+
*/
|
|
236
|
+
export function stripManagedBlock(existing, options) {
|
|
237
|
+
const tag = options?.tag ?? DEFAULT_MANAGED_TAG;
|
|
238
|
+
const re = managedBlockRegex(tag);
|
|
239
|
+
if (!re.test(existing))
|
|
240
|
+
return existing;
|
|
241
|
+
const stripped = existing.replace(re, "").replace(/^\n+/, "");
|
|
242
|
+
return stripped.trim().length === 0 ? null : stripped;
|
|
243
|
+
}
|
|
244
|
+
function buildManagedBlock(content, tag) {
|
|
245
|
+
const body = content.replace(/\s+$/, "");
|
|
246
|
+
const hash = createHash("sha256").update(body).digest("hex").slice(0, 12);
|
|
247
|
+
return `<!-- ${tag}:managed:start hash=${hash} -->\n${body}\n<!-- ${tag}:managed:end -->`;
|
|
248
|
+
}
|
|
249
|
+
function managedBlockRegex(tag) {
|
|
250
|
+
const t = escapeRegExp(tag);
|
|
251
|
+
return new RegExp(`<!--\\s*${t}:managed:start[^>]*-->[\\s\\S]*?<!--\\s*${t}:managed:end\\s*-->`);
|
|
252
|
+
}
|
|
253
|
+
function escapeRegExp(s) {
|
|
254
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
255
|
+
}
|
|
256
|
+
function ensureTrailingNewline(s) {
|
|
257
|
+
return s.endsWith("\n") ? s : `${s}\n`;
|
|
258
|
+
}
|
|
259
|
+
async function readFileOrNull(filePath) {
|
|
260
|
+
try {
|
|
261
|
+
return await fs.readFile(filePath, "utf-8");
|
|
262
|
+
}
|
|
263
|
+
catch (err) {
|
|
264
|
+
if (err.code === "ENOENT")
|
|
265
|
+
return null;
|
|
266
|
+
throw err;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
21
269
|
//# sourceMappingURL=instructions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/utils/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"instructions.js","sourceRoot":"","sources":["../../src/utils/instructions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAE3D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,QAAiB;IACzD,IAAI,CAAC,QAAQ;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,GAAI,GAA6B,CAAC,IAAI,CAAC;QACjD,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,gCAAgC,QAAQ,EAAE,CAAC,CAAC;QAC9D,CAAC;QACD,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC;AAoCD,MAAM,oBAAoB,GAAiD;IAC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C,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;AACzC,CAAC;AAED,KAAK,UAAU,cAAc,CAAC,QAAgB;IAC5C,IAAI,CAAC;QACH,OAAO,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,IAAK,GAA6B,CAAC,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAClE,MAAM,GAAG,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -8,6 +8,9 @@ import type { SkillRuntime } from "./skills.js";
|
|
|
8
8
|
export declare function getRuntimeHomeEnvVar(runtime: SkillRuntime): string | null;
|
|
9
9
|
/**
|
|
10
10
|
* Returns the default global home directory path for the given runtime.
|
|
11
|
+
*
|
|
12
|
+
* Pass `homeDir` to resolve against a base other than the user's real home
|
|
13
|
+
* directory (useful for sandboxed installs and tests). Defaults to os.homedir().
|
|
11
14
|
*/
|
|
12
|
-
export declare function getDefaultRuntimeHome(runtime: SkillRuntime): string;
|
|
15
|
+
export declare function getDefaultRuntimeHome(runtime: SkillRuntime, homeDir?: string): string;
|
|
13
16
|
//# sourceMappingURL=runtime-homes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-homes.d.ts","sourceRoot":"","sources":["../../src/utils/runtime-homes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA2BhD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAEzE;AAED
|
|
1
|
+
{"version":3,"file":"runtime-homes.d.ts","sourceRoot":"","sources":["../../src/utils/runtime-homes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AA2BhD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM,GAAG,IAAI,CAEzE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,YAAY,EAAE,OAAO,GAAE,MAAqB,GAAG,MAAM,CAGnG"}
|
|
@@ -13,15 +13,15 @@ const ENV_VAR_MAP = {
|
|
|
13
13
|
pi: "PI_HOME",
|
|
14
14
|
};
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* Home directory subpath (relative to the home base) for each runtime.
|
|
17
17
|
*/
|
|
18
|
-
const
|
|
19
|
-
claude:
|
|
20
|
-
codex:
|
|
21
|
-
gemini:
|
|
22
|
-
cursor:
|
|
23
|
-
opencode:
|
|
24
|
-
pi:
|
|
18
|
+
const HOME_SUBPATH_MAP = {
|
|
19
|
+
claude: [".claude"],
|
|
20
|
+
codex: [".codex"],
|
|
21
|
+
gemini: [".gemini"],
|
|
22
|
+
cursor: [".cursor"],
|
|
23
|
+
opencode: [".config", "opencode"],
|
|
24
|
+
pi: [".pi"],
|
|
25
25
|
};
|
|
26
26
|
/**
|
|
27
27
|
* Returns the environment variable name that overrides the global home
|
|
@@ -34,8 +34,12 @@ export function getRuntimeHomeEnvVar(runtime) {
|
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Returns the default global home directory path for the given runtime.
|
|
37
|
+
*
|
|
38
|
+
* Pass `homeDir` to resolve against a base other than the user's real home
|
|
39
|
+
* directory (useful for sandboxed installs and tests). Defaults to os.homedir().
|
|
37
40
|
*/
|
|
38
|
-
export function getDefaultRuntimeHome(runtime) {
|
|
39
|
-
|
|
41
|
+
export function getDefaultRuntimeHome(runtime, homeDir = os.homedir()) {
|
|
42
|
+
const subpath = HOME_SUBPATH_MAP[runtime] ?? [`.${runtime}`];
|
|
43
|
+
return path.join(homeDir, ...subpath);
|
|
40
44
|
}
|
|
41
45
|
//# sourceMappingURL=runtime-homes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime-homes.js","sourceRoot":"","sources":["../../src/utils/runtime-homes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAG9B;;;GAGG;AACH,MAAM,WAAW,GAAwC;IACvD,MAAM,EAAE,mBAAmB;IAC3B,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,mBAAmB;IAC3B,QAAQ,EAAE,iBAAiB,EAAG,8BAA8B;IAC5D,EAAE,EAAE,SAAS;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"runtime-homes.js","sourceRoot":"","sources":["../../src/utils/runtime-homes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAG9B;;;GAGG;AACH,MAAM,WAAW,GAAwC;IACvD,MAAM,EAAE,mBAAmB;IAC3B,KAAK,EAAE,YAAY;IACnB,MAAM,EAAE,mBAAmB;IAC3B,MAAM,EAAE,mBAAmB;IAC3B,QAAQ,EAAE,iBAAiB,EAAG,8BAA8B;IAC5D,EAAE,EAAE,SAAS;CACd,CAAC;AAEF;;GAEG;AACH,MAAM,gBAAgB,GAAmC;IACvD,MAAM,EAAE,CAAC,SAAS,CAAC;IACnB,KAAK,EAAE,CAAC,QAAQ,CAAC;IACjB,MAAM,EAAE,CAAC,SAAS,CAAC;IACnB,MAAM,EAAE,CAAC,SAAS,CAAC;IACnB,QAAQ,EAAE,CAAC,SAAS,EAAE,UAAU,CAAC;IACjC,EAAE,EAAE,CAAC,KAAK,CAAC;CACZ,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAqB;IACxD,OAAO,WAAW,CAAC,OAAO,CAAC,IAAI,IAAI,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,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