@astryxdesign/cli 0.7.8 → 0.7.9-canary.0236bb8
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/api/discover/_adapter.d.mts +1 -1
- package/api/docs/_adapter.d.mts +8 -2
- package/api/docs/_adapter.mjs +10 -4
- package/api/docs/detail/section/section.d.mts +5 -2
- package/api/docs/detail/section/section.mjs +6 -2
- package/api/docs/docs.mjs +7 -1
- package/api/search/_adapter.d.mts +3 -1
- package/api/search/_adapter.mjs +12 -2
- package/api/search/_candidate-score.mjs +25 -23
- package/api/search/_main-searcher.mjs +1 -1
- package/api/search/_result.d.mts +5 -5
- package/api/search/_words.d.mts +44 -7
- package/api/search/_words.mjs +113 -21
- package/api/search/search.d.mts +4 -2
- package/api/search/search.mjs +9 -8
- package/api/swizzle/_adapter.d.mts +10 -0
- package/api/swizzle/_adapter.mjs +24 -1
- package/api/swizzle/copy/copy.mjs +9 -4
- package/api/theme/build/build.d.mts +26 -1
- package/api/theme/build/build.mjs +71 -20
- package/api/theme/build/core-interception.d.mts +2 -1
- package/api/theme/build/core-interception.mjs +23 -5
- package/assets/discover/official-packages.json +4 -0
- package/assets/docs/tree/calendar-systems.doc.mjs +146 -0
- package/assets/docs/tree/calendars.doc.mjs +46 -0
- package/assets/docs/tree/i18n-calendars.doc.mjs +51 -0
- package/assets/docs/tree/internationalization.doc.mjs +3 -3
- package/assets/docs/tree/tokens-color.doc.mjs +1 -1
- package/assets/templates/blocks/components/Hooks/useClickableContainerHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useClickableContainerHookUsage.tsx +67 -0
- package/assets/templates/blocks/components/Hooks/useImageModeHookUsage.doc.mjs +14 -0
- package/assets/templates/blocks/components/Hooks/useImageModeHookUsage.tsx +55 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipMetricDefinitions.doc.mjs +14 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipMetricDefinitions.tsx +46 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipPermissionNotes.doc.mjs +14 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipPermissionNotes.tsx +41 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipShowcase.doc.mjs +13 -0
- package/assets/templates/blocks/components/InfoTip/InfoTipShowcase.tsx +24 -0
- package/assets/templates/blocks/components/PowerSearch/PowerSearchContentSearch.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchFullFeatured.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchPresetFilters.tsx +8 -7
- package/assets/templates/blocks/components/PowerSearch/PowerSearchSearchWithTable.tsx +12 -10
- package/assets/templates/blocks/components/PowerSearch/PowerSearchShowcase.tsx +8 -7
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerClear.tsx +2 -2
- package/assets/templates/blocks/components/Tokenizer/TokenizerCreatable.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerEndContent.tsx +0 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.doc.mjs +2 -1
- package/assets/templates/blocks/components/Tokenizer/TokenizerOverflow.tsx +0 -2
- package/assets/templates/pages/table-inbox/page.tsx +11 -8
- package/assets/templates/pages/work-item-detail/page.tsx +6 -2
- package/assets/theme.template.ts +1 -1
- package/authoring/debug/parse.d.mts +2 -2
- package/clients/cli/commands/ensure-core-built.mjs +399 -43
- package/clients/cli/index.mjs +11 -6
- package/foundation/agent-docs/agent-docs-target.d.mts +49 -0
- package/foundation/agent-docs/agent-docs-target.mjs +201 -0
- package/foundation/agent-docs/agent-docs.d.mts +1 -38
- package/foundation/agent-docs/agent-docs.mjs +16 -181
- package/foundation/config/config-path.d.mts +13 -0
- package/foundation/config/config-path.mjs +42 -0
- package/foundation/config/project.d.mts +1 -10
- package/foundation/config/project.mjs +31 -35
- package/foundation/discovery/component-discovery.mjs +39 -4
- package/foundation/discovery/component-loader.d.mts +1 -1
- package/foundation/discovery/icon-set-paths.d.mts +18 -0
- package/foundation/discovery/icon-set-paths.mjs +23 -0
- package/foundation/discovery/icon-set-writer.d.mts +2 -7
- package/foundation/discovery/icon-set-writer.mjs +3 -12
- package/foundation/env/search-path.d.mts +12 -0
- package/foundation/env/search-path.mjs +71 -43
- package/foundation/fs/module-loader.d.mts +2 -8
- package/foundation/fs/module-loader.mjs +3 -12
- package/foundation/fs/present-files.d.mts +11 -0
- package/foundation/fs/present-files.mjs +25 -0
- package/foundation/integrations/autolink.d.mts +2 -21
- package/foundation/integrations/autolink.mjs +6 -42
- package/foundation/integrations/contribution-fixes.mjs +26 -3
- package/foundation/integrations/contribution-inventory.mjs +1 -1
- package/foundation/integrations/installed-package.d.mts +36 -0
- package/foundation/integrations/installed-package.mjs +57 -0
- package/foundation/integrations/integrations.d.mts +3 -75
- package/foundation/integrations/integrations.mjs +3 -16
- package/foundation/integrations/manifest-paths.d.mts +13 -0
- package/foundation/integrations/manifest-paths.mjs +31 -0
- package/foundation/integrations/manifest-writer.d.mts +3 -4
- package/foundation/integrations/manifest-writer.mjs +5 -3
- package/foundation/release/cache.d.mts +11 -4
- package/foundation/release/cache.mjs +15 -7
- package/foundation/runtime/locked-versions.mjs +1 -1
- package/foundation/runtime/package-set.mjs +1 -1
- package/foundation/text/levenshtein.d.mts +4 -1
- package/foundation/text/levenshtein.mjs +44 -1
- package/package.json +9 -9
- package/api/swizzle/_github.d.mts +0 -8
- package/api/swizzle/_github.mjs +0 -22
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file agent-docs-target.mjs
|
|
5
|
+
* @input The folder a run starts in, the home folder, and the package.json
|
|
6
|
+
* files and repository markers above the folder
|
|
7
|
+
* @output AgentDocsHomeError, assertAgentDocsTarget, resolveAgentDocsRoot and
|
|
8
|
+
* agentDocsTargetDir, with the realDir and REPOSITORY_MARKERS helpers
|
|
9
|
+
* @position The folder agent docs go to. It imports node builtins only, so the
|
|
10
|
+
* per-command setup nudge (clients/cli/index.mjs) loads it without
|
|
11
|
+
* agent-docs.mjs's discovery and config. agent-docs.mjs re-exports it.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import * as fs from 'node:fs';
|
|
15
|
+
import * as os from 'node:os';
|
|
16
|
+
import * as path from 'node:path';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Thrown when agent docs would be written into the home folder, or into a
|
|
20
|
+
* settings folder in it such as `~/.gemini` outside a project. Agents read the
|
|
21
|
+
* files there (for example `~/.claude/CLAUDE.md` or `~/.gemini/GEMINI.md`) in
|
|
22
|
+
* every project, so a project's version-pinned block never goes there. Removal
|
|
23
|
+
* stays allowed.
|
|
24
|
+
*/
|
|
25
|
+
export class AgentDocsHomeError extends Error {
|
|
26
|
+
/** @param {string} dir */
|
|
27
|
+
constructor(dir) {
|
|
28
|
+
super(
|
|
29
|
+
`Agent docs are not written into the home folder, or into a settings folder in it outside a project (${dir}): agents read the files there in every project. Run init inside a project folder.`,
|
|
30
|
+
);
|
|
31
|
+
this.name = 'AgentDocsHomeError';
|
|
32
|
+
/** The refused folder. */
|
|
33
|
+
this.dir = dir;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* `p` resolved, through symlinks when it exists.
|
|
39
|
+
* @param {string} p
|
|
40
|
+
* @returns {string}
|
|
41
|
+
*/
|
|
42
|
+
export function realDir(p) {
|
|
43
|
+
try {
|
|
44
|
+
return fs.realpathSync(path.resolve(p));
|
|
45
|
+
} catch {
|
|
46
|
+
return path.resolve(p);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* `dir` relative to the home folder, compared without symlinks (and without
|
|
52
|
+
* case on Windows). null when there is no home folder.
|
|
53
|
+
* @param {string} dir
|
|
54
|
+
* @returns {string | null}
|
|
55
|
+
*/
|
|
56
|
+
function relativeToHome(dir) {
|
|
57
|
+
let home;
|
|
58
|
+
try {
|
|
59
|
+
home = os.homedir();
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
if (!home) return null;
|
|
64
|
+
/** @param {string} p */
|
|
65
|
+
const fold = p => (process.platform === 'win32' ? p.toLowerCase() : p);
|
|
66
|
+
return path.relative(fold(realDir(home)), fold(realDir(dir)));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Whether `dir` is the home folder.
|
|
71
|
+
* @param {string} dir
|
|
72
|
+
* @returns {boolean}
|
|
73
|
+
*/
|
|
74
|
+
function isHomeFolder(dir) {
|
|
75
|
+
return relativeToHome(dir) === '';
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Whether agent docs stay out of `dir`: the home folder, or a folder in a
|
|
80
|
+
* settings folder of it (a folder of the home folder whose name starts with a
|
|
81
|
+
* dot, such as `~/.gemini` or `~/.claude`) that belongs to no project there.
|
|
82
|
+
* Agents read the files at the top of a settings folder in every project, so
|
|
83
|
+
* the settings folder itself is never a project, even with a package.json. A
|
|
84
|
+
* folder below it with a package.json at or above it is a project, such as an
|
|
85
|
+
* agent worktree in `~/.codex/worktrees/<id>/<repo>`.
|
|
86
|
+
* @param {string} dir
|
|
87
|
+
* @returns {boolean}
|
|
88
|
+
*/
|
|
89
|
+
function isHomeOrSettingsFolder(dir) {
|
|
90
|
+
const rel = relativeToHome(dir);
|
|
91
|
+
if (rel == null) return false;
|
|
92
|
+
if (rel === '') return true;
|
|
93
|
+
if (rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
const parts = rel.split(path.sep);
|
|
97
|
+
if (!parts[0].startsWith('.')) return false;
|
|
98
|
+
// Look for a package.json from `dir` up to, not including, the settings folder.
|
|
99
|
+
let current = realDir(dir);
|
|
100
|
+
for (let depth = parts.length; depth > 1; depth--) {
|
|
101
|
+
if (fs.existsSync(path.join(current, 'package.json'))) return false;
|
|
102
|
+
current = path.dirname(current);
|
|
103
|
+
}
|
|
104
|
+
return true;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Throw {@link AgentDocsHomeError} when `targetDir` is the home folder, or a
|
|
109
|
+
* settings folder in it outside a project.
|
|
110
|
+
* @param {string} targetDir
|
|
111
|
+
*/
|
|
112
|
+
export function assertAgentDocsTarget(targetDir) {
|
|
113
|
+
if (isHomeOrSettingsFolder(targetDir))
|
|
114
|
+
throw new AgentDocsHomeError(realDir(targetDir));
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Folders that mark a repository root; the project search stops there. */
|
|
118
|
+
export const REPOSITORY_MARKERS = ['.git', '.hg', '.sl'];
|
|
119
|
+
|
|
120
|
+
/** Dependency fields where a project declares the Astryx packages it uses. */
|
|
121
|
+
const DEPENDENCY_FIELDS = [
|
|
122
|
+
'dependencies',
|
|
123
|
+
'devDependencies',
|
|
124
|
+
'peerDependencies',
|
|
125
|
+
'optionalDependencies',
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* The package.json in `dir`: its parsed content, `null` when it exists but
|
|
130
|
+
* does not parse, or `undefined` when there is none.
|
|
131
|
+
* @param {string} dir
|
|
132
|
+
* @returns {Record<string, unknown> | null | undefined}
|
|
133
|
+
*/
|
|
134
|
+
function readPackageJson(dir) {
|
|
135
|
+
const file = path.join(dir, 'package.json');
|
|
136
|
+
if (!fs.existsSync(file)) return undefined;
|
|
137
|
+
try {
|
|
138
|
+
const parsed = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
139
|
+
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
140
|
+
} catch {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Whether a parsed package.json declares an `@astryxdesign` package.
|
|
147
|
+
* @param {Record<string, unknown> | null} manifest
|
|
148
|
+
* @returns {boolean}
|
|
149
|
+
*/
|
|
150
|
+
function declaresAstryx(manifest) {
|
|
151
|
+
return DEPENDENCY_FIELDS.some(field => {
|
|
152
|
+
const deps = manifest?.[field];
|
|
153
|
+
return (
|
|
154
|
+
deps != null &&
|
|
155
|
+
typeof deps === 'object' &&
|
|
156
|
+
Object.keys(deps).some(name => name.startsWith('@astryxdesign/'))
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The folder a run started in `cwd` writes agent docs to: the nearest folder at
|
|
163
|
+
* or above it whose package.json declares an `@astryxdesign` package, else the
|
|
164
|
+
* nearest folder with any package.json. The search stops at a repository root
|
|
165
|
+
* and never reaches the home folder, so a stray `~/package.json` cannot pull
|
|
166
|
+
* the docs there.
|
|
167
|
+
* @param {string} cwd
|
|
168
|
+
* @returns {string | null} null when no folder it searches has a package.json;
|
|
169
|
+
* init then writes where it runs, as before.
|
|
170
|
+
*/
|
|
171
|
+
export function resolveAgentDocsRoot(cwd) {
|
|
172
|
+
let dir = path.resolve(cwd);
|
|
173
|
+
/** @type {string | null} */
|
|
174
|
+
let nearest = null;
|
|
175
|
+
for (let i = 0; i < 50 && !isHomeFolder(dir); i++) {
|
|
176
|
+
const manifest = readPackageJson(dir);
|
|
177
|
+
if (manifest !== undefined) {
|
|
178
|
+
if (declaresAstryx(manifest)) return dir;
|
|
179
|
+
nearest ??= dir;
|
|
180
|
+
}
|
|
181
|
+
if (
|
|
182
|
+
REPOSITORY_MARKERS.some(marker => fs.existsSync(path.join(dir, marker)))
|
|
183
|
+
)
|
|
184
|
+
break;
|
|
185
|
+
const parent = path.dirname(dir);
|
|
186
|
+
if (parent === dir) break;
|
|
187
|
+
dir = parent;
|
|
188
|
+
}
|
|
189
|
+
return nearest;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The folder `init` run in `cwd` writes the agent docs to: the project root
|
|
194
|
+
* {@link resolveAgentDocsRoot} finds, else `cwd` itself. The one definition
|
|
195
|
+
* that init, its removal, and the per-command setup nudge all use.
|
|
196
|
+
* @param {string} cwd
|
|
197
|
+
* @returns {string}
|
|
198
|
+
*/
|
|
199
|
+
export function agentDocsTargetDir(cwd) {
|
|
200
|
+
return resolveAgentDocsRoot(cwd) ?? cwd;
|
|
201
|
+
}
|
|
@@ -1,31 +1,6 @@
|
|
|
1
1
|
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
2
|
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Throw {@link AgentDocsHomeError} when `targetDir` is the home folder, or a
|
|
6
|
-
* settings folder in it outside a project.
|
|
7
|
-
* @param {string} targetDir
|
|
8
|
-
*/
|
|
9
|
-
export function assertAgentDocsTarget(targetDir: string): void;
|
|
10
|
-
/**
|
|
11
|
-
* The folder a run started in `cwd` writes agent docs to: the nearest folder at
|
|
12
|
-
* or above it whose package.json declares an `@astryxdesign` package, else the
|
|
13
|
-
* nearest folder with any package.json. The search stops at a repository root
|
|
14
|
-
* and never reaches the home folder, so a stray `~/package.json` cannot pull
|
|
15
|
-
* the docs there.
|
|
16
|
-
* @param {string} cwd
|
|
17
|
-
* @returns {string | null} null when no folder it searches has a package.json;
|
|
18
|
-
* init then writes where it runs, as before.
|
|
19
|
-
*/
|
|
20
|
-
export function resolveAgentDocsRoot(cwd: string): string | null;
|
|
21
|
-
/**
|
|
22
|
-
* The folder `init` run in `cwd` writes the agent docs to: the project root
|
|
23
|
-
* {@link resolveAgentDocsRoot} finds, else `cwd` itself. The one definition
|
|
24
|
-
* that init, its removal, and the per-command setup nudge all use.
|
|
25
|
-
* @param {string} cwd
|
|
26
|
-
* @returns {string}
|
|
27
|
-
*/
|
|
28
|
-
export function agentDocsTargetDir(cwd: string): string;
|
|
29
4
|
/**
|
|
30
5
|
* Parse the Astryx version a managed block was generated for, from its header
|
|
31
6
|
* line ("Astryx v1.2.3 · N components"). Returns null when the block predates
|
|
@@ -311,20 +286,8 @@ export function installAgentDocs(targetDir: string, { zh, lang, agent, paths, on
|
|
|
311
286
|
onSkipped?: ((rel: string, reason: string) => void) | undefined;
|
|
312
287
|
refuseEscapes?: boolean | undefined;
|
|
313
288
|
}): string[];
|
|
314
|
-
/**
|
|
315
|
-
* Thrown when agent docs would be written into the home folder, or into a
|
|
316
|
-
* settings folder in it such as `~/.gemini` outside a project. Agents read the
|
|
317
|
-
* files there (for example `~/.claude/CLAUDE.md` or `~/.gemini/GEMINI.md`) in
|
|
318
|
-
* every project, so a project's version-pinned block never goes there. Removal
|
|
319
|
-
* stays allowed.
|
|
320
|
-
*/
|
|
321
|
-
export class AgentDocsHomeError extends Error {
|
|
322
|
-
/** @param {string} dir */
|
|
323
|
-
constructor(dir: string);
|
|
324
|
-
/** The refused folder. */
|
|
325
|
-
dir: string;
|
|
326
|
-
}
|
|
327
289
|
import { discoverAgentDocs } from './agent-doc-state.mjs';
|
|
328
290
|
import { isAstryxInitialized } from './agent-doc-state.mjs';
|
|
329
291
|
import { isAstryxPromptInReach } from './agent-doc-state.mjs';
|
|
330
292
|
export { discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach };
|
|
293
|
+
export { AgentDocsHomeError, agentDocsTargetDir, assertAgentDocsTarget, resolveAgentDocsRoot } from "./agent-docs-target.mjs";
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
|
|
32
32
|
import {spawnSync} from 'node:child_process';
|
|
33
33
|
import * as fs from 'node:fs';
|
|
34
|
-
import * as os from 'node:os';
|
|
35
34
|
import * as path from 'node:path';
|
|
36
35
|
import {findCoreDir, findInstalledPackage, CLI_ROOT} from '../fs/paths.mjs';
|
|
37
36
|
import {assertWithin, PathSafetyError} from '../fs/path-safety.mjs';
|
|
@@ -67,6 +66,12 @@ import {
|
|
|
67
66
|
WORKFLOW_STEPS,
|
|
68
67
|
WORKFLOW_TITLE,
|
|
69
68
|
} from './agent-doc-state.mjs';
|
|
69
|
+
import {
|
|
70
|
+
agentDocsTargetDir,
|
|
71
|
+
assertAgentDocsTarget,
|
|
72
|
+
realDir,
|
|
73
|
+
REPOSITORY_MARKERS,
|
|
74
|
+
} from './agent-docs-target.mjs';
|
|
70
75
|
|
|
71
76
|
// The agent-doc locations, markers, and the setup-state predicates
|
|
72
77
|
// (discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach) are the ONE
|
|
@@ -77,6 +82,16 @@ import {
|
|
|
77
82
|
// keep their `from './agent-docs.mjs'` paths.
|
|
78
83
|
export {discoverAgentDocs, isAstryxInitialized, isAstryxPromptInReach};
|
|
79
84
|
|
|
85
|
+
// The folder the docs go to lives in ./agent-docs-target.mjs, with node
|
|
86
|
+
// builtins only. So the per-command setup nudge loads it without this
|
|
87
|
+
// module's discovery and config. Re-exported here for existing importers.
|
|
88
|
+
export {
|
|
89
|
+
AgentDocsHomeError,
|
|
90
|
+
agentDocsTargetDir,
|
|
91
|
+
assertAgentDocsTarget,
|
|
92
|
+
resolveAgentDocsRoot,
|
|
93
|
+
} from './agent-docs-target.mjs';
|
|
94
|
+
|
|
80
95
|
const MAX_PROJECT_AGENT_DOC_LINES = 32;
|
|
81
96
|
const MANAGED_MARKER_TEXT = /(?:ASTRYX|XDS):(START|END)/u;
|
|
82
97
|
|
|
@@ -321,186 +336,6 @@ function geminiImportsAgentsMd(targetDir) {
|
|
|
321
336
|
);
|
|
322
337
|
}
|
|
323
338
|
|
|
324
|
-
/**
|
|
325
|
-
* Thrown when agent docs would be written into the home folder, or into a
|
|
326
|
-
* settings folder in it such as `~/.gemini` outside a project. Agents read the
|
|
327
|
-
* files there (for example `~/.claude/CLAUDE.md` or `~/.gemini/GEMINI.md`) in
|
|
328
|
-
* every project, so a project's version-pinned block never goes there. Removal
|
|
329
|
-
* stays allowed.
|
|
330
|
-
*/
|
|
331
|
-
export class AgentDocsHomeError extends Error {
|
|
332
|
-
/** @param {string} dir */
|
|
333
|
-
constructor(dir) {
|
|
334
|
-
super(
|
|
335
|
-
`Agent docs are not written into the home folder, or into a settings folder in it outside a project (${dir}): agents read the files there in every project. Run init inside a project folder.`,
|
|
336
|
-
);
|
|
337
|
-
this.name = 'AgentDocsHomeError';
|
|
338
|
-
/** The refused folder. */
|
|
339
|
-
this.dir = dir;
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* `p` resolved, through symlinks when it exists.
|
|
345
|
-
* @param {string} p
|
|
346
|
-
* @returns {string}
|
|
347
|
-
*/
|
|
348
|
-
function realDir(p) {
|
|
349
|
-
try {
|
|
350
|
-
return fs.realpathSync(path.resolve(p));
|
|
351
|
-
} catch {
|
|
352
|
-
return path.resolve(p);
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
* `dir` relative to the home folder, compared without symlinks (and without
|
|
358
|
-
* case on Windows). null when there is no home folder.
|
|
359
|
-
* @param {string} dir
|
|
360
|
-
* @returns {string | null}
|
|
361
|
-
*/
|
|
362
|
-
function relativeToHome(dir) {
|
|
363
|
-
let home;
|
|
364
|
-
try {
|
|
365
|
-
home = os.homedir();
|
|
366
|
-
} catch {
|
|
367
|
-
return null;
|
|
368
|
-
}
|
|
369
|
-
if (!home) return null;
|
|
370
|
-
/** @param {string} p */
|
|
371
|
-
const fold = p => (process.platform === 'win32' ? p.toLowerCase() : p);
|
|
372
|
-
return path.relative(fold(realDir(home)), fold(realDir(dir)));
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Whether `dir` is the home folder.
|
|
377
|
-
* @param {string} dir
|
|
378
|
-
* @returns {boolean}
|
|
379
|
-
*/
|
|
380
|
-
function isHomeFolder(dir) {
|
|
381
|
-
return relativeToHome(dir) === '';
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* Whether agent docs stay out of `dir`: the home folder, or a folder in a
|
|
386
|
-
* settings folder of it (a folder of the home folder whose name starts with a
|
|
387
|
-
* dot, such as `~/.gemini` or `~/.claude`) that belongs to no project there.
|
|
388
|
-
* Agents read the files at the top of a settings folder in every project, so
|
|
389
|
-
* the settings folder itself is never a project, even with a package.json. A
|
|
390
|
-
* folder below it with a package.json at or above it is a project, such as an
|
|
391
|
-
* agent worktree in `~/.codex/worktrees/<id>/<repo>`.
|
|
392
|
-
* @param {string} dir
|
|
393
|
-
* @returns {boolean}
|
|
394
|
-
*/
|
|
395
|
-
function isHomeOrSettingsFolder(dir) {
|
|
396
|
-
const rel = relativeToHome(dir);
|
|
397
|
-
if (rel == null) return false;
|
|
398
|
-
if (rel === '') return true;
|
|
399
|
-
if (rel === '..' || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel)) {
|
|
400
|
-
return false;
|
|
401
|
-
}
|
|
402
|
-
const parts = rel.split(path.sep);
|
|
403
|
-
if (!parts[0].startsWith('.')) return false;
|
|
404
|
-
// Look for a package.json from `dir` up to, not including, the settings folder.
|
|
405
|
-
let current = realDir(dir);
|
|
406
|
-
for (let depth = parts.length; depth > 1; depth--) {
|
|
407
|
-
if (fs.existsSync(path.join(current, 'package.json'))) return false;
|
|
408
|
-
current = path.dirname(current);
|
|
409
|
-
}
|
|
410
|
-
return true;
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Throw {@link AgentDocsHomeError} when `targetDir` is the home folder, or a
|
|
415
|
-
* settings folder in it outside a project.
|
|
416
|
-
* @param {string} targetDir
|
|
417
|
-
*/
|
|
418
|
-
export function assertAgentDocsTarget(targetDir) {
|
|
419
|
-
if (isHomeOrSettingsFolder(targetDir)) throw new AgentDocsHomeError(realDir(targetDir));
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
/** Folders that mark a repository root; the project search stops there. */
|
|
423
|
-
const REPOSITORY_MARKERS = ['.git', '.hg', '.sl'];
|
|
424
|
-
|
|
425
|
-
/** Dependency fields where a project declares the Astryx packages it uses. */
|
|
426
|
-
const DEPENDENCY_FIELDS = [
|
|
427
|
-
'dependencies',
|
|
428
|
-
'devDependencies',
|
|
429
|
-
'peerDependencies',
|
|
430
|
-
'optionalDependencies',
|
|
431
|
-
];
|
|
432
|
-
|
|
433
|
-
/**
|
|
434
|
-
* The package.json in `dir`: its parsed content, `null` when it exists but
|
|
435
|
-
* does not parse, or `undefined` when there is none.
|
|
436
|
-
* @param {string} dir
|
|
437
|
-
* @returns {Record<string, unknown> | null | undefined}
|
|
438
|
-
*/
|
|
439
|
-
function readPackageJson(dir) {
|
|
440
|
-
const file = path.join(dir, 'package.json');
|
|
441
|
-
if (!fs.existsSync(file)) return undefined;
|
|
442
|
-
try {
|
|
443
|
-
const parsed = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
444
|
-
return parsed && typeof parsed === 'object' ? parsed : null;
|
|
445
|
-
} catch {
|
|
446
|
-
return null;
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
/**
|
|
451
|
-
* Whether a parsed package.json declares an `@astryxdesign` package.
|
|
452
|
-
* @param {Record<string, unknown> | null} manifest
|
|
453
|
-
* @returns {boolean}
|
|
454
|
-
*/
|
|
455
|
-
function declaresAstryx(manifest) {
|
|
456
|
-
return DEPENDENCY_FIELDS.some(field => {
|
|
457
|
-
const deps = manifest?.[field];
|
|
458
|
-
return (
|
|
459
|
-
deps != null &&
|
|
460
|
-
typeof deps === 'object' &&
|
|
461
|
-
Object.keys(deps).some(name => name.startsWith('@astryxdesign/'))
|
|
462
|
-
);
|
|
463
|
-
});
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
* The folder a run started in `cwd` writes agent docs to: the nearest folder at
|
|
468
|
-
* or above it whose package.json declares an `@astryxdesign` package, else the
|
|
469
|
-
* nearest folder with any package.json. The search stops at a repository root
|
|
470
|
-
* and never reaches the home folder, so a stray `~/package.json` cannot pull
|
|
471
|
-
* the docs there.
|
|
472
|
-
* @param {string} cwd
|
|
473
|
-
* @returns {string | null} null when no folder it searches has a package.json;
|
|
474
|
-
* init then writes where it runs, as before.
|
|
475
|
-
*/
|
|
476
|
-
export function resolveAgentDocsRoot(cwd) {
|
|
477
|
-
let dir = path.resolve(cwd);
|
|
478
|
-
/** @type {string | null} */
|
|
479
|
-
let nearest = null;
|
|
480
|
-
for (let i = 0; i < 50 && !isHomeFolder(dir); i++) {
|
|
481
|
-
const manifest = readPackageJson(dir);
|
|
482
|
-
if (manifest !== undefined) {
|
|
483
|
-
if (declaresAstryx(manifest)) return dir;
|
|
484
|
-
nearest ??= dir;
|
|
485
|
-
}
|
|
486
|
-
if (REPOSITORY_MARKERS.some(marker => fs.existsSync(path.join(dir, marker)))) break;
|
|
487
|
-
const parent = path.dirname(dir);
|
|
488
|
-
if (parent === dir) break;
|
|
489
|
-
dir = parent;
|
|
490
|
-
}
|
|
491
|
-
return nearest;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
/**
|
|
495
|
-
* The folder `init` run in `cwd` writes the agent docs to: the project root
|
|
496
|
-
* {@link resolveAgentDocsRoot} finds, else `cwd` itself. The one definition
|
|
497
|
-
* that init, its removal, and the per-command setup nudge all use.
|
|
498
|
-
* @param {string} cwd
|
|
499
|
-
* @returns {string}
|
|
500
|
-
*/
|
|
501
|
-
export function agentDocsTargetDir(cwd) {
|
|
502
|
-
return resolveAgentDocsRoot(cwd) ?? cwd;
|
|
503
|
-
}
|
|
504
339
|
|
|
505
340
|
/**
|
|
506
341
|
* Agent tool presets — maps tool names to their file search paths.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// @generated by scripts/sync-api-types.mjs from the JSDoc in foundation/**/*.mjs.
|
|
2
|
+
// DO NOT EDIT — run `pnpm sync:api-types` to regenerate.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Find astryx.config.{ts,mjs,js} as a sibling of the nearest package.json.
|
|
6
|
+
* Returns the absolute path, or null if none is present. Throws if multiple
|
|
7
|
+
* config files exist at that root.
|
|
8
|
+
* @param {string} [startDir]
|
|
9
|
+
* @returns {string|null}
|
|
10
|
+
*/
|
|
11
|
+
export function findConfigPath(startDir?: string): string | null;
|
|
12
|
+
/** Conventional config basenames, in load-precedence order. */
|
|
13
|
+
export const CONFIG_BASENAMES: string[];
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @file config-path.mjs
|
|
5
|
+
* @input The folder a run starts in
|
|
6
|
+
* @output CONFIG_BASENAMES and findConfigPath: the project's Astryx config
|
|
7
|
+
* file, or null
|
|
8
|
+
* @position packages/cli/foundation/config: finds the config without loading
|
|
9
|
+
* project.mjs, so a run in a folder with no config loads none of it.
|
|
10
|
+
* project.mjs re-exports both.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import * as path from 'node:path';
|
|
14
|
+
import {findPackageRoot} from '../fs/paths.mjs';
|
|
15
|
+
import {findPresentFiles} from '../fs/present-files.mjs';
|
|
16
|
+
|
|
17
|
+
/** Conventional config basenames, in load-precedence order. */
|
|
18
|
+
export const CONFIG_BASENAMES = [
|
|
19
|
+
'astryx.config.ts',
|
|
20
|
+
'astryx.config.mjs',
|
|
21
|
+
'astryx.config.js',
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Find astryx.config.{ts,mjs,js} as a sibling of the nearest package.json.
|
|
26
|
+
* Returns the absolute path, or null if none is present. Throws if multiple
|
|
27
|
+
* config files exist at that root.
|
|
28
|
+
* @param {string} [startDir]
|
|
29
|
+
* @returns {string|null}
|
|
30
|
+
*/
|
|
31
|
+
export function findConfigPath(startDir = process.cwd()) {
|
|
32
|
+
const root = findPackageRoot(startDir) ?? startDir;
|
|
33
|
+
const present = findPresentFiles(root, CONFIG_BASENAMES);
|
|
34
|
+
if (present.length > 1) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
`Multiple Astryx config files found in ${root} (${present
|
|
37
|
+
.map(p => path.basename(p))
|
|
38
|
+
.join(', ')}). Keep exactly one.`,
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
return present.length === 1 ? present[0] : null;
|
|
42
|
+
}
|
|
@@ -19,14 +19,6 @@ export function computerIntegrationCandidates(cwd?: string): import("../integrat
|
|
|
19
19
|
* @returns {Promise<import('../integrations/computer-integrations.mjs').ComputerIntegrationCandidate[]>}
|
|
20
20
|
*/
|
|
21
21
|
export function availableComputerIntegrations(cwd: string, installed: Set<string>): Promise<import("../integrations/computer-integrations.mjs").ComputerIntegrationCandidate[]>;
|
|
22
|
-
/**
|
|
23
|
-
* Find astryx.config.{ts,mjs,js} as a sibling of the nearest package.json.
|
|
24
|
-
* Returns the absolute path, or null if none is present. Throws if multiple
|
|
25
|
-
* config files exist at that root.
|
|
26
|
-
* @param {string} [startDir]
|
|
27
|
-
* @returns {string|null}
|
|
28
|
-
*/
|
|
29
|
-
export function findConfigPath(startDir?: string): string | null;
|
|
30
22
|
/**
|
|
31
23
|
* The provider ledger a Project resolved at load: one outcome for every
|
|
32
24
|
* package directory configured, autolinked, or authored. Internal: upgrade
|
|
@@ -41,8 +33,6 @@ export function providerLedgerOf(project: Project): import("../integrations/prov
|
|
|
41
33
|
* `package` that produced it, which Project tracks for routing/dedup.
|
|
42
34
|
* @typedef {import('../integrations/issue').AstryxIntegrationIssue & {package: string}} ProjectIntegrationIssue
|
|
43
35
|
*/
|
|
44
|
-
/** Conventional config basenames, in load-precedence order. */
|
|
45
|
-
export const CONFIG_BASENAMES: string[];
|
|
46
36
|
/** Default issue tracker used when neither config nor integration routes one. */
|
|
47
37
|
export const DEFAULT_ISSUES_URL: "https://github.com/meta/astryx/issues/new";
|
|
48
38
|
/**
|
|
@@ -268,3 +258,4 @@ export type ProjectIntegrationIssue = import("../integrations/issue").AstryxInte
|
|
|
268
258
|
package: string;
|
|
269
259
|
};
|
|
270
260
|
import { DocsCatalog } from '../discovery/docs-discovery.mjs';
|
|
261
|
+
export { CONFIG_BASENAMES, findConfigPath } from "./config-path.mjs";
|
|
@@ -35,7 +35,8 @@
|
|
|
35
35
|
|
|
36
36
|
import * as fs from 'node:fs';
|
|
37
37
|
import * as path from 'node:path';
|
|
38
|
-
import {
|
|
38
|
+
import {loadModuleWithParser} from '../fs/module-loader.mjs';
|
|
39
|
+
import {findConfigPath} from './config-path.mjs';
|
|
39
40
|
import {parseConfig} from '../../authoring/config/parse.mjs';
|
|
40
41
|
import {
|
|
41
42
|
loadIntegrations,
|
|
@@ -105,6 +106,8 @@ import {
|
|
|
105
106
|
configContentHash,
|
|
106
107
|
} from './config-cache.mjs';
|
|
107
108
|
|
|
109
|
+
export {CONFIG_BASENAMES, findConfigPath} from './config-path.mjs';
|
|
110
|
+
|
|
108
111
|
/**
|
|
109
112
|
* Extract a human-readable message from an unknown thrown value.
|
|
110
113
|
* Reproduces the historical `err?.message ?? String(err)` behavior in a
|
|
@@ -321,12 +324,6 @@ function readPackageJson(dir) {
|
|
|
321
324
|
* @typedef {import('../integrations/issue').AstryxIntegrationIssue & {package: string}} ProjectIntegrationIssue
|
|
322
325
|
*/
|
|
323
326
|
|
|
324
|
-
/** Conventional config basenames, in load-precedence order. */
|
|
325
|
-
export const CONFIG_BASENAMES = [
|
|
326
|
-
'astryx.config.ts',
|
|
327
|
-
'astryx.config.mjs',
|
|
328
|
-
'astryx.config.js',
|
|
329
|
-
];
|
|
330
327
|
|
|
331
328
|
/** Default issue tracker used when neither config nor integration routes one. */
|
|
332
329
|
export const DEFAULT_ISSUES_URL =
|
|
@@ -367,25 +364,6 @@ function inheritsIntegrationDebug(projectDir) {
|
|
|
367
364
|
}
|
|
368
365
|
}
|
|
369
366
|
|
|
370
|
-
/**
|
|
371
|
-
* Find astryx.config.{ts,mjs,js} as a sibling of the nearest package.json.
|
|
372
|
-
* Returns the absolute path, or null if none is present. Throws if multiple
|
|
373
|
-
* config files exist at that root.
|
|
374
|
-
* @param {string} [startDir]
|
|
375
|
-
* @returns {string|null}
|
|
376
|
-
*/
|
|
377
|
-
export function findConfigPath(startDir = process.cwd()) {
|
|
378
|
-
const root = findPackageRoot(startDir) ?? startDir;
|
|
379
|
-
const present = findPresentFiles(root, CONFIG_BASENAMES);
|
|
380
|
-
if (present.length > 1) {
|
|
381
|
-
throw new Error(
|
|
382
|
-
`Multiple Astryx config files found in ${root} (${present
|
|
383
|
-
.map(p => path.basename(p))
|
|
384
|
-
.join(', ')}). Keep exactly one.`,
|
|
385
|
-
);
|
|
386
|
-
}
|
|
387
|
-
return present.length === 1 ? present[0] : null;
|
|
388
|
-
}
|
|
389
367
|
|
|
390
368
|
/**
|
|
391
369
|
* The provider ledger each loaded Project resolved, kept off the class so it
|
|
@@ -405,6 +383,15 @@ export function providerLedgerOf(project) {
|
|
|
405
383
|
return PROVIDER_LEDGERS.get(project) ?? new Map();
|
|
406
384
|
}
|
|
407
385
|
|
|
386
|
+
/**
|
|
387
|
+
* True when an integration's templates root exists, the only place its
|
|
388
|
+
* templates come from (discoverIntegrationTemplatesForOne).
|
|
389
|
+
* @param {any} integration
|
|
390
|
+
* @returns {boolean}
|
|
391
|
+
*/
|
|
392
|
+
const hasTemplatesRoot = integration =>
|
|
393
|
+
integration?.templates != null && fs.existsSync(integration.templates);
|
|
394
|
+
|
|
408
395
|
/**
|
|
409
396
|
* The single API for reading resolved project configuration. Construct via the
|
|
410
397
|
* async {@link Project.load} factory.
|
|
@@ -1281,15 +1268,24 @@ export class Project {
|
|
|
1281
1268
|
* @returns {Promise<ProjectIntegrationIssue[]>}
|
|
1282
1269
|
*/
|
|
1283
1270
|
async issues() {
|
|
1284
|
-
//
|
|
1285
|
-
//
|
|
1286
|
-
//
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1271
|
+
// Each issue these passes find belongs to an integration, because Core's
|
|
1272
|
+
// templates and components declare no replacement. A project with no
|
|
1273
|
+
// integration skips them.
|
|
1274
|
+
if (this.#loadedIntegrations.length > 0) {
|
|
1275
|
+
// Template replacement validity depends on the combined Core +
|
|
1276
|
+
// integration catalog. Resolve it first so issue results never depend
|
|
1277
|
+
// on which discovery method the caller happened to invoke earlier. Only
|
|
1278
|
+
// an integration's own templates can replace one, so with none, Core's
|
|
1279
|
+
// templates stay unread.
|
|
1280
|
+
if (this.#loadedIntegrations.some(hasTemplatesRoot)) {
|
|
1281
|
+
await this.templates();
|
|
1282
|
+
}
|
|
1283
|
+
// Component replacement validity likewise depends on Core plus every
|
|
1284
|
+
// integration's components.
|
|
1285
|
+
await this.componentReplacements();
|
|
1286
|
+
for (const integration of this.#loadedIntegrations) {
|
|
1287
|
+
await this.#collectIssues(integration);
|
|
1288
|
+
}
|
|
1293
1289
|
}
|
|
1294
1290
|
// Return a stable copy so callers can't mutate internal state.
|
|
1295
1291
|
return this.#issues.map(i => ({...i}));
|