@agentex/agent 0.0.37 → 0.0.38
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 +19 -0
- package/README.md +9 -4
- package/dist/utils/instructions.d.ts +36 -12
- package/dist/utils/instructions.d.ts.map +1 -1
- package/dist/utils/instructions.js +104 -53
- package/dist/utils/instructions.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/instructions.ts +152 -64
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.38 — AGENTS.md is the workspace instruction file for every runtime
|
|
4
|
+
|
|
5
|
+
Claude Code reads `AGENTS.md` since 2.1.277, loaded exactly where `CLAUDE.md` would be, but only in a folder with no `CLAUDE.md`. A `CLAUDE.md`, a `CLAUDE.local.md`, or one in a parent folder hides `AGENTS.md` completely (verified against 2.1.281). Not yet on Bedrock, Vertex or Foundry.
|
|
6
|
+
|
|
7
|
+
### Changed (breaking)
|
|
8
|
+
|
|
9
|
+
- **`installInstructions` writes `AGENTS.md` only by default.** Claude's workspace file is now `AGENTS.md`, like every other runtime. `CLAUDE.md` is Claude's native file, written only with `includeNativeFiles: true`, and then as a one-line `@AGENTS.md` pointer in the managed region instead of a second copy of the brief. A copy would have made anything the user writes in `AGENTS.md` invisible to Claude. Opt in for Claude Code before 2.1.277 or on a third-party API provider. `includeNativeFiles` still writes Gemini's `GEMINI.md` as a copy.
|
|
10
|
+
- **An existing workspace `CLAUDE.md` is reconciled** whenever `claude` is among the runtimes and the opt-in is off, because it would hide `AGENTS.md`: one holding nothing but this installer's managed region (for example the full brief 0.0.37 and earlier wrote) is deleted, and one the user wrote keeps their content and gains `@AGENTS.md` in the managed region. `managed: false` leaves it alone.
|
|
11
|
+
- **`removeInstructions` always checks native files** (`CLAUDE.md`, `GEMINI.md`), so an opt-in install is fully removable. It still only strips the managed region.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- `InstructionStatus` gains `"removed"`, and `InstructionInstallResult` a `removed` count.
|
|
16
|
+
- `InstructionTarget.importsFile` marks a pointer file (`"AGENTS.md"` on an opt-in `CLAUDE.md`).
|
|
17
|
+
|
|
18
|
+
### Migration
|
|
19
|
+
|
|
20
|
+
A host that relied on the default `CLAUDE.md` gets `AGENTS.md` only. Nothing else is needed on Claude Code 2.1.277+ with first-party auth: the next install deletes the old managed-only `CLAUDE.md`. Elsewhere, pass `includeNativeFiles: true`.
|
|
21
|
+
|
|
3
22
|
## 0.0.37 — Turn liveness and background-task identity (Claude)
|
|
4
23
|
|
|
5
24
|
Claude Code starts turns by itself. When a background task finishes, the CLI
|
package/README.md
CHANGED
|
@@ -1041,11 +1041,11 @@ Channels and locations follow the emerging `.agents/skills/` + `.claude/skills/`
|
|
|
1041
1041
|
import { installInstructions, removeInstructions } from "@agentex/agent";
|
|
1042
1042
|
|
|
1043
1043
|
// Workspace (repo-root) install — the common case.
|
|
1044
|
-
// Writes the brief into {cwd}/
|
|
1044
|
+
// Writes the brief into {cwd}/AGENTS.md, which every runtime reads.
|
|
1045
1045
|
await installInstructions(brief, {
|
|
1046
1046
|
location: "workspace", // or "global"
|
|
1047
1047
|
cwd: process.cwd(), // required for workspace installs
|
|
1048
|
-
includeNativeFiles: false, // true also writes
|
|
1048
|
+
includeNativeFiles: false, // true also writes CLAUDE.md (an @AGENTS.md pointer) and GEMINI.md
|
|
1049
1049
|
managed: true, // wrap in markers + merge (default); false overwrites the file
|
|
1050
1050
|
managedTag: "agentex", // marker tag → <!-- agentex:managed:start -->
|
|
1051
1051
|
});
|
|
@@ -1058,7 +1058,12 @@ await installInstructions(brief, { location: "global" });
|
|
|
1058
1058
|
await removeInstructions({ location: "workspace", cwd: process.cwd() });
|
|
1059
1059
|
```
|
|
1060
1060
|
|
|
1061
|
-
Every runtime
|
|
1061
|
+
Every runtime reads `AGENTS.md` at a workspace root. Claude Code does since 2.1.277, but only where the folder has no `CLAUDE.md`: a `CLAUDE.md`, a `CLAUDE.local.md`, or one in a parent folder hides `AGENTS.md` completely. So a workspace `CLAUDE.md` is only ever a one-line `@AGENTS.md` pointer, never a second copy of the brief:
|
|
1062
|
+
|
|
1063
|
+
- `includeNativeFiles: true` writes the pointer. Use it for Claude Code before 2.1.277, or on Bedrock, Vertex or Foundry, where Claude doesn't read `AGENTS.md` on its own. It also writes Gemini's native `GEMINI.md` (a copy), since Gemini reads `AGENTS.md` only when configured.
|
|
1064
|
+
- With the opt-in off, an existing `CLAUDE.md` is reconciled whenever Claude is among the runtimes: one holding nothing but the managed region is removed (reported `removed`), and one the user wrote gets `@AGENTS.md` in its managed region, so the brief still reaches Claude.
|
|
1065
|
+
|
|
1066
|
+
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.
|
|
1062
1067
|
|
|
1063
1068
|
### Discover Slash-Invokable Skills
|
|
1064
1069
|
|
|
@@ -1268,7 +1273,7 @@ registerProvider(myProvider);
|
|
|
1268
1273
|
- `renderTemplate(template, ctx)` — `{{var}}` interpolation.
|
|
1269
1274
|
- `redactEnvForLogs(env)` — redact sensitive values before logging.
|
|
1270
1275
|
- `resolveInstructions(path?)` — read an instructions file, or `null` if no path.
|
|
1271
|
-
- `installInstructions(content, opts?)` / `removeInstructions(opts?)` — write/remove a managed instruction brief across per-runtime files (`
|
|
1276
|
+
- `installInstructions(content, opts?)` / `removeInstructions(opts?)` — write/remove a managed instruction brief across per-runtime files (`AGENTS.md`, plus opt-in native `CLAUDE.md` pointer / `GEMINI.md`), workspace or global.
|
|
1272
1277
|
- `resolveInstructionTargets(opts?)` — list which instruction files would be written, without touching disk.
|
|
1273
1278
|
- `upsertManagedBlock(existing, content, opts?)` / `stripManagedBlock(existing, opts?)` — low-level managed-region merge/strip (preserves content outside the markers).
|
|
1274
1279
|
- `getDefaultRuntimeHome(runtime, homeDir?)` — pass `homeDir` to resolve against a sandboxed base instead of `os.homedir()`.
|
|
@@ -14,15 +14,20 @@ export interface InstallInstructionsOptions {
|
|
|
14
14
|
cwd?: string;
|
|
15
15
|
/**
|
|
16
16
|
* Also write each runtime's native file when it differs from the shared
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* AGENTS.md: Claude's CLAUDE.md (as a one-line `@AGENTS.md` pointer) and
|
|
18
|
+
* Gemini's GEMINI.md (as a copy). Only affects "workspace"; "global" always
|
|
19
|
+
* uses native files. Default: false.
|
|
20
|
+
*
|
|
21
|
+
* Opt in for Claude Code before 2.1.277, or on Bedrock, Vertex or Foundry,
|
|
22
|
+
* where Claude doesn't read AGENTS.md on its own.
|
|
19
23
|
*/
|
|
20
24
|
includeNativeFiles?: boolean;
|
|
21
25
|
/**
|
|
22
26
|
* Wrap `content` in managed markers and merge into any existing file,
|
|
23
27
|
* replacing only the previously-managed region and preserving everything the
|
|
24
28
|
* user wrote outside it. Default: true. When false, the file is overwritten
|
|
25
|
-
* with raw `content` (escape hatch for fully-owned files)
|
|
29
|
+
* with raw `content` (escape hatch for fully-owned files), and an existing
|
|
30
|
+
* CLAUDE.md is left alone even though it hides AGENTS.md from Claude Code.
|
|
26
31
|
*/
|
|
27
32
|
managed?: boolean;
|
|
28
33
|
/** Marker tag, so the comment reads `<!-- <tag>:managed:start -->`. Default: "agentex". */
|
|
@@ -33,7 +38,11 @@ export interface InstallInstructionsOptions {
|
|
|
33
38
|
*/
|
|
34
39
|
homeDir?: string;
|
|
35
40
|
}
|
|
36
|
-
|
|
41
|
+
/**
|
|
42
|
+
* "removed": a workspace CLAUDE.md that held nothing but this installer's
|
|
43
|
+
* managed region, deleted because the opt-in (`includeNativeFiles`) is off.
|
|
44
|
+
*/
|
|
45
|
+
export type InstructionStatus = "created" | "updated" | "skipped" | "removed" | "error";
|
|
37
46
|
export interface InstructionInstallEntry {
|
|
38
47
|
/** The filename written, e.g. "AGENTS.md", "CLAUDE.md", "GEMINI.md". */
|
|
39
48
|
filename: string;
|
|
@@ -41,6 +50,8 @@ export interface InstructionInstallEntry {
|
|
|
41
50
|
targetPath: string;
|
|
42
51
|
/** Which requested runtimes this file serves. */
|
|
43
52
|
runtimes: SkillRuntime[];
|
|
53
|
+
/** Set when the file is a pointer: its managed region is `@<importsFile>`, not the brief. */
|
|
54
|
+
importsFile?: string;
|
|
44
55
|
status: InstructionStatus;
|
|
45
56
|
error?: string;
|
|
46
57
|
}
|
|
@@ -49,12 +60,15 @@ export interface InstructionInstallResult {
|
|
|
49
60
|
installed: number;
|
|
50
61
|
updated: number;
|
|
51
62
|
skipped: number;
|
|
63
|
+
removed: number;
|
|
52
64
|
errors: number;
|
|
53
65
|
}
|
|
54
66
|
export interface InstructionTarget {
|
|
55
67
|
filename: string;
|
|
56
68
|
targetPath: string;
|
|
57
69
|
runtimes: SkillRuntime[];
|
|
70
|
+
/** Set when the file is a pointer: its managed region is `@<importsFile>`, not the brief. */
|
|
71
|
+
importsFile?: string;
|
|
58
72
|
}
|
|
59
73
|
export interface RemoveInstructionsOptions {
|
|
60
74
|
runtimes?: SkillRuntime[];
|
|
@@ -85,7 +99,8 @@ export interface ManagedBlockOptions {
|
|
|
85
99
|
* without touching disk.
|
|
86
100
|
*
|
|
87
101
|
* - "workspace": files dedupe by name under {cwd}/ (the default writes
|
|
88
|
-
*
|
|
102
|
+
* AGENTS.md once). `includeNativeFiles` adds CLAUDE.md (a pointer, marked by
|
|
103
|
+
* `importsFile`) and GEMINI.md.
|
|
89
104
|
* - "global": one file per runtime in each runtime's home dir. Runtimes without
|
|
90
105
|
* a file-based global config (Cursor) are omitted.
|
|
91
106
|
*/
|
|
@@ -99,18 +114,25 @@ export declare function resolveInstructionTargets(options?: {
|
|
|
99
114
|
/**
|
|
100
115
|
* Install an instruction brief into the right per-runtime files.
|
|
101
116
|
*
|
|
102
|
-
* By default merges `content` into a managed region of `{cwd}/
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
117
|
+
* By default merges `content` into a managed region of `{cwd}/AGENTS.md`,
|
|
118
|
+
* preserving any user-authored content outside the markers. Idempotent: a
|
|
119
|
+
* re-install with unchanged content reports every entry as "skipped".
|
|
120
|
+
*
|
|
121
|
+
* When Claude is among the runtimes, a `{cwd}/CLAUDE.md` already on disk is
|
|
122
|
+
* reconciled, because it would hide AGENTS.md from Claude Code: one holding
|
|
123
|
+
* nothing but this installer's managed region is removed, and one the user
|
|
124
|
+
* wrote gets `@AGENTS.md` in its managed region. With `includeNativeFiles`,
|
|
125
|
+
* CLAUDE.md is written as that pointer either way. `managed: false` leaves an
|
|
126
|
+
* existing CLAUDE.md alone.
|
|
106
127
|
*
|
|
107
128
|
* @example
|
|
108
129
|
* ```ts
|
|
109
130
|
* // Workspace (repo-root) install — the common case.
|
|
110
131
|
* await installInstructions(brief, { location: "workspace", cwd: projectDir });
|
|
111
|
-
* // → {cwd}/
|
|
132
|
+
* // → {cwd}/AGENTS.md
|
|
112
133
|
*
|
|
113
|
-
* // Also
|
|
134
|
+
* // Also write the native files: CLAUDE.md as an `@AGENTS.md` pointer (for
|
|
135
|
+
* // Claude Code before 2.1.277, or on Bedrock/Vertex/Foundry) and GEMINI.md.
|
|
114
136
|
* await installInstructions(brief, { location: "workspace", cwd, includeNativeFiles: true });
|
|
115
137
|
*
|
|
116
138
|
* // Global install — per-runtime home files.
|
|
@@ -123,7 +145,9 @@ export declare function installInstructions(content: string, options?: InstallIn
|
|
|
123
145
|
* Remove the managed region installed by {@link installInstructions}, preserving
|
|
124
146
|
* any user-authored content outside the markers. If the file contains nothing
|
|
125
147
|
* but the managed block, it is deleted. User-owned files (no managed region) are
|
|
126
|
-
* left untouched and reported as "skipped".
|
|
148
|
+
* left untouched and reported as "skipped". Native files (CLAUDE.md, GEMINI.md)
|
|
149
|
+
* are always checked, whether or not they were installed with
|
|
150
|
+
* `includeNativeFiles`.
|
|
127
151
|
*/
|
|
128
152
|
export declare function removeInstructions(options?: RemoveInstructionsOptions): Promise<InstructionRemoveResult>;
|
|
129
153
|
/**
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAiED,MAAM,WAAW,0BAA0B;IACzC,qFAAqF;IACrF,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,mDAAmD;IACnD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;;;;;;OAQG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,2FAA2F;IAC3F,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAExF,MAAM,WAAW,uBAAuB;IACtC,wEAAwE;IACxE,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB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IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAMD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,CAAC,EAAE;IAClD,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;IAC1B,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GAAG,iBAAiB,EAAE,CA4CtB;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,0BAA0B,GACnC,OAAO,CAAC,wBAAwB,CAAC,CAwBnC;AAoED;;;;;;;GAOG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,CAAC,EAAE,yBAAyB,GAClC,OAAO,CAAC,uBAAuB,CAAC,CA0ClC;AAMD;;;;;;;;;;GAUG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,GAAG,IAAI,EACvB,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,mBAAmB,GAC5B,MAAM,CAeR;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,GAAG,IAAI,CAOhG"}
|
|
@@ -22,12 +22,12 @@ export async function resolveInstructions(filePath) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
const RUNTIME_INSTRUCTIONS = {
|
|
25
|
-
claude: { projectFile: "
|
|
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 },
|
|
25
|
+
claude: { projectFile: "AGENTS.md", nativeFile: "CLAUDE.md", nativeFileMode: "pointer", hasGlobalFile: true },
|
|
26
|
+
codex: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", nativeFileMode: "copy", hasGlobalFile: true },
|
|
27
|
+
opencode: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", nativeFileMode: "copy", hasGlobalFile: true },
|
|
28
|
+
gemini: { projectFile: "AGENTS.md", nativeFile: "GEMINI.md", nativeFileMode: "copy", hasGlobalFile: true },
|
|
29
|
+
cursor: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", nativeFileMode: "copy", hasGlobalFile: false },
|
|
30
|
+
pi: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", nativeFileMode: "copy", hasGlobalFile: true },
|
|
31
31
|
};
|
|
32
32
|
const ALL_RUNTIMES = ["claude", "codex", "gemini", "cursor", "opencode", "pi"];
|
|
33
33
|
const DEFAULT_MANAGED_TAG = "agentex";
|
|
@@ -39,7 +39,8 @@ const DEFAULT_MANAGED_TAG = "agentex";
|
|
|
39
39
|
* without touching disk.
|
|
40
40
|
*
|
|
41
41
|
* - "workspace": files dedupe by name under {cwd}/ (the default writes
|
|
42
|
-
*
|
|
42
|
+
* AGENTS.md once). `includeNativeFiles` adds CLAUDE.md (a pointer, marked by
|
|
43
|
+
* `importsFile`) and GEMINI.md.
|
|
43
44
|
* - "global": one file per runtime in each runtime's home dir. Runtimes without
|
|
44
45
|
* a file-based global config (Cursor) are omitted.
|
|
45
46
|
*/
|
|
@@ -51,23 +52,24 @@ export function resolveInstructionTargets(options) {
|
|
|
51
52
|
if (!cwd)
|
|
52
53
|
throw new Error("cwd is required when location is 'workspace'");
|
|
53
54
|
const byFile = new Map();
|
|
54
|
-
const add = (filename, runtime) => {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const add = (filename, runtime, importsFile) => {
|
|
56
|
+
const target = byFile.get(filename) ?? {
|
|
57
|
+
filename,
|
|
58
|
+
targetPath: path.join(cwd, filename),
|
|
59
|
+
runtimes: [],
|
|
60
|
+
...(importsFile !== undefined && { importsFile }),
|
|
61
|
+
};
|
|
62
|
+
target.runtimes.push(runtime);
|
|
63
|
+
byFile.set(filename, target);
|
|
58
64
|
};
|
|
59
65
|
for (const runtime of runtimes) {
|
|
60
66
|
const spec = RUNTIME_INSTRUCTIONS[runtime];
|
|
61
67
|
add(spec.projectFile, runtime);
|
|
62
68
|
if (options?.includeNativeFiles && spec.nativeFile !== spec.projectFile) {
|
|
63
|
-
add(spec.nativeFile, runtime);
|
|
69
|
+
add(spec.nativeFile, runtime, spec.nativeFileMode === "pointer" ? spec.projectFile : undefined);
|
|
64
70
|
}
|
|
65
71
|
}
|
|
66
|
-
return [...byFile.
|
|
67
|
-
filename,
|
|
68
|
-
targetPath: path.join(cwd, filename),
|
|
69
|
-
runtimes: dedupeRuntimes(rts),
|
|
70
|
-
}));
|
|
72
|
+
return [...byFile.values()].map((target) => ({ ...target, runtimes: dedupeRuntimes(target.runtimes) }));
|
|
71
73
|
}
|
|
72
74
|
// global: each runtime reads its own native file in its own home dir.
|
|
73
75
|
const targets = [];
|
|
@@ -93,18 +95,25 @@ function dedupeRuntimes(runtimes) {
|
|
|
93
95
|
/**
|
|
94
96
|
* Install an instruction brief into the right per-runtime files.
|
|
95
97
|
*
|
|
96
|
-
* By default merges `content` into a managed region of `{cwd}/
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
98
|
+
* By default merges `content` into a managed region of `{cwd}/AGENTS.md`,
|
|
99
|
+
* preserving any user-authored content outside the markers. Idempotent: a
|
|
100
|
+
* re-install with unchanged content reports every entry as "skipped".
|
|
101
|
+
*
|
|
102
|
+
* When Claude is among the runtimes, a `{cwd}/CLAUDE.md` already on disk is
|
|
103
|
+
* reconciled, because it would hide AGENTS.md from Claude Code: one holding
|
|
104
|
+
* nothing but this installer's managed region is removed, and one the user
|
|
105
|
+
* wrote gets `@AGENTS.md` in its managed region. With `includeNativeFiles`,
|
|
106
|
+
* CLAUDE.md is written as that pointer either way. `managed: false` leaves an
|
|
107
|
+
* existing CLAUDE.md alone.
|
|
100
108
|
*
|
|
101
109
|
* @example
|
|
102
110
|
* ```ts
|
|
103
111
|
* // Workspace (repo-root) install — the common case.
|
|
104
112
|
* await installInstructions(brief, { location: "workspace", cwd: projectDir });
|
|
105
|
-
* // → {cwd}/
|
|
113
|
+
* // → {cwd}/AGENTS.md
|
|
106
114
|
*
|
|
107
|
-
* // Also
|
|
115
|
+
* // Also write the native files: CLAUDE.md as an `@AGENTS.md` pointer (for
|
|
116
|
+
* // Claude Code before 2.1.277, or on Bedrock/Vertex/Foundry) and GEMINI.md.
|
|
108
117
|
* await installInstructions(brief, { location: "workspace", cwd, includeNativeFiles: true });
|
|
109
118
|
*
|
|
110
119
|
* // Global install — per-runtime home files.
|
|
@@ -115,36 +124,16 @@ function dedupeRuntimes(runtimes) {
|
|
|
115
124
|
export async function installInstructions(content, options) {
|
|
116
125
|
const managed = options?.managed ?? true;
|
|
117
126
|
const tag = options?.managedTag ?? DEFAULT_MANAGED_TAG;
|
|
118
|
-
const targets = resolveInstructionTargets(options);
|
|
119
127
|
const entries = [];
|
|
120
|
-
for (const target of
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
if (
|
|
128
|
-
|
|
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
|
-
});
|
|
128
|
+
for (const target of resolveInstructionTargets(options)) {
|
|
129
|
+
const body = target.importsFile !== undefined ? `@${target.importsFile}` : content;
|
|
130
|
+
entries.push(await writeTarget(target, body, managed, tag));
|
|
131
|
+
}
|
|
132
|
+
if (managed) {
|
|
133
|
+
for (const target of unrequestedPointerTargets(options)) {
|
|
134
|
+
const entry = await reconcilePointer(target, tag);
|
|
135
|
+
if (entry)
|
|
136
|
+
entries.push(entry);
|
|
148
137
|
}
|
|
149
138
|
}
|
|
150
139
|
return {
|
|
@@ -152,14 +141,75 @@ export async function installInstructions(content, options) {
|
|
|
152
141
|
installed: entries.filter((e) => e.status === "created").length,
|
|
153
142
|
updated: entries.filter((e) => e.status === "updated").length,
|
|
154
143
|
skipped: entries.filter((e) => e.status === "skipped").length,
|
|
144
|
+
removed: entries.filter((e) => e.status === "removed").length,
|
|
155
145
|
errors: entries.filter((e) => e.status === "error").length,
|
|
156
146
|
};
|
|
157
147
|
}
|
|
148
|
+
async function writeTarget(target, body, managed, tag) {
|
|
149
|
+
try {
|
|
150
|
+
const existing = await readFileOrNull(target.targetPath);
|
|
151
|
+
const next = managed ? upsertManagedBlock(existing, body, { tag }) : ensureTrailingNewline(body);
|
|
152
|
+
let status;
|
|
153
|
+
if (existing === null) {
|
|
154
|
+
status = "created";
|
|
155
|
+
}
|
|
156
|
+
else if (existing === next) {
|
|
157
|
+
status = "skipped";
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
status = "updated";
|
|
161
|
+
}
|
|
162
|
+
if (status !== "skipped") {
|
|
163
|
+
await fs.mkdir(path.dirname(target.targetPath), { recursive: true });
|
|
164
|
+
await fs.writeFile(target.targetPath, next, { mode: 0o644 });
|
|
165
|
+
}
|
|
166
|
+
return { ...target, status };
|
|
167
|
+
}
|
|
168
|
+
catch (err) {
|
|
169
|
+
return { ...target, status: "error", error: err instanceof Error ? err.message : String(err) };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Pointer files (a workspace CLAUDE.md) for the requested runtimes that the
|
|
174
|
+
* install doesn't write because the opt-in is off, but that still need
|
|
175
|
+
* reconciling if they exist.
|
|
176
|
+
*/
|
|
177
|
+
function unrequestedPointerTargets(options) {
|
|
178
|
+
if ((options?.location ?? "workspace") !== "workspace" || options?.includeNativeFiles)
|
|
179
|
+
return [];
|
|
180
|
+
return resolveInstructionTargets({ ...options, includeNativeFiles: true }).filter((target) => target.importsFile !== undefined);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* An existing pointer file with the opt-in off: delete it when nothing but our
|
|
184
|
+
* managed region is in it, otherwise keep the user's content and make sure it
|
|
185
|
+
* imports the project file. Returns null when there is no file.
|
|
186
|
+
*/
|
|
187
|
+
async function reconcilePointer(target, tag) {
|
|
188
|
+
try {
|
|
189
|
+
const existing = await readFileOrNull(target.targetPath);
|
|
190
|
+
if (existing === null)
|
|
191
|
+
return null;
|
|
192
|
+
if (stripManagedBlock(existing, { tag }) === null) {
|
|
193
|
+
await fs.rm(target.targetPath, { force: true });
|
|
194
|
+
return { ...target, status: "removed" };
|
|
195
|
+
}
|
|
196
|
+
const next = upsertManagedBlock(existing, `@${target.importsFile}`, { tag });
|
|
197
|
+
if (next === existing)
|
|
198
|
+
return { ...target, status: "skipped" };
|
|
199
|
+
await fs.writeFile(target.targetPath, next);
|
|
200
|
+
return { ...target, status: "updated" };
|
|
201
|
+
}
|
|
202
|
+
catch (err) {
|
|
203
|
+
return { ...target, status: "error", error: err instanceof Error ? err.message : String(err) };
|
|
204
|
+
}
|
|
205
|
+
}
|
|
158
206
|
/**
|
|
159
207
|
* Remove the managed region installed by {@link installInstructions}, preserving
|
|
160
208
|
* any user-authored content outside the markers. If the file contains nothing
|
|
161
209
|
* but the managed block, it is deleted. User-owned files (no managed region) are
|
|
162
|
-
* left untouched and reported as "skipped".
|
|
210
|
+
* left untouched and reported as "skipped". Native files (CLAUDE.md, GEMINI.md)
|
|
211
|
+
* are always checked, whether or not they were installed with
|
|
212
|
+
* `includeNativeFiles`.
|
|
163
213
|
*/
|
|
164
214
|
export async function removeInstructions(options) {
|
|
165
215
|
const tag = options?.managedTag ?? DEFAULT_MANAGED_TAG;
|
|
@@ -167,6 +217,7 @@ export async function removeInstructions(options) {
|
|
|
167
217
|
runtimes: options?.runtimes,
|
|
168
218
|
location: options?.location,
|
|
169
219
|
cwd: options?.cwd,
|
|
220
|
+
includeNativeFiles: true,
|
|
170
221
|
homeDir: options?.homeDir,
|
|
171
222
|
});
|
|
172
223
|
const entries = [];
|
|
@@ -1 +1 @@
|
|
|
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,C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C,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"}
|
package/package.json
CHANGED
|
@@ -29,18 +29,27 @@ export async function resolveInstructions(filePath?: string): Promise<string | n
|
|
|
29
29
|
// (.agents/skills + .claude/skills) with a per-runtime "native" escape hatch.
|
|
30
30
|
// Instruction files follow the same shape:
|
|
31
31
|
//
|
|
32
|
-
// - every runtime
|
|
33
|
-
//
|
|
34
|
-
//
|
|
32
|
+
// - every runtime reads AGENTS.md at a workspace root (Claude Code since
|
|
33
|
+
// 2.1.277, where the folder has no CLAUDE.md)
|
|
34
|
+
// - Claude's CLAUDE.md and Gemini's GEMINI.md are native files, written only
|
|
35
|
+
// on opt-in (`includeNativeFiles`)
|
|
35
36
|
//
|
|
36
37
|
// Two locations, mirroring installSkills:
|
|
37
38
|
//
|
|
38
39
|
// - "workspace": files at {cwd}/ — the repo-root AGENTS.md convention. Files
|
|
39
|
-
// dedupe by name, so the default writes
|
|
40
|
+
// dedupe by name, so the default writes AGENTS.md once.
|
|
40
41
|
// - "global": each runtime reads its own file in its own home dir
|
|
41
42
|
// (~/.claude/CLAUDE.md, ~/.codex/AGENTS.md, ~/.gemini/GEMINI.md, ...). There
|
|
42
43
|
// is no universal ~/AGENTS.md, so global is inherently per-runtime.
|
|
43
44
|
//
|
|
45
|
+
// Claude Code reads AGENTS.md only where no CLAUDE.md exists: a CLAUDE.md (or
|
|
46
|
+
// a CLAUDE.local.md, or one in a parent directory) hides AGENTS.md completely.
|
|
47
|
+
// So a workspace CLAUDE.md is only ever a one-line pointer (`@AGENTS.md`),
|
|
48
|
+
// never a second copy of the brief, and a CLAUDE.md already on disk is
|
|
49
|
+
// reconciled on every install: one holding nothing but our managed region is
|
|
50
|
+
// removed when the opt-in is off, and one the user wrote gets the pointer so
|
|
51
|
+
// the brief still reaches Claude.
|
|
52
|
+
//
|
|
44
53
|
// Unlike skills (which are symlinked dirs), instruction files carry content, so
|
|
45
54
|
// installInstructions does a managed-region merge: it wraps `content` in marker
|
|
46
55
|
// comments and replaces only that region on re-install, preserving anything the
|
|
@@ -48,21 +57,28 @@ export async function resolveInstructions(filePath?: string): Promise<string | n
|
|
|
48
57
|
// ===========================================================================
|
|
49
58
|
|
|
50
59
|
interface RuntimeInstructionSpec {
|
|
51
|
-
/** File this runtime reads at a workspace/repo root. AGENTS.md for
|
|
60
|
+
/** File this runtime reads at a workspace/repo root. AGENTS.md for every runtime. */
|
|
52
61
|
projectFile: string;
|
|
53
|
-
/** The runtime's own preferred filename.
|
|
62
|
+
/** The runtime's own preferred filename. Written in a workspace only on opt-in (`includeNativeFiles`). */
|
|
54
63
|
nativeFile: string;
|
|
64
|
+
/**
|
|
65
|
+
* How an opt-in native file carries the brief. "pointer": only an import of
|
|
66
|
+
* the project file (`@AGENTS.md`), because the native file's mere presence
|
|
67
|
+
* hides the project file from the runtime (Claude). "copy": the brief itself
|
|
68
|
+
* (Gemini, which doesn't read AGENTS.md by default).
|
|
69
|
+
*/
|
|
70
|
+
nativeFileMode: "pointer" | "copy";
|
|
55
71
|
/** Whether the runtime has a file-based global config. False for Cursor (global = app User Rules). */
|
|
56
72
|
hasGlobalFile: boolean;
|
|
57
73
|
}
|
|
58
74
|
|
|
59
75
|
const RUNTIME_INSTRUCTIONS: Record<SkillRuntime, RuntimeInstructionSpec> = {
|
|
60
|
-
claude: { projectFile: "
|
|
61
|
-
codex: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", hasGlobalFile: true },
|
|
62
|
-
opencode: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", hasGlobalFile: true },
|
|
63
|
-
gemini: { projectFile: "AGENTS.md", nativeFile: "GEMINI.md", hasGlobalFile: true },
|
|
64
|
-
cursor: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", hasGlobalFile: false },
|
|
65
|
-
pi: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", hasGlobalFile: true },
|
|
76
|
+
claude: { projectFile: "AGENTS.md", nativeFile: "CLAUDE.md", nativeFileMode: "pointer", hasGlobalFile: true },
|
|
77
|
+
codex: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", nativeFileMode: "copy", hasGlobalFile: true },
|
|
78
|
+
opencode: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", nativeFileMode: "copy", hasGlobalFile: true },
|
|
79
|
+
gemini: { projectFile: "AGENTS.md", nativeFile: "GEMINI.md", nativeFileMode: "copy", hasGlobalFile: true },
|
|
80
|
+
cursor: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", nativeFileMode: "copy", hasGlobalFile: false },
|
|
81
|
+
pi: { projectFile: "AGENTS.md", nativeFile: "AGENTS.md", nativeFileMode: "copy", hasGlobalFile: true },
|
|
66
82
|
};
|
|
67
83
|
|
|
68
84
|
const ALL_RUNTIMES: SkillRuntime[] = ["claude", "codex", "gemini", "cursor", "opencode", "pi"];
|
|
@@ -78,15 +94,20 @@ export interface InstallInstructionsOptions {
|
|
|
78
94
|
cwd?: string;
|
|
79
95
|
/**
|
|
80
96
|
* Also write each runtime's native file when it differs from the shared
|
|
81
|
-
*
|
|
82
|
-
*
|
|
97
|
+
* AGENTS.md: Claude's CLAUDE.md (as a one-line `@AGENTS.md` pointer) and
|
|
98
|
+
* Gemini's GEMINI.md (as a copy). Only affects "workspace"; "global" always
|
|
99
|
+
* uses native files. Default: false.
|
|
100
|
+
*
|
|
101
|
+
* Opt in for Claude Code before 2.1.277, or on Bedrock, Vertex or Foundry,
|
|
102
|
+
* where Claude doesn't read AGENTS.md on its own.
|
|
83
103
|
*/
|
|
84
104
|
includeNativeFiles?: boolean;
|
|
85
105
|
/**
|
|
86
106
|
* Wrap `content` in managed markers and merge into any existing file,
|
|
87
107
|
* replacing only the previously-managed region and preserving everything the
|
|
88
108
|
* user wrote outside it. Default: true. When false, the file is overwritten
|
|
89
|
-
* with raw `content` (escape hatch for fully-owned files)
|
|
109
|
+
* with raw `content` (escape hatch for fully-owned files), and an existing
|
|
110
|
+
* CLAUDE.md is left alone even though it hides AGENTS.md from Claude Code.
|
|
90
111
|
*/
|
|
91
112
|
managed?: boolean;
|
|
92
113
|
/** Marker tag, so the comment reads `<!-- <tag>:managed:start -->`. Default: "agentex". */
|
|
@@ -98,7 +119,11 @@ export interface InstallInstructionsOptions {
|
|
|
98
119
|
homeDir?: string;
|
|
99
120
|
}
|
|
100
121
|
|
|
101
|
-
|
|
122
|
+
/**
|
|
123
|
+
* "removed": a workspace CLAUDE.md that held nothing but this installer's
|
|
124
|
+
* managed region, deleted because the opt-in (`includeNativeFiles`) is off.
|
|
125
|
+
*/
|
|
126
|
+
export type InstructionStatus = "created" | "updated" | "skipped" | "removed" | "error";
|
|
102
127
|
|
|
103
128
|
export interface InstructionInstallEntry {
|
|
104
129
|
/** The filename written, e.g. "AGENTS.md", "CLAUDE.md", "GEMINI.md". */
|
|
@@ -107,6 +132,8 @@ export interface InstructionInstallEntry {
|
|
|
107
132
|
targetPath: string;
|
|
108
133
|
/** Which requested runtimes this file serves. */
|
|
109
134
|
runtimes: SkillRuntime[];
|
|
135
|
+
/** Set when the file is a pointer: its managed region is `@<importsFile>`, not the brief. */
|
|
136
|
+
importsFile?: string;
|
|
110
137
|
status: InstructionStatus;
|
|
111
138
|
error?: string;
|
|
112
139
|
}
|
|
@@ -116,6 +143,7 @@ export interface InstructionInstallResult {
|
|
|
116
143
|
installed: number; // newly created files
|
|
117
144
|
updated: number; // existing files whose content changed
|
|
118
145
|
skipped: number; // content already current → no write
|
|
146
|
+
removed: number; // managed-only CLAUDE.md deleted because the opt-in is off
|
|
119
147
|
errors: number;
|
|
120
148
|
}
|
|
121
149
|
|
|
@@ -123,6 +151,8 @@ export interface InstructionTarget {
|
|
|
123
151
|
filename: string;
|
|
124
152
|
targetPath: string;
|
|
125
153
|
runtimes: SkillRuntime[];
|
|
154
|
+
/** Set when the file is a pointer: its managed region is `@<importsFile>`, not the brief. */
|
|
155
|
+
importsFile?: string;
|
|
126
156
|
}
|
|
127
157
|
|
|
128
158
|
export interface RemoveInstructionsOptions {
|
|
@@ -163,7 +193,8 @@ export interface ManagedBlockOptions {
|
|
|
163
193
|
* without touching disk.
|
|
164
194
|
*
|
|
165
195
|
* - "workspace": files dedupe by name under {cwd}/ (the default writes
|
|
166
|
-
*
|
|
196
|
+
* AGENTS.md once). `includeNativeFiles` adds CLAUDE.md (a pointer, marked by
|
|
197
|
+
* `importsFile`) and GEMINI.md.
|
|
167
198
|
* - "global": one file per runtime in each runtime's home dir. Runtimes without
|
|
168
199
|
* a file-based global config (Cursor) are omitted.
|
|
169
200
|
*/
|
|
@@ -181,26 +212,27 @@ export function resolveInstructionTargets(options?: {
|
|
|
181
212
|
const cwd = options?.cwd;
|
|
182
213
|
if (!cwd) throw new Error("cwd is required when location is 'workspace'");
|
|
183
214
|
|
|
184
|
-
const byFile = new Map<string,
|
|
185
|
-
const add = (filename: string, runtime: SkillRuntime) => {
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
|
|
215
|
+
const byFile = new Map<string, InstructionTarget>();
|
|
216
|
+
const add = (filename: string, runtime: SkillRuntime, importsFile?: string) => {
|
|
217
|
+
const target: InstructionTarget = byFile.get(filename) ?? {
|
|
218
|
+
filename,
|
|
219
|
+
targetPath: path.join(cwd, filename),
|
|
220
|
+
runtimes: [],
|
|
221
|
+
...(importsFile !== undefined && { importsFile }),
|
|
222
|
+
};
|
|
223
|
+
target.runtimes.push(runtime);
|
|
224
|
+
byFile.set(filename, target);
|
|
189
225
|
};
|
|
190
226
|
|
|
191
227
|
for (const runtime of runtimes) {
|
|
192
228
|
const spec = RUNTIME_INSTRUCTIONS[runtime];
|
|
193
229
|
add(spec.projectFile, runtime);
|
|
194
230
|
if (options?.includeNativeFiles && spec.nativeFile !== spec.projectFile) {
|
|
195
|
-
add(spec.nativeFile, runtime);
|
|
231
|
+
add(spec.nativeFile, runtime, spec.nativeFileMode === "pointer" ? spec.projectFile : undefined);
|
|
196
232
|
}
|
|
197
233
|
}
|
|
198
234
|
|
|
199
|
-
return [...byFile.
|
|
200
|
-
filename,
|
|
201
|
-
targetPath: path.join(cwd, filename),
|
|
202
|
-
runtimes: dedupeRuntimes(rts),
|
|
203
|
-
}));
|
|
235
|
+
return [...byFile.values()].map((target) => ({ ...target, runtimes: dedupeRuntimes(target.runtimes) }));
|
|
204
236
|
}
|
|
205
237
|
|
|
206
238
|
// global: each runtime reads its own native file in its own home dir.
|
|
@@ -229,18 +261,25 @@ function dedupeRuntimes(runtimes: SkillRuntime[]): SkillRuntime[] {
|
|
|
229
261
|
/**
|
|
230
262
|
* Install an instruction brief into the right per-runtime files.
|
|
231
263
|
*
|
|
232
|
-
* By default merges `content` into a managed region of `{cwd}/
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
264
|
+
* By default merges `content` into a managed region of `{cwd}/AGENTS.md`,
|
|
265
|
+
* preserving any user-authored content outside the markers. Idempotent: a
|
|
266
|
+
* re-install with unchanged content reports every entry as "skipped".
|
|
267
|
+
*
|
|
268
|
+
* When Claude is among the runtimes, a `{cwd}/CLAUDE.md` already on disk is
|
|
269
|
+
* reconciled, because it would hide AGENTS.md from Claude Code: one holding
|
|
270
|
+
* nothing but this installer's managed region is removed, and one the user
|
|
271
|
+
* wrote gets `@AGENTS.md` in its managed region. With `includeNativeFiles`,
|
|
272
|
+
* CLAUDE.md is written as that pointer either way. `managed: false` leaves an
|
|
273
|
+
* existing CLAUDE.md alone.
|
|
236
274
|
*
|
|
237
275
|
* @example
|
|
238
276
|
* ```ts
|
|
239
277
|
* // Workspace (repo-root) install — the common case.
|
|
240
278
|
* await installInstructions(brief, { location: "workspace", cwd: projectDir });
|
|
241
|
-
* // → {cwd}/
|
|
279
|
+
* // → {cwd}/AGENTS.md
|
|
242
280
|
*
|
|
243
|
-
* // Also
|
|
281
|
+
* // Also write the native files: CLAUDE.md as an `@AGENTS.md` pointer (for
|
|
282
|
+
* // Claude Code before 2.1.277, or on Bedrock/Vertex/Foundry) and GEMINI.md.
|
|
244
283
|
* await installInstructions(brief, { location: "workspace", cwd, includeNativeFiles: true });
|
|
245
284
|
*
|
|
246
285
|
* // Global install — per-runtime home files.
|
|
@@ -254,37 +293,16 @@ export async function installInstructions(
|
|
|
254
293
|
): Promise<InstructionInstallResult> {
|
|
255
294
|
const managed = options?.managed ?? true;
|
|
256
295
|
const tag = options?.managedTag ?? DEFAULT_MANAGED_TAG;
|
|
257
|
-
const targets = resolveInstructionTargets(options);
|
|
258
296
|
const entries: InstructionInstallEntry[] = [];
|
|
259
297
|
|
|
260
|
-
for (const target of
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
if (existing === null) {
|
|
269
|
-
status = "created";
|
|
270
|
-
} else if (existing === next) {
|
|
271
|
-
status = "skipped";
|
|
272
|
-
} else {
|
|
273
|
-
status = "updated";
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
if (status !== "skipped") {
|
|
277
|
-
await fs.mkdir(path.dirname(target.targetPath), { recursive: true });
|
|
278
|
-
await fs.writeFile(target.targetPath, next, { mode: 0o644 });
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
entries.push({ ...target, status });
|
|
282
|
-
} catch (err) {
|
|
283
|
-
entries.push({
|
|
284
|
-
...target,
|
|
285
|
-
status: "error",
|
|
286
|
-
error: err instanceof Error ? err.message : String(err),
|
|
287
|
-
});
|
|
298
|
+
for (const target of resolveInstructionTargets(options)) {
|
|
299
|
+
const body = target.importsFile !== undefined ? `@${target.importsFile}` : content;
|
|
300
|
+
entries.push(await writeTarget(target, body, managed, tag));
|
|
301
|
+
}
|
|
302
|
+
if (managed) {
|
|
303
|
+
for (const target of unrequestedPointerTargets(options)) {
|
|
304
|
+
const entry = await reconcilePointer(target, tag);
|
|
305
|
+
if (entry) entries.push(entry);
|
|
288
306
|
}
|
|
289
307
|
}
|
|
290
308
|
|
|
@@ -293,15 +311,84 @@ export async function installInstructions(
|
|
|
293
311
|
installed: entries.filter((e) => e.status === "created").length,
|
|
294
312
|
updated: entries.filter((e) => e.status === "updated").length,
|
|
295
313
|
skipped: entries.filter((e) => e.status === "skipped").length,
|
|
314
|
+
removed: entries.filter((e) => e.status === "removed").length,
|
|
296
315
|
errors: entries.filter((e) => e.status === "error").length,
|
|
297
316
|
};
|
|
298
317
|
}
|
|
299
318
|
|
|
319
|
+
async function writeTarget(
|
|
320
|
+
target: InstructionTarget,
|
|
321
|
+
body: string,
|
|
322
|
+
managed: boolean,
|
|
323
|
+
tag: string,
|
|
324
|
+
): Promise<InstructionInstallEntry> {
|
|
325
|
+
try {
|
|
326
|
+
const existing = await readFileOrNull(target.targetPath);
|
|
327
|
+
const next = managed ? upsertManagedBlock(existing, body, { tag }) : ensureTrailingNewline(body);
|
|
328
|
+
|
|
329
|
+
let status: InstructionStatus;
|
|
330
|
+
if (existing === null) {
|
|
331
|
+
status = "created";
|
|
332
|
+
} else if (existing === next) {
|
|
333
|
+
status = "skipped";
|
|
334
|
+
} else {
|
|
335
|
+
status = "updated";
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (status !== "skipped") {
|
|
339
|
+
await fs.mkdir(path.dirname(target.targetPath), { recursive: true });
|
|
340
|
+
await fs.writeFile(target.targetPath, next, { mode: 0o644 });
|
|
341
|
+
}
|
|
342
|
+
return { ...target, status };
|
|
343
|
+
} catch (err) {
|
|
344
|
+
return { ...target, status: "error", error: err instanceof Error ? err.message : String(err) };
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Pointer files (a workspace CLAUDE.md) for the requested runtimes that the
|
|
350
|
+
* install doesn't write because the opt-in is off, but that still need
|
|
351
|
+
* reconciling if they exist.
|
|
352
|
+
*/
|
|
353
|
+
function unrequestedPointerTargets(options?: InstallInstructionsOptions): InstructionTarget[] {
|
|
354
|
+
if ((options?.location ?? "workspace") !== "workspace" || options?.includeNativeFiles) return [];
|
|
355
|
+
return resolveInstructionTargets({ ...options, includeNativeFiles: true }).filter(
|
|
356
|
+
(target) => target.importsFile !== undefined,
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* An existing pointer file with the opt-in off: delete it when nothing but our
|
|
362
|
+
* managed region is in it, otherwise keep the user's content and make sure it
|
|
363
|
+
* imports the project file. Returns null when there is no file.
|
|
364
|
+
*/
|
|
365
|
+
async function reconcilePointer(
|
|
366
|
+
target: InstructionTarget,
|
|
367
|
+
tag: string,
|
|
368
|
+
): Promise<InstructionInstallEntry | null> {
|
|
369
|
+
try {
|
|
370
|
+
const existing = await readFileOrNull(target.targetPath);
|
|
371
|
+
if (existing === null) return null;
|
|
372
|
+
if (stripManagedBlock(existing, { tag }) === null) {
|
|
373
|
+
await fs.rm(target.targetPath, { force: true });
|
|
374
|
+
return { ...target, status: "removed" };
|
|
375
|
+
}
|
|
376
|
+
const next = upsertManagedBlock(existing, `@${target.importsFile}`, { tag });
|
|
377
|
+
if (next === existing) return { ...target, status: "skipped" };
|
|
378
|
+
await fs.writeFile(target.targetPath, next);
|
|
379
|
+
return { ...target, status: "updated" };
|
|
380
|
+
} catch (err) {
|
|
381
|
+
return { ...target, status: "error", error: err instanceof Error ? err.message : String(err) };
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
300
385
|
/**
|
|
301
386
|
* Remove the managed region installed by {@link installInstructions}, preserving
|
|
302
387
|
* any user-authored content outside the markers. If the file contains nothing
|
|
303
388
|
* but the managed block, it is deleted. User-owned files (no managed region) are
|
|
304
|
-
* left untouched and reported as "skipped".
|
|
389
|
+
* left untouched and reported as "skipped". Native files (CLAUDE.md, GEMINI.md)
|
|
390
|
+
* are always checked, whether or not they were installed with
|
|
391
|
+
* `includeNativeFiles`.
|
|
305
392
|
*/
|
|
306
393
|
export async function removeInstructions(
|
|
307
394
|
options?: RemoveInstructionsOptions,
|
|
@@ -311,6 +398,7 @@ export async function removeInstructions(
|
|
|
311
398
|
runtimes: options?.runtimes,
|
|
312
399
|
location: options?.location,
|
|
313
400
|
cwd: options?.cwd,
|
|
401
|
+
includeNativeFiles: true,
|
|
314
402
|
homeDir: options?.homeDir,
|
|
315
403
|
});
|
|
316
404
|
const entries: InstructionRemoveEntry[] = [];
|