carrick 0.3.150 → 0.3.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/global-install.d.ts +2 -2
- package/dist/global-install.js +1 -1
- package/dist/global-install.js.map +1 -1
- package/dist/hook/reuse.d.ts +1 -0
- package/dist/hook/reuse.js +10 -1
- package/dist/hook/reuse.js.map +1 -1
- package/dist/hook/session-start.js +15 -13
- package/dist/hook/session-start.js.map +1 -1
- package/dist/hook/stop-wait.js +5 -1
- package/dist/hook/stop-wait.js.map +1 -1
- package/dist/hook/upgrade.d.ts +11 -0
- package/dist/hook/upgrade.js +81 -0
- package/dist/hook/upgrade.js.map +1 -0
- package/dist/hook/worktree.d.ts +4 -0
- package/dist/hook/worktree.js +9 -0
- package/dist/hook/worktree.js.map +1 -1
- package/dist/init/repo-copies.d.ts +2 -0
- package/dist/init/repo-copies.js +1 -1
- package/dist/init/repo-copies.js.map +1 -1
- package/dist/init/self-update.d.ts +2 -2
- package/dist/init/self-update.js +56 -12
- package/dist/init/self-update.js.map +1 -1
- package/dist/self-upgrade.d.ts +1 -0
- package/dist/self-upgrade.js +10 -0
- package/dist/self-upgrade.js.map +1 -0
- package/dist/upgrade.d.ts +26 -0
- package/dist/upgrade.js +86 -0
- package/dist/upgrade.js.map +1 -0
- package/package.json +6 -6
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/sidecar/dist/src/capture/anchors.d.ts +7 -0
- package/sidecar/dist/src/capture/anchors.js +13 -4
- package/sidecar/dist/src/capture/check-classify.js +4 -2
- package/sidecar/dist/src/capture/check.js +8 -4
- package/sidecar/dist/src/capture/deep-walk.d.ts +14 -8
- package/sidecar/dist/src/capture/deep-walk.js +26 -9
- package/sidecar/dist/src/capture/index.js +4 -2
- package/sidecar/dist/src/capture/self-check.d.ts +7 -0
- package/sidecar/dist/src/capture/self-check.js +19 -1
- package/sidecar/dist/src/capture/service-config.d.ts +5 -4
- package/sidecar/dist/src/capture/service-config.js +15 -12
- package/sidecar/dist/src/library-claims.js +81 -17
- package/sidecar/dist/src/position-rows.js +25 -3
- package/sidecar/dist/src/types.d.ts +8 -1
- package/sidecar/dist/src/validators.d.ts +104 -0
- package/sidecar/dist/src/validators.js +3 -1
package/dist/init/self-update.js
CHANGED
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
// for a Claude Code session; the skills and the AGENTS.md section, which Codex
|
|
31
31
|
// reads with no trust gate, move the same way under either.
|
|
32
32
|
//
|
|
33
|
+
// A file git tracks here is the team's, not ours: it is left as it is and named in
|
|
34
|
+
// one line (carrick self-update R5), because a rewrite on whatever branch the
|
|
35
|
+
// session is on leaves a diff, and two teammates on different versions would flip
|
|
36
|
+
// it back and forth.
|
|
37
|
+
//
|
|
33
38
|
// `.codex/hooks.json` is never written: a changed project hook is untrusted until
|
|
34
39
|
// Codex records its hash (`codex.ts`), so only `carrick init` plus the user's
|
|
35
40
|
// approval can move it.
|
|
@@ -43,7 +48,8 @@ import { isNewer } from "../update.js";
|
|
|
43
48
|
import { AGENTS_FILE, CLAUDE_FILE, renderCheckSection, withCheckSection } from "./agents-section.js";
|
|
44
49
|
import { entriesAreStale, outdatedFiles, outdatedInstall, recordCliVersion, recordedCliVersion, } from "./outdated.js";
|
|
45
50
|
import { expectedCarrickHooks, installedCarrickHooks, mergeCarrickHooks, SETTINGS_FILES } from "./settings.js";
|
|
46
|
-
import {
|
|
51
|
+
import { trackedPaths } from "./repo-copies.js";
|
|
52
|
+
import { inspectTaskSkills, renderTaskSkill, scopeOf, SKILL_ROOTS, TASK_SKILLS } from "./task-skills.js";
|
|
47
53
|
/** Which settings files were rewritten for which version, so one removed on purpose stays removed. */
|
|
48
54
|
export function updatedStampFile(workspace) {
|
|
49
55
|
return path.join(workspace, ".carrick", "hook-entries-updated.json");
|
|
@@ -74,13 +80,15 @@ function writeAtomic(target, body) {
|
|
|
74
80
|
* files written: a file the merge leaves as it is is neither stamped nor reported.
|
|
75
81
|
* `merge` is a parameter so a test can hold a file the merge does not move.
|
|
76
82
|
*/
|
|
77
|
-
export function updateHooks(workspace, projectDir, running, merge = mergeCarrickHooks) {
|
|
83
|
+
export function updateHooks(workspace, projectDir, running, merge = mergeCarrickHooks, tracked = new Set(), held = []) {
|
|
78
84
|
const stamp = readStamp(workspace);
|
|
79
85
|
const changed = [];
|
|
80
86
|
for (const relative of SETTINGS_FILES) {
|
|
81
|
-
if (stamp[relative] === running)
|
|
82
|
-
continue;
|
|
83
87
|
const target = path.join(projectDir, relative);
|
|
88
|
+
// Keyed by the file's path under the workspace, so a repo's copy is its own entry.
|
|
89
|
+
const key = path.relative(workspace, target);
|
|
90
|
+
if (stamp[key] === running)
|
|
91
|
+
continue;
|
|
84
92
|
try {
|
|
85
93
|
const body = fs.readFileSync(target, "utf8");
|
|
86
94
|
if (!entriesAreStale(body, expectedCarrickHooks))
|
|
@@ -89,8 +97,12 @@ export function updateHooks(workspace, projectDir, running, merge = mergeCarrick
|
|
|
89
97
|
const merged = merge(body, prefix);
|
|
90
98
|
if (!merged.changed)
|
|
91
99
|
continue;
|
|
100
|
+
if (tracked.has(relative)) {
|
|
101
|
+
held.push(relative);
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
92
104
|
writeAtomic(target, merged.body);
|
|
93
|
-
stamp[
|
|
105
|
+
stamp[key] = running;
|
|
94
106
|
changed.push(relative);
|
|
95
107
|
}
|
|
96
108
|
catch {
|
|
@@ -108,7 +120,7 @@ export function updateHooks(workspace, projectDir, running, merge = mergeCarrick
|
|
|
108
120
|
return changed;
|
|
109
121
|
}
|
|
110
122
|
/** Task skills still ours and an older body, rewritten with the scope each was written with. */
|
|
111
|
-
function updateSkills(workspace) {
|
|
123
|
+
function updateSkills(workspace, tracked, held) {
|
|
112
124
|
const changed = [];
|
|
113
125
|
for (const skill of inspectTaskSkills(workspace)) {
|
|
114
126
|
if (skill.state !== "ours" || skill.current)
|
|
@@ -116,6 +128,10 @@ function updateSkills(workspace) {
|
|
|
116
128
|
const name = path.basename(path.dirname(skill.path));
|
|
117
129
|
if (!TASK_SKILLS.includes(name))
|
|
118
130
|
continue;
|
|
131
|
+
if (tracked.has(skill.path)) {
|
|
132
|
+
held.push(skill.path);
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
119
135
|
try {
|
|
120
136
|
const target = path.join(workspace, skill.path);
|
|
121
137
|
writeAtomic(target, renderTaskSkill(name, scopeOf(fs.readFileSync(target, "utf8"))));
|
|
@@ -145,7 +161,7 @@ function snapshotCounts(workspace) {
|
|
|
145
161
|
* the snapshot. Returns the file written, or null. `log` says why a section was
|
|
146
162
|
* left alone.
|
|
147
163
|
*/
|
|
148
|
-
function updateAgentsSection(workspace, log) {
|
|
164
|
+
function updateAgentsSection(workspace, log, tracked, held) {
|
|
149
165
|
const target = path.join(workspace, AGENTS_FILE);
|
|
150
166
|
try {
|
|
151
167
|
const existing = fs.readFileSync(target, "utf8");
|
|
@@ -160,6 +176,10 @@ function updateAgentsSection(workspace, log) {
|
|
|
160
176
|
const body = withCheckSection(existing, renderCheckSection({ slug }, counts));
|
|
161
177
|
if (body === existing)
|
|
162
178
|
return null;
|
|
179
|
+
if (tracked.has(AGENTS_FILE)) {
|
|
180
|
+
held.push(AGENTS_FILE);
|
|
181
|
+
return null;
|
|
182
|
+
}
|
|
163
183
|
writeAtomic(target, body);
|
|
164
184
|
return AGENTS_FILE;
|
|
165
185
|
}
|
|
@@ -173,7 +193,7 @@ function updateAgentsSection(workspace, log) {
|
|
|
173
193
|
* holds our marker, so a folder init never wrote to is left alone. Returns the
|
|
174
194
|
* file written, or null.
|
|
175
195
|
*/
|
|
176
|
-
function updateClaudeSection(workspace) {
|
|
196
|
+
function updateClaudeSection(workspace, tracked, held) {
|
|
177
197
|
const target = path.join(workspace, CLAUDE_FILE);
|
|
178
198
|
try {
|
|
179
199
|
const agents = fs.readFileSync(path.join(workspace, AGENTS_FILE), "utf8");
|
|
@@ -187,6 +207,10 @@ function updateClaudeSection(workspace) {
|
|
|
187
207
|
const body = withCheckSection(existing, renderCheckSection({ slug }, counts));
|
|
188
208
|
if (body === existing)
|
|
189
209
|
return null;
|
|
210
|
+
if (tracked.has(CLAUDE_FILE)) {
|
|
211
|
+
held.push(CLAUDE_FILE);
|
|
212
|
+
return null;
|
|
213
|
+
}
|
|
190
214
|
writeAtomic(target, body);
|
|
191
215
|
return CLAUDE_FILE;
|
|
192
216
|
}
|
|
@@ -202,26 +226,46 @@ function updateClaudeSection(workspace) {
|
|
|
202
226
|
* than the one recorded in `.carrick/cli-version` (the mismatch line tells the
|
|
203
227
|
* person to replace that install, and a rewrite would downgrade the files).
|
|
204
228
|
*/
|
|
205
|
-
export function bringUpToDate(workspace, projectDir, running, log = () => { }) {
|
|
229
|
+
export function bringUpToDate(workspace, projectDir, running, log = () => { }, held = []) {
|
|
206
230
|
if (!running || !/^\d+\.\d+\.\d+$/.test(running))
|
|
207
231
|
return [];
|
|
208
232
|
const recorded = recordedCliVersion(workspace);
|
|
209
233
|
if (recorded !== null && isNewer(recorded, running))
|
|
210
234
|
return [];
|
|
211
235
|
const lines = [];
|
|
212
|
-
|
|
236
|
+
// Files git tracks here are the team's: left as they are and named below. Asked
|
|
237
|
+
// once per directory; a folder that is no repository, or a git that cannot
|
|
238
|
+
// answer, tracks nothing, which is what this did before it asked.
|
|
239
|
+
const settingsHeld = [];
|
|
240
|
+
const hooks = projectDir === null
|
|
241
|
+
? []
|
|
242
|
+
: updateHooks(workspace, projectDir, running, mergeCarrickHooks, trackedPaths(projectDir, SETTINGS_FILES) ?? new Set(), settingsHeld);
|
|
213
243
|
if (hooks.length > 0) {
|
|
214
244
|
lines.push(`Carrick brought its hook entries in ${hooks.join(", ")} up to date for ${running}.`);
|
|
215
245
|
}
|
|
216
|
-
const
|
|
246
|
+
const rootTracked = trackedPaths(workspace, [...SKILL_ROOTS, AGENTS_FILE, CLAUDE_FILE]) ?? new Set();
|
|
247
|
+
const rootHeld = [];
|
|
248
|
+
const skills = updateSkills(workspace, rootTracked, rootHeld);
|
|
217
249
|
if (skills.length > 0) {
|
|
218
250
|
const roots = [...new Set(skills.map((file) => path.dirname(path.dirname(file))))];
|
|
219
251
|
lines.push(`Carrick brought its task skills in ${roots.join(", ")} up to date for ${running}.`);
|
|
220
252
|
}
|
|
221
|
-
const written = [
|
|
253
|
+
const written = [
|
|
254
|
+
updateAgentsSection(workspace, log, rootTracked, rootHeld),
|
|
255
|
+
updateClaudeSection(workspace, rootTracked, rootHeld),
|
|
256
|
+
].filter((file) => file !== null);
|
|
222
257
|
if (written.length > 0) {
|
|
223
258
|
lines.push(`Carrick brought its rules section in ${written.join(" and ")} up to date for ${running}.`);
|
|
224
259
|
}
|
|
260
|
+
const skipped = [
|
|
261
|
+
...settingsHeld.map((file) => path.relative(workspace, path.join(projectDir ?? workspace, file))),
|
|
262
|
+
...rootHeld,
|
|
263
|
+
];
|
|
264
|
+
held.push(...skipped);
|
|
265
|
+
if (skipped.length > 0) {
|
|
266
|
+
const named = skipped.length === 1 ? skipped[0] : `${skipped.slice(0, -1).join(", ")} and ${skipped.at(-1)}`;
|
|
267
|
+
lines.push(`Carrick did not update ${named} because git tracks them here. Run \`carrick init\`, then commit the change in its own pull request.`);
|
|
268
|
+
}
|
|
225
269
|
// The recorded version is what the mismatch line compares. Move it only when
|
|
226
270
|
// nothing of ours is still old: a Codex hook file we may not touch keeps the
|
|
227
271
|
// "run carrick init" line honest.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"self-update.js","sourceRoot":"","sources":["../../src/init/self-update.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,+EAA+E;AAC/E,0EAA0E;AAC1E,iFAAiF;AACjF,oEAAoE;AACpE,EAAE;AACF,qCAAqC;AACrC,EAAE;AACF,uFAAuF;AACvF,mFAAmF;AACnF,oFAAoF;AACpF,0EAA0E;AAC1E,kFAAkF;AAClF,kFAAkF;AAClF,0EAA0E;AAC1E,kFAAkF;AAClF,kFAAkF;AAClF,uCAAuC;AACvC,EAAE;AACF,kFAAkF;AAClF,gFAAgF;AAChF,+EAA+E;AAC/E,4EAA4E;AAC5E,gFAAgF;AAChF,iBAAiB;AACjB,EAAE;AACF,2EAA2E;AAC3E,iFAAiF;AACjF,+EAA+E;AAC/E,4DAA4D;AAC5D,EAAE;AACF,kFAAkF;AAClF,8EAA8E;AAC9E,wBAAwB;AACxB,EAAE;AACF,8CAA8C;AAE9C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,kBAAkB,EAAE,gBAAgB,EAAwB,MAAM,qBAAqB,CAAC;AAC3H,OAAO,EACL,eAAe,EACf,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/G,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,OAAO,EAAE,WAAW,EAAkB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"self-update.js","sourceRoot":"","sources":["../../src/init/self-update.ts"],"names":[],"mappings":"AAAA,iEAAiE;AACjE,EAAE;AACF,+EAA+E;AAC/E,0EAA0E;AAC1E,iFAAiF;AACjF,oEAAoE;AACpE,EAAE;AACF,qCAAqC;AACrC,EAAE;AACF,uFAAuF;AACvF,mFAAmF;AACnF,oFAAoF;AACpF,0EAA0E;AAC1E,kFAAkF;AAClF,kFAAkF;AAClF,0EAA0E;AAC1E,kFAAkF;AAClF,kFAAkF;AAClF,uCAAuC;AACvC,EAAE;AACF,kFAAkF;AAClF,gFAAgF;A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,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,OAAO,IAAI,aAAa,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxG,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// The detached child that upgrades an existing global install.
|
|
2
|
+
//
|
|
3
|
+
// Started by the session-start hook (`src/hook/upgrade.ts`), which does not
|
|
4
|
+
// wait for it. It prints nothing on either stream: its parent is gone and its
|
|
5
|
+
// stdio is `ignore`. What it did is read by the next session from
|
|
6
|
+
// `self-upgrade.json` (`src/upgrade.ts`).
|
|
7
|
+
import { runUpgrade } from "./upgrade.js";
|
|
8
|
+
await runUpgrade().catch(() => { });
|
|
9
|
+
process.exit(0);
|
|
10
|
+
//# sourceMappingURL=self-upgrade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"self-upgrade.js","sourceRoot":"","sources":["../src/self-upgrade.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,kEAAkE;AAClE,0CAA0C;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,MAAM,UAAU,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;AACnC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { GlobalMachine } from "./global-install.ts";
|
|
2
|
+
/** What an attempt ended in. Attempts that changed nothing leave no record. */
|
|
3
|
+
export type UpgradeRecord = {
|
|
4
|
+
kind: "upgraded" | "refused" | "stale";
|
|
5
|
+
from: string | null;
|
|
6
|
+
to: string;
|
|
7
|
+
warning: string | null;
|
|
8
|
+
at: string;
|
|
9
|
+
/** Set once a session has told the reader. */
|
|
10
|
+
reported?: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare function outcomePath(env?: NodeJS.ProcessEnv): string;
|
|
13
|
+
export declare function readOutcome(env?: NodeJS.ProcessEnv): UpgradeRecord | null;
|
|
14
|
+
export declare function writeOutcome(record: UpgradeRecord, env?: NodeJS.ProcessEnv): boolean;
|
|
15
|
+
/** Whether two plain versions share a major number: no upgrade crosses one. */
|
|
16
|
+
export declare function sameMajor(a: string, b: string): boolean;
|
|
17
|
+
export type UpgradeOptions = {
|
|
18
|
+
env?: NodeJS.ProcessEnv;
|
|
19
|
+
machine?: GlobalMachine;
|
|
20
|
+
/** The version running; this package's own when absent. */
|
|
21
|
+
current?: string | null;
|
|
22
|
+
/** A fresh registry answer, never the cache: a stale cache once downgraded an install. */
|
|
23
|
+
latest?: () => Promise<string | null>;
|
|
24
|
+
};
|
|
25
|
+
/** Returns the record it wrote, or null when it changed nothing or failed. */
|
|
26
|
+
export declare function runUpgrade(options?: UpgradeOptions): Promise<UpgradeRecord | null>;
|
package/dist/upgrade.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// The upgrade a detached child performs, and the record it leaves for the next
|
|
2
|
+
// session (docs/reference/update-check.md, "Upgrade an existing global").
|
|
3
|
+
//
|
|
4
|
+
// `src/self-upgrade.ts` is the entry point; the logic lives here so a test can
|
|
5
|
+
// drive it with a fake machine. The child only ever upgrades a global install
|
|
6
|
+
// that already exists, through `syncGlobalInstall`, to a release newer than the
|
|
7
|
+
// one running and inside the same major version. It prints nothing and fails
|
|
8
|
+
// open: any error ends it with no record.
|
|
9
|
+
//
|
|
10
|
+
// Static imports only, and no dynamic `import()` after the install starts: the
|
|
11
|
+
// package manager replaces this package's own files while the child runs.
|
|
12
|
+
import fs from "node:fs";
|
|
13
|
+
import path from "node:path";
|
|
14
|
+
import { configDir } from "./auth/credentials.js";
|
|
15
|
+
import { realMachine, syncGlobalInstall } from "./global-install.js";
|
|
16
|
+
import { writeAtomic } from "./hook/reuse.js";
|
|
17
|
+
import { currentVersion, fetchLatest, inCi, isNewer, suppressed } from "./update.js";
|
|
18
|
+
export function outcomePath(env = process.env) {
|
|
19
|
+
return path.join(configDir(env), "self-upgrade.json");
|
|
20
|
+
}
|
|
21
|
+
export function readOutcome(env = process.env) {
|
|
22
|
+
try {
|
|
23
|
+
const parsed = JSON.parse(fs.readFileSync(outcomePath(env), "utf8"));
|
|
24
|
+
const kind = parsed?.kind;
|
|
25
|
+
if (kind !== "upgraded" && kind !== "refused" && kind !== "stale")
|
|
26
|
+
return null;
|
|
27
|
+
if (typeof parsed.to !== "string" || typeof parsed.at !== "string")
|
|
28
|
+
return null;
|
|
29
|
+
return {
|
|
30
|
+
kind,
|
|
31
|
+
from: typeof parsed.from === "string" ? parsed.from : null,
|
|
32
|
+
to: parsed.to,
|
|
33
|
+
warning: typeof parsed.warning === "string" ? parsed.warning : null,
|
|
34
|
+
at: parsed.at,
|
|
35
|
+
...(parsed.reported === true ? { reported: true } : {}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export function writeOutcome(record, env = process.env) {
|
|
43
|
+
return writeAtomic(outcomePath(env), `${JSON.stringify(record, null, 2)}\n`);
|
|
44
|
+
}
|
|
45
|
+
/** Whether two plain versions share a major number: no upgrade crosses one. */
|
|
46
|
+
export function sameMajor(a, b) {
|
|
47
|
+
const major = (value) => /^(\d+)\.\d+\.\d+$/.exec(value.trim())?.[1] ?? null;
|
|
48
|
+
const left = major(a);
|
|
49
|
+
return left !== null && left === major(b);
|
|
50
|
+
}
|
|
51
|
+
/** Returns the record it wrote, or null when it changed nothing or failed. */
|
|
52
|
+
export async function runUpgrade(options = {}) {
|
|
53
|
+
try {
|
|
54
|
+
const env = options.env ?? process.env;
|
|
55
|
+
if (suppressed(env) || inCi(env))
|
|
56
|
+
return null;
|
|
57
|
+
const current = options.current === undefined ? currentVersion() : options.current;
|
|
58
|
+
if (!current)
|
|
59
|
+
return null;
|
|
60
|
+
const fresh = await (options.latest ?? (() => fetchLatest()))();
|
|
61
|
+
if (!fresh || !isNewer(fresh, current) || !sameMajor(fresh, current))
|
|
62
|
+
return null;
|
|
63
|
+
const outcome = syncGlobalInstall({
|
|
64
|
+
target: fresh,
|
|
65
|
+
say: () => { },
|
|
66
|
+
env,
|
|
67
|
+
...(options.machine ? { machine: options.machine } : {}),
|
|
68
|
+
});
|
|
69
|
+
if (outcome.kind !== "upgraded" && outcome.kind !== "refused" && outcome.kind !== "stale")
|
|
70
|
+
return null;
|
|
71
|
+
const record = {
|
|
72
|
+
kind: outcome.kind,
|
|
73
|
+
from: outcome.kind === "stale" ? (outcome.version ?? current) : outcome.from,
|
|
74
|
+
to: fresh,
|
|
75
|
+
warning: outcome.warning,
|
|
76
|
+
at: new Date().toISOString(),
|
|
77
|
+
reported: false,
|
|
78
|
+
};
|
|
79
|
+
writeOutcome(record, env);
|
|
80
|
+
return record;
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=upgrade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrade.js","sourceRoot":"","sources":["../src/upgrade.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,0EAA0E;AAC1E,EAAE;AACF,+EAA+E;AAC/E,8EAA8E;AAC9E,gFAAgF;AAChF,6EAA6E;AAC7E,0CAA0C;AAC1C,EAAE;AACF,+EAA+E;AAC/E,0EAA0E;AAE1E,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MA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ent_cache_version": 2
|
|
@@ -115,11 +115,11 @@
|
|
|
115
115
|
"zod": "^3.23.0"
|
|
116
116
|
},
|
|
117
117
|
"optionalDependencies": {
|
|
118
|
-
"@carrick-tools/cli-darwin-arm64": "0.3.
|
|
119
|
-
"@carrick-tools/cli-darwin-x64": "0.3.
|
|
120
|
-
"@carrick-tools/cli-linux-arm64": "0.3.
|
|
121
|
-
"@carrick-tools/cli-linux-x64": "0.3.
|
|
122
|
-
"@carrick-tools/cli-win32-x64": "0.3.
|
|
118
|
+
"@carrick-tools/cli-darwin-arm64": "0.3.151",
|
|
119
|
+
"@carrick-tools/cli-darwin-x64": "0.3.151",
|
|
120
|
+
"@carrick-tools/cli-linux-arm64": "0.3.151",
|
|
121
|
+
"@carrick-tools/cli-linux-x64": "0.3.151",
|
|
122
|
+
"@carrick-tools/cli-win32-x64": "0.3.151"
|
|
123
123
|
},
|
|
124
124
|
"devDependencies": {
|
|
125
125
|
"@types/node": "^24.13.3"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "carrick",
|
|
3
3
|
"description": "Claude Code plugin for Carrick, which indexes TypeScript codebases across service and repository boundaries. After each edit it adds the file's routes, calls, and cross-service type mismatches to the session, and it registers Carrick's language server. It pairs with the Carrick MCP server, which lets agents search functions by intent rather than name.",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.151",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Carrick",
|
|
7
7
|
"email": "hello@carrick.tools"
|
|
@@ -70,6 +70,13 @@ export interface ResolvedAnchor {
|
|
|
70
70
|
* module setting maps back to the source and, in the stub, to its
|
|
71
71
|
* declaration.
|
|
72
72
|
*/
|
|
73
|
+
/**
|
|
74
|
+
* The absolute path of an anchor's `source_file`. The scanner sends a file
|
|
75
|
+
* outside the service root as an absolute path; `path.join` would nest it
|
|
76
|
+
* under the root, so a source file resolves with `path.resolve`: absolute
|
|
77
|
+
* stays absolute, relative is taken from the root.
|
|
78
|
+
*/
|
|
79
|
+
export declare function resolveSourceFile(repoRoot: string, sourceFile: string): string;
|
|
73
80
|
export declare function entryRelativeSpecifier(entryDir: string, repoRoot: string, sourceFile: string, resolveFromEntry?: (specifier: string) => string | undefined): string;
|
|
74
81
|
export declare function moduleExport(checker: ts.TypeChecker, sourceFile: ts.SourceFile, name: string): ts.Symbol | undefined;
|
|
75
82
|
/**
|
|
@@ -27,8 +27,17 @@ import { unresolvedAtAnchor, unresolvedSpecifiersReachableFrom, } from './unreso
|
|
|
27
27
|
* module setting maps back to the source and, in the stub, to its
|
|
28
28
|
* declaration.
|
|
29
29
|
*/
|
|
30
|
+
/**
|
|
31
|
+
* The absolute path of an anchor's `source_file`. The scanner sends a file
|
|
32
|
+
* outside the service root as an absolute path; `path.join` would nest it
|
|
33
|
+
* under the root, so a source file resolves with `path.resolve`: absolute
|
|
34
|
+
* stays absolute, relative is taken from the root.
|
|
35
|
+
*/
|
|
36
|
+
export function resolveSourceFile(repoRoot, sourceFile) {
|
|
37
|
+
return path.resolve(repoRoot, sourceFile);
|
|
38
|
+
}
|
|
30
39
|
export function entryRelativeSpecifier(entryDir, repoRoot, sourceFile, resolveFromEntry) {
|
|
31
|
-
const target =
|
|
40
|
+
const target = resolveSourceFile(repoRoot, sourceFile);
|
|
32
41
|
const from = (file) => {
|
|
33
42
|
const rel = path.relative(entryDir, file).split(path.sep).join('/');
|
|
34
43
|
return rel.startsWith('.') ? rel : `./${rel}`;
|
|
@@ -114,7 +123,7 @@ export function resolveAnchor(program, request, args) {
|
|
|
114
123
|
...(unresolved ? { unresolved } : {}),
|
|
115
124
|
};
|
|
116
125
|
}
|
|
117
|
-
const sourceAbs =
|
|
126
|
+
const sourceAbs = resolveSourceFile(args.repoRoot, request.source_file);
|
|
118
127
|
const sourceFile = program.getSourceFile(sourceAbs);
|
|
119
128
|
if (!sourceFile) {
|
|
120
129
|
return demote(`source file not in program: ${request.source_file}`);
|
|
@@ -439,7 +448,7 @@ function mergeUnresolved(atAnchor, substitutedPaths, specifiers) {
|
|
|
439
448
|
function unresolvedSpecifiersForLiteral(program, sourceFileRel, repoRoot) {
|
|
440
449
|
if (!sourceFileRel)
|
|
441
450
|
return [];
|
|
442
|
-
const sourceFile = program.getSourceFile(
|
|
451
|
+
const sourceFile = program.getSourceFile(resolveSourceFile(repoRoot, sourceFileRel));
|
|
443
452
|
return sourceFile ? unresolvedSpecifiersReachableFrom(program, sourceFile) : [];
|
|
444
453
|
}
|
|
445
454
|
/** `undeclaredNamesIn` over type text rather than a built node. */
|
|
@@ -492,7 +501,7 @@ function substituteUndeclaredNamesInText(text, program, destination) {
|
|
|
492
501
|
function qualifyNamesFromSource(text, program, sourceFileRel, printed, args) {
|
|
493
502
|
if (!sourceFileRel)
|
|
494
503
|
return undefined;
|
|
495
|
-
const source = program.getSourceFile(
|
|
504
|
+
const source = program.getSourceFile(resolveSourceFile(args.repoRoot, sourceFileRel));
|
|
496
505
|
const parsed = parseLiteralAnchor(text);
|
|
497
506
|
if (!source || !parsed)
|
|
498
507
|
return undefined;
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
*/
|
|
34
34
|
import { decisiveAssignmentLine, unwidenedAliasOf, } from './check-probe.js';
|
|
35
35
|
import { scrubDiagnostic, scrubPaths } from './check-scrub.js';
|
|
36
|
-
import {
|
|
36
|
+
import { onlyDeclaredOpenMembers } from './deep-walk.js';
|
|
37
37
|
import { describeFieldReport, fieldReportNotes, } from './check-fields.js';
|
|
38
38
|
const PRIMARY_RE = /^(?<file>(?:[a-zA-Z]:)?[^(]*?)\((?<line>\d+),(?<col>\d+)\): error TS(?<code>\d+): (?<msg>.*)$/;
|
|
39
39
|
/** Parse `tsc --pretty false` output into structured diagnostics. */
|
|
@@ -462,7 +462,9 @@ function factness(input, strict = false) {
|
|
|
462
462
|
for (const side of ['sent', 'expected']) {
|
|
463
463
|
// Open members only (carrick#2591): the closed members were judged and an
|
|
464
464
|
// open one is never a mismatch, so the verdict is a fact about the type.
|
|
465
|
-
|
|
465
|
+
// A declared `unknown` is open on the receiving side alone.
|
|
466
|
+
if (!strict &&
|
|
467
|
+
onlyDeclaredOpenMembers(findings[side], side === 'expected', findings[side === 'sent' ? 'expected' : 'sent']))
|
|
466
468
|
continue;
|
|
467
469
|
const first = findings[side][0];
|
|
468
470
|
if (!first)
|
|
@@ -25,7 +25,7 @@ import { scrubPaths } from './check-scrub.js';
|
|
|
25
25
|
import { assembleWorkspace, writeProbes, } from './check-workspace.js';
|
|
26
26
|
import { buildPoisonIndexes } from './check-poison.js';
|
|
27
27
|
import { openProbeProgram, probeDeepFindings } from './check-deep.js';
|
|
28
|
-
import {
|
|
28
|
+
import { onlyDeclaredOpenMembers } from './deep-walk.js';
|
|
29
29
|
import { pairFieldReports } from './check-fields.js';
|
|
30
30
|
import { pairDispatchUnions } from './check-union.js';
|
|
31
31
|
function runProcess(command, args, cwd, env, limits) {
|
|
@@ -669,9 +669,13 @@ function deepDecayOf(plan, aliasRecords) {
|
|
|
669
669
|
// pre-gate reads, exactly as when the walk stopped at the first hit.
|
|
670
670
|
const findings = record?.any_provenance ?? [];
|
|
671
671
|
// An `any` the source declares under a named member is an open member
|
|
672
|
-
// (carrick#2591)
|
|
673
|
-
//
|
|
674
|
-
|
|
672
|
+
// (carrick#2591), and so is an `unknown` on the side that receives the
|
|
673
|
+
// payload, or one the receiving side also declares at the same path: the pair is probed, and the compiler judges the closed members.
|
|
674
|
+
// Anything else on the record keeps the pair out of the probe.
|
|
675
|
+
const other = side === 'producer' ? 'consumer' : 'producer';
|
|
676
|
+
const otherEndpoint = plan.spec[other];
|
|
677
|
+
const counterpart = aliasRecords.get(otherEndpoint.service_name)?.get(otherEndpoint.alias)?.any_provenance ?? [];
|
|
678
|
+
if (onlyDeclaredOpenMembers(findings, side === plan.direction.expected, counterpart))
|
|
675
679
|
continue;
|
|
676
680
|
const finding = findings[0];
|
|
677
681
|
if (finding) {
|
|
@@ -93,20 +93,26 @@ export declare function isErrorPlaceholder(t: ts.Type): boolean;
|
|
|
93
93
|
*/
|
|
94
94
|
export declare function pathNamesAMember(path: string): boolean;
|
|
95
95
|
/**
|
|
96
|
-
* True when every finding is
|
|
97
|
-
* member
|
|
96
|
+
* True when every finding is a top type the SOURCE declares under a named
|
|
97
|
+
* member: an OPEN member (carrick#2591). The policy: an open member is never
|
|
98
98
|
* a mismatch, and the closed members are judged as for a fully typed pair.
|
|
99
99
|
* `any` accepts and supplies every shape in the assignment the probe makes, so
|
|
100
100
|
* the compiler already judges only the closed members.
|
|
101
101
|
*
|
|
102
|
+
* `unknown` is open only on the side that RECEIVES the payload
|
|
103
|
+
* (`receiving`): any type is assignable to `unknown`, so no mismatch can hide
|
|
104
|
+
* there. On the sending side `unknown` rejects a narrower receiver, so it
|
|
105
|
+
* would read as a mismatch the policy forbids and stays a gate, except where
|
|
106
|
+
* the `counterpart` (the receiving side's findings) declares a top type at the
|
|
107
|
+
* same path: anything is assignable there.
|
|
108
|
+
*
|
|
102
109
|
* Nothing else qualifies. A callable's return (`getData()`) is no data
|
|
103
|
-
* member.
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* walk's cap may have stopped listing, so it cannot vouch for every position.
|
|
110
|
+
* member. A `budget_exhausted` sentinel, a root top type and a top type an
|
|
111
|
+
* unresolved import left say nothing about the author's intent. A list as long
|
|
112
|
+
* as the walk's cap may have stopped listing, so it cannot vouch for every
|
|
113
|
+
* position.
|
|
108
114
|
*/
|
|
109
|
-
export declare function
|
|
115
|
+
export declare function onlyDeclaredOpenMembers(findings: readonly TypeProvenance[], receiving: boolean, counterpart?: readonly TypeProvenance[]): boolean;
|
|
110
116
|
/** What an anchor's SOURCE program could not resolve (carrick#1164). */
|
|
111
117
|
export interface UnresolvedAtAnchor {
|
|
112
118
|
/** Member paths holding the unresolved-reference placeholder. */
|
|
@@ -290,23 +290,40 @@ export function pathNamesAMember(path) {
|
|
|
290
290
|
return false;
|
|
291
291
|
}
|
|
292
292
|
/**
|
|
293
|
-
* True when
|
|
294
|
-
*
|
|
293
|
+
* True when the other side declares `unknown` or `any` at exactly `path`
|
|
294
|
+
* (the same member, `[index]` element or nested member named on both sides).
|
|
295
|
+
* Anything is assignable there, so a sent `unknown` cannot mismatch. A list
|
|
296
|
+
* at the walk's cap may have stopped listing, so it vouches for nothing.
|
|
297
|
+
*/
|
|
298
|
+
function counterpartDeclaresTopAt(counterpart, path) {
|
|
299
|
+
return (counterpart.length < MAX_DEEP_FINDINGS &&
|
|
300
|
+
counterpart.some((c) => (c.kind === 'any' || c.kind === 'unknown') && c.reason === 'declared' && c.path === path));
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* True when every finding is a top type the SOURCE declares under a named
|
|
304
|
+
* member: an OPEN member (carrick#2591). The policy: an open member is never
|
|
295
305
|
* a mismatch, and the closed members are judged as for a fully typed pair.
|
|
296
306
|
* `any` accepts and supplies every shape in the assignment the probe makes, so
|
|
297
307
|
* the compiler already judges only the closed members.
|
|
298
308
|
*
|
|
309
|
+
* `unknown` is open only on the side that RECEIVES the payload
|
|
310
|
+
* (`receiving`): any type is assignable to `unknown`, so no mismatch can hide
|
|
311
|
+
* there. On the sending side `unknown` rejects a narrower receiver, so it
|
|
312
|
+
* would read as a mismatch the policy forbids and stays a gate, except where
|
|
313
|
+
* the `counterpart` (the receiving side's findings) declares a top type at the
|
|
314
|
+
* same path: anything is assignable there.
|
|
315
|
+
*
|
|
299
316
|
* Nothing else qualifies. A callable's return (`getData()`) is no data
|
|
300
|
-
* member.
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* walk's cap may have stopped listing, so it cannot vouch for every position.
|
|
317
|
+
* member. A `budget_exhausted` sentinel, a root top type and a top type an
|
|
318
|
+
* unresolved import left say nothing about the author's intent. A list as long
|
|
319
|
+
* as the walk's cap may have stopped listing, so it cannot vouch for every
|
|
320
|
+
* position.
|
|
305
321
|
*/
|
|
306
|
-
export function
|
|
322
|
+
export function onlyDeclaredOpenMembers(findings, receiving, counterpart = []) {
|
|
307
323
|
return (findings.length > 0 &&
|
|
308
324
|
findings.length < MAX_DEEP_FINDINGS &&
|
|
309
|
-
findings.every((f) => f.kind === 'any'
|
|
325
|
+
findings.every((f) => (f.kind === 'any' ||
|
|
326
|
+
(f.kind === 'unknown' && (receiving || counterpartDeclaresTopAt(counterpart, f.path)))) &&
|
|
310
327
|
f.reason === 'declared' &&
|
|
311
328
|
pathNamesAMember(f.path) &&
|
|
312
329
|
!f.path.includes('()')));
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
import ts from 'typescript';
|
|
31
31
|
import * as fs from 'node:fs';
|
|
32
32
|
import * as path from 'node:path';
|
|
33
|
-
import { entryRelativeSpecifier, resolveAnchor } from './anchors.js';
|
|
33
|
+
import { entryRelativeSpecifier, resolveAnchor, resolveSourceFile } from './anchors.js';
|
|
34
34
|
import { findAugmentationFiles } from './augmentations.js';
|
|
35
35
|
import { installedVersions, lockfileVersions } from './lockfile.js';
|
|
36
36
|
import { installedResolutionEdges, RESOLUTION_FILE } from './resolution-edges.js';
|
|
@@ -513,6 +513,7 @@ export function captureStub(opts) {
|
|
|
513
513
|
bareCheckout,
|
|
514
514
|
repoRoot: dependencyRoot,
|
|
515
515
|
compilerHost,
|
|
516
|
+
outsideSources: written.outsideSources,
|
|
516
517
|
});
|
|
517
518
|
let aliases;
|
|
518
519
|
let secondAliases;
|
|
@@ -791,6 +792,7 @@ function writeStub(surface, stubDir, ctx) {
|
|
|
791
792
|
pinned,
|
|
792
793
|
unpinned,
|
|
793
794
|
installs: rewritten.installs,
|
|
795
|
+
outsideSources: Object.fromEntries([...placed.outside].map(([source, rel]) => [path.join(typesDir, rel), `${source}.ts`])),
|
|
794
796
|
};
|
|
795
797
|
}
|
|
796
798
|
/**
|
|
@@ -1215,7 +1217,7 @@ function resolveAnchors(opts, parsed, ctx, deno, owner) {
|
|
|
1215
1217
|
ctx.progress('program', 'building the program the anchors are read in');
|
|
1216
1218
|
const anchorSources = [
|
|
1217
1219
|
...new Set(opts.anchors
|
|
1218
|
-
.flatMap((a) => (a.source_file ? [
|
|
1220
|
+
.flatMap((a) => (a.source_file ? [resolveSourceFile(ctx.repoRoot, a.source_file)] : []))),
|
|
1219
1221
|
].filter((f) => fs.existsSync(f));
|
|
1220
1222
|
const options = sidecarCompilerOptions({
|
|
1221
1223
|
...parsed.options,
|
|
@@ -56,6 +56,13 @@ export interface SelfCheckArgs {
|
|
|
56
56
|
/** Producer repo root; its node_modules (if any) backs resolution. */
|
|
57
57
|
repoRoot: string;
|
|
58
58
|
compilerHost?: (options: ts.CompilerOptions) => ts.CompilerHost;
|
|
59
|
+
/**
|
|
60
|
+
* Absolute stub path of each declaration emitted for a source outside the
|
|
61
|
+
* service's rootDir -> that source's own path. A bare specifier such a
|
|
62
|
+
* declaration names that the stub's links do not reach is resolved from the
|
|
63
|
+
* source's place in the checkout, as the compiler resolved it at emit.
|
|
64
|
+
*/
|
|
65
|
+
outsideSources?: Readonly<Record<string, string>>;
|
|
59
66
|
}
|
|
60
67
|
/** The records of each surface, in `args.surfaces` order. */
|
|
61
68
|
export declare function selfCheckStub(args: SelfCheckArgs): CaptureAliasRecord[][];
|