@astryxdesign/cli 0.7.9-canary.3b44b43 → 0.7.9-canary.4e7823a
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/_result.d.mts +5 -5
- package/api/search/search.d.mts +1 -1
- 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/authoring/debug/parse.d.mts +2 -2
- 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 +4 -26
- 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/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/runtime/locked-versions.mjs +1 -1
- package/foundation/runtime/package-set.mjs +1 -1
- package/package.json +9 -9
|
@@ -216,7 +216,7 @@ export const OFFICIAL_LIST_FILE: string;
|
|
|
216
216
|
*/
|
|
217
217
|
export const EXPERIMENTAL_KINDS: readonly ["icon-set"];
|
|
218
218
|
/** The item kinds every project reads: the catalog kinds, less experimental ones. */
|
|
219
|
-
export const STABLE_KINDS: ("template" | "component" | "
|
|
219
|
+
export const STABLE_KINDS: ("template" | "component" | "doc" | "theme" | "codemod" | "agent-doc" | "icon-set")[];
|
|
220
220
|
/** The list and detail entry fields for each item kind, in display order. */
|
|
221
221
|
export const KIND_FIELDS: readonly [readonly ["component", "components"], readonly ["template", "templates"], readonly ["doc", "docs"], readonly ["theme", "themes"], readonly ["codemod", "codemods"], readonly ["agent-doc", "agentDocs"], readonly ["icon-set", "iconSets"]];
|
|
222
222
|
export type ScannedPackage = import("./_package-scanner.mjs").ScannedPackage;
|
package/api/docs/_adapter.d.mts
CHANGED
|
@@ -274,6 +274,11 @@ export function topicLinks(catalog: DocsCatalog, entry: import("../../foundation
|
|
|
274
274
|
* decides.
|
|
275
275
|
* @param {unknown} topic
|
|
276
276
|
* @param {{cwd?: string}} [options]
|
|
277
|
+
* @param {DocsCatalog} [loaded] internal: a catalog the read already loaded,
|
|
278
|
+
* so the read and every part of it share one snapshot of the project's docs
|
|
279
|
+
* (and its memoized lowering) instead of loading the project again for each
|
|
280
|
+
* part. It is a separate argument, never an option, so no caller of the
|
|
281
|
+
* public `docs()` can set it
|
|
277
282
|
* @returns {Promise<
|
|
278
283
|
* | {kind: 'topic', catalog: DocsCatalog, entry: import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry}
|
|
279
284
|
* | {kind: 'node', catalog: DocsCatalog, tree: import('../../foundation/doc-compiler/tree.mjs').DocsTree, node: import('../../foundation/doc-compiler/tree.mjs').TreeNode}
|
|
@@ -282,7 +287,7 @@ export function topicLinks(catalog: DocsCatalog, entry: import("../../foundation
|
|
|
282
287
|
*/
|
|
283
288
|
export function resolveDocsArgument(topic: unknown, { cwd }?: {
|
|
284
289
|
cwd?: string;
|
|
285
|
-
}): Promise<{
|
|
290
|
+
}, loaded?: DocsCatalog): Promise<{
|
|
286
291
|
kind: "topic";
|
|
287
292
|
catalog: DocsCatalog;
|
|
288
293
|
entry: import("../../foundation/discovery/docs-discovery.mjs").DocsTopicEntry;
|
|
@@ -358,13 +363,14 @@ export function notLoaded(catalog: DocsCatalog): string;
|
|
|
358
363
|
* and lower it for the topic readers.
|
|
359
364
|
* @param {unknown} topic
|
|
360
365
|
* @param {{lang?: string | null, zh?: boolean, dense?: boolean, cwd?: string}} [options]
|
|
366
|
+
* @param {DocsCatalog} [loaded] internal, as {@link resolveDocsArgument}
|
|
361
367
|
*/
|
|
362
368
|
export function resolveTopicDocs(topic: unknown, options?: {
|
|
363
369
|
lang?: string | null;
|
|
364
370
|
zh?: boolean;
|
|
365
371
|
dense?: boolean;
|
|
366
372
|
cwd?: string;
|
|
367
|
-
}): Promise<{
|
|
373
|
+
}, loaded?: DocsCatalog): Promise<{
|
|
368
374
|
catalog: DocsCatalog;
|
|
369
375
|
node: import("../../foundation/doc-compiler/compile.mjs").CompiledReferenceNode;
|
|
370
376
|
lang: string | null;
|
package/api/docs/_adapter.mjs
CHANGED
|
@@ -1721,14 +1721,19 @@ export async function topicLinks(catalog, entry) {
|
|
|
1721
1721
|
* decides.
|
|
1722
1722
|
* @param {unknown} topic
|
|
1723
1723
|
* @param {{cwd?: string}} [options]
|
|
1724
|
+
* @param {DocsCatalog} [loaded] internal: a catalog the read already loaded,
|
|
1725
|
+
* so the read and every part of it share one snapshot of the project's docs
|
|
1726
|
+
* (and its memoized lowering) instead of loading the project again for each
|
|
1727
|
+
* part. It is a separate argument, never an option, so no caller of the
|
|
1728
|
+
* public `docs()` can set it
|
|
1724
1729
|
* @returns {Promise<
|
|
1725
1730
|
* | {kind: 'topic', catalog: DocsCatalog, entry: import('../../foundation/discovery/docs-discovery.mjs').DocsTopicEntry}
|
|
1726
1731
|
* | {kind: 'node', catalog: DocsCatalog, tree: import('../../foundation/doc-compiler/tree.mjs').DocsTree, node: import('../../foundation/doc-compiler/tree.mjs').TreeNode}
|
|
1727
1732
|
* | {kind: 'unknown', catalog: DocsCatalog}
|
|
1728
1733
|
* >}
|
|
1729
1734
|
*/
|
|
1730
|
-
export async function resolveDocsArgument(topic, {cwd} = {}) {
|
|
1731
|
-
const catalog = await loadDocsCatalog(cwd);
|
|
1735
|
+
export async function resolveDocsArgument(topic, {cwd} = {}, loaded) {
|
|
1736
|
+
const catalog = loaded ?? (await loadDocsCatalog(cwd));
|
|
1732
1737
|
if (typeof topic !== 'string' || topic === '')
|
|
1733
1738
|
return {kind: 'unknown', catalog};
|
|
1734
1739
|
const tree = await projectTree(catalog);
|
|
@@ -1942,13 +1947,14 @@ export function notLoaded(catalog) {
|
|
|
1942
1947
|
* and lower it for the topic readers.
|
|
1943
1948
|
* @param {unknown} topic
|
|
1944
1949
|
* @param {{lang?: string | null, zh?: boolean, dense?: boolean, cwd?: string}} [options]
|
|
1950
|
+
* @param {DocsCatalog} [loaded] internal, as {@link resolveDocsArgument}
|
|
1945
1951
|
*/
|
|
1946
|
-
export async function resolveTopicDocs(topic, options = {}) {
|
|
1952
|
+
export async function resolveTopicDocs(topic, options = {}, loaded) {
|
|
1947
1953
|
const {lang = null, zh = false, dense = false, cwd} = options;
|
|
1948
1954
|
const effectiveLang = lang || (dense ? 'dense' : zh ? 'zh' : null);
|
|
1949
1955
|
// A public API caller could pass a non-string topic; it lands on the same
|
|
1950
1956
|
// stable code as an unknown name rather than a raw TypeError.
|
|
1951
|
-
const found = await resolveDocsArgument(topic, {cwd});
|
|
1957
|
+
const found = await resolveDocsArgument(topic, {cwd}, loaded);
|
|
1952
1958
|
if (found.kind !== 'topic') {
|
|
1953
1959
|
throw found.kind === 'node'
|
|
1954
1960
|
? new AstryxError(
|
|
@@ -30,14 +30,17 @@ export function section(topic: string, sectionName: string, options?: {
|
|
|
30
30
|
* with the section its own section read returns for the query; when that
|
|
31
31
|
* section's key (its `id`, else the key its title derives) is the query in
|
|
32
32
|
* some guides, those guides answer first. No guide, or several, fail with ERR_UNKNOWN_SECTION, naming
|
|
33
|
-
* the guides to read instead.
|
|
33
|
+
* the guides to read instead. Every guide is read from `catalog`, the one the
|
|
34
|
+
* namespace read loaded, so the read loads the project once, not once per
|
|
35
|
+
* guide below the namespace.
|
|
36
|
+
* @param {import('../../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
|
|
34
37
|
* @param {import('../../../../foundation/doc-compiler/tree.mjs').DocsTree} tree
|
|
35
38
|
* @param {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} namespace
|
|
36
39
|
* @param {string} sectionName
|
|
37
40
|
* @param {object} [options] as {@link section}
|
|
38
41
|
* @returns {Promise<import('../../docs.type.mjs').DocsDetailSectionResponse>}
|
|
39
42
|
*/
|
|
40
|
-
export function namespaceSection(tree: import("../../../../foundation/doc-compiler/tree.mjs").DocsTree, namespace: import("../../../../foundation/doc-compiler/tree.mjs").TreeNode, sectionName: string, options?: object): Promise<import("../../docs.type.mjs").DocsDetailSectionResponse>;
|
|
43
|
+
export function namespaceSection(catalog: import("../../../../foundation/discovery/docs-discovery.mjs").DocsCatalog, tree: import("../../../../foundation/doc-compiler/tree.mjs").DocsTree, namespace: import("../../../../foundation/doc-compiler/tree.mjs").TreeNode, sectionName: string, options?: object): Promise<import("../../docs.type.mjs").DocsDetailSectionResponse>;
|
|
41
44
|
/**
|
|
42
45
|
* The guide a namespace section read answers from, or null to ask. When the
|
|
43
46
|
* query matches sections in several guides, the read asks the reader which
|
|
@@ -130,7 +130,10 @@ async function sectionResponse({catalog, node, lang, entry}, sections, match) {
|
|
|
130
130
|
* with the section its own section read returns for the query; when that
|
|
131
131
|
* section's key (its `id`, else the key its title derives) is the query in
|
|
132
132
|
* some guides, those guides answer first. No guide, or several, fail with ERR_UNKNOWN_SECTION, naming
|
|
133
|
-
* the guides to read instead.
|
|
133
|
+
* the guides to read instead. Every guide is read from `catalog`, the one the
|
|
134
|
+
* namespace read loaded, so the read loads the project once, not once per
|
|
135
|
+
* guide below the namespace.
|
|
136
|
+
* @param {import('../../../../foundation/discovery/docs-discovery.mjs').DocsCatalog} catalog
|
|
134
137
|
* @param {import('../../../../foundation/doc-compiler/tree.mjs').DocsTree} tree
|
|
135
138
|
* @param {import('../../../../foundation/doc-compiler/tree.mjs').TreeNode} namespace
|
|
136
139
|
* @param {string} sectionName
|
|
@@ -138,6 +141,7 @@ async function sectionResponse({catalog, node, lang, entry}, sections, match) {
|
|
|
138
141
|
* @returns {Promise<import('../../docs.type.mjs').DocsDetailSectionResponse>}
|
|
139
142
|
*/
|
|
140
143
|
export async function namespaceSection(
|
|
144
|
+
catalog,
|
|
141
145
|
tree,
|
|
142
146
|
namespace,
|
|
143
147
|
sectionName,
|
|
@@ -148,7 +152,7 @@ export async function namespaceSection(
|
|
|
148
152
|
/** @type {Omit<GuideMatch, 'match'>[]} */
|
|
149
153
|
const reads = [];
|
|
150
154
|
for (const guide of guides) {
|
|
151
|
-
const resolved = await resolveTopicDocs(guide.route, options);
|
|
155
|
+
const resolved = await resolveTopicDocs(guide.route, options, catalog);
|
|
152
156
|
reads.push({guide, resolved, sections: readerSections(resolved.node)});
|
|
153
157
|
}
|
|
154
158
|
|
package/api/docs/docs.mjs
CHANGED
|
@@ -155,7 +155,13 @@ async function docsRead(topic, section, options = {}) {
|
|
|
155
155
|
// A namespace answers a section read from the one guide below it that
|
|
156
156
|
// has the section (spec:AST-046 FR6). A typed doc is one read.
|
|
157
157
|
if (found.node.kind === 'namespace') {
|
|
158
|
-
return namespaceSection(
|
|
158
|
+
return namespaceSection(
|
|
159
|
+
found.catalog,
|
|
160
|
+
found.tree,
|
|
161
|
+
found.node,
|
|
162
|
+
section,
|
|
163
|
+
options,
|
|
164
|
+
);
|
|
159
165
|
}
|
|
160
166
|
throw new AstryxError(
|
|
161
167
|
`"${found.node.route}" has no sections. Read it whole: ${formatCliCommand(`docs ${found.node.route}`)}.`,
|
package/api/search/_result.d.mts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* (spec AST-081 FR3).
|
|
18
18
|
*/
|
|
19
19
|
export function toResult(c: Candidate, score: number, reason: string, matchedTerms: number, queryTerms: number, outside?: boolean): {
|
|
20
|
-
domain: "template" | "component" | "
|
|
20
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
21
21
|
name: string;
|
|
22
22
|
package: string | undefined;
|
|
23
23
|
score: number;
|
|
@@ -27,7 +27,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
27
27
|
deprecated?: import("../../authoring/index.js").ComponentDeprecation | undefined;
|
|
28
28
|
import: string | undefined;
|
|
29
29
|
command: string;
|
|
30
|
-
domain: "template" | "component" | "
|
|
30
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
31
31
|
name: string;
|
|
32
32
|
package: string | undefined;
|
|
33
33
|
score: number;
|
|
@@ -39,7 +39,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
39
39
|
command: string;
|
|
40
40
|
section?: string | undefined;
|
|
41
41
|
name: string;
|
|
42
|
-
domain: "template" | "component" | "
|
|
42
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
43
43
|
package: string | undefined;
|
|
44
44
|
score: number;
|
|
45
45
|
reason: string;
|
|
@@ -48,7 +48,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
48
48
|
displayName: string | undefined;
|
|
49
49
|
kind: "page" | "block" | undefined;
|
|
50
50
|
command: string;
|
|
51
|
-
domain: "template" | "component" | "
|
|
51
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
52
52
|
name: string;
|
|
53
53
|
package: string | undefined;
|
|
54
54
|
score: number;
|
|
@@ -57,7 +57,7 @@ export function toResult(c: Candidate, score: number, reason: string, matchedTer
|
|
|
57
57
|
} | {
|
|
58
58
|
displayName: string | undefined;
|
|
59
59
|
command: string;
|
|
60
|
-
domain: "template" | "component" | "
|
|
60
|
+
domain: "template" | "component" | "doc" | "theme" | "hook";
|
|
61
61
|
name: string;
|
|
62
62
|
package: string | undefined;
|
|
63
63
|
score: number;
|
package/api/search/search.d.mts
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
export function search(query: string, options?: {
|
|
15
15
|
cwd?: string | undefined;
|
|
16
|
-
type?: "template" | "component" | "
|
|
16
|
+
type?: "template" | "component" | "doc" | "theme" | "hook" | undefined;
|
|
17
17
|
limit?: number | undefined;
|
|
18
18
|
}): Promise<import("./search.type.mjs").SearchResponse>;
|
|
19
19
|
/**
|
|
@@ -66,12 +66,13 @@ export default function PowerSearchContentSearch() {
|
|
|
66
66
|
const [filters, setFilters] = useState<PowerSearchFilter[]>([]);
|
|
67
67
|
|
|
68
68
|
return (
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
69
|
+
<div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 300px)'}}>
|
|
70
|
+
<PowerSearch
|
|
71
|
+
config={config}
|
|
72
|
+
filters={filters}
|
|
73
|
+
onChange={newFilters => setFilters([...newFilters])}
|
|
74
|
+
placeholder="Type to search by title, or pick a field..."
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
76
77
|
);
|
|
77
78
|
}
|
|
@@ -94,12 +94,13 @@ export default function PowerSearchFullFeatured() {
|
|
|
94
94
|
const [filters, setFilters] = useState<PowerSearchFilter[]>([]);
|
|
95
95
|
|
|
96
96
|
return (
|
|
97
|
-
<
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
97
|
+
<div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 300px)'}}>
|
|
98
|
+
<PowerSearch
|
|
99
|
+
config={config}
|
|
100
|
+
filters={filters}
|
|
101
|
+
onChange={newFilters => setFilters([...newFilters])}
|
|
102
|
+
placeholder="Search..."
|
|
103
|
+
/>
|
|
104
|
+
</div>
|
|
104
105
|
);
|
|
105
106
|
}
|
|
@@ -69,12 +69,13 @@ export default function PowerSearchPresetFilters() {
|
|
|
69
69
|
]);
|
|
70
70
|
|
|
71
71
|
return (
|
|
72
|
-
<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
72
|
+
<div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 360px)'}}>
|
|
73
|
+
<PowerSearch
|
|
74
|
+
config={config}
|
|
75
|
+
filters={filters}
|
|
76
|
+
onChange={newFilters => setFilters([...newFilters])}
|
|
77
|
+
placeholder="Add more filters..."
|
|
78
|
+
/>
|
|
79
|
+
</div>
|
|
79
80
|
);
|
|
80
81
|
}
|
|
@@ -92,15 +92,17 @@ export default function PowerSearchSearchWithTable() {
|
|
|
92
92
|
const filteredBooks = applyFilters(filters, books);
|
|
93
93
|
|
|
94
94
|
return (
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
95
|
+
<div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 500px)'}}>
|
|
96
|
+
<VStack gap={4}>
|
|
97
|
+
<PowerSearch
|
|
98
|
+
config={config}
|
|
99
|
+
filters={filters}
|
|
100
|
+
onChange={newFilters => setFilters([...newFilters])}
|
|
101
|
+
placeholder="Filter books by title, author, year, genre..."
|
|
102
|
+
resultCount={filteredBooks.length}
|
|
103
|
+
/>
|
|
104
|
+
<Table data={filteredBooks} columns={columns} idKey="id" hasHover />
|
|
105
|
+
</VStack>
|
|
106
|
+
</div>
|
|
105
107
|
);
|
|
106
108
|
}
|
|
@@ -55,12 +55,13 @@ export default function PowerSearchShowcase() {
|
|
|
55
55
|
const [filters, setFilters] = useState<PowerSearchFilter[]>(initialFilters);
|
|
56
56
|
|
|
57
57
|
return (
|
|
58
|
-
<
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
<div style={{display: 'grid', gridTemplateColumns: 'minmax(0, 400px)'}}>
|
|
59
|
+
<PowerSearch
|
|
60
|
+
config={config}
|
|
61
|
+
filters={filters}
|
|
62
|
+
onChange={newFilters => setFilters([...newFilters])}
|
|
63
|
+
placeholder="Search by status, title..."
|
|
64
|
+
/>
|
|
65
|
+
</div>
|
|
65
66
|
);
|
|
66
67
|
}
|
|
@@ -78,9 +78,9 @@ declare const eventSchema: z.ZodObject<{
|
|
|
78
78
|
template: "template";
|
|
79
79
|
command: "command";
|
|
80
80
|
component: "component";
|
|
81
|
-
hook: "hook";
|
|
82
|
-
theme: "theme";
|
|
83
81
|
doc: "doc";
|
|
82
|
+
theme: "theme";
|
|
83
|
+
hook: "hook";
|
|
84
84
|
integration: "integration";
|
|
85
85
|
migration: "migration";
|
|
86
86
|
mixed: "mixed";
|
package/clients/cli/index.mjs
CHANGED
|
@@ -19,6 +19,7 @@ import * as path from 'node:path';
|
|
|
19
19
|
import {formatCliCommand, getCliInvocation, quoteCommandArgument} from '../../foundation/env/package-manager.mjs';
|
|
20
20
|
import {hasRecordedProject} from '../../foundation/env/cli-command.mjs';
|
|
21
21
|
import {isOutsideProject} from '../../foundation/env/project-scope.mjs';
|
|
22
|
+
import {findConfigPath} from '../../foundation/config/config-path.mjs';
|
|
22
23
|
import {API_VERSION, setJsonMode} from '../../foundation/response/json.mjs';
|
|
23
24
|
import {answeredBy, runChoice} from '../../foundation/release/run-context.mjs';
|
|
24
25
|
import {cliInstallAdvice, installFolder} from '../../foundation/release/notices.mjs';
|
|
@@ -29,14 +30,18 @@ import {ERROR_CODES} from '../../foundation/response/error-codes.mjs';
|
|
|
29
30
|
import {levenshteinDistance} from '../../foundation/text/string-utils.mjs';
|
|
30
31
|
import {installJsonShim} from './lib/json-shim.mjs';
|
|
31
32
|
import {markReportsResult} from './lib/define-command.mjs';
|
|
33
|
+
// The light modules, not agent-docs.mjs: that one loads discovery and the
|
|
34
|
+
// project config, which every run would pay for at startup.
|
|
32
35
|
import {
|
|
33
36
|
agentDocsTargetDir,
|
|
34
37
|
assertAgentDocsTarget,
|
|
38
|
+
} from '../../foundation/agent-docs/agent-docs-target.mjs';
|
|
39
|
+
import {CLI_ROOT} from '../../foundation/fs/paths.mjs';
|
|
40
|
+
import {
|
|
35
41
|
isAstryxInitialized,
|
|
36
42
|
isAstryxPromptInReach,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
import {setupNudge} from '../../foundation/agent-docs/agent-doc-state.mjs';
|
|
43
|
+
setupNudge,
|
|
44
|
+
} from '../../foundation/agent-docs/agent-doc-state.mjs';
|
|
40
45
|
import * as debug from '../../foundation/debug/index.mjs';
|
|
41
46
|
|
|
42
47
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
@@ -186,9 +191,6 @@ function fullCommandName(actionCommand, root) {
|
|
|
186
191
|
*/
|
|
187
192
|
export async function loadProjectDebugHandler() {
|
|
188
193
|
try {
|
|
189
|
-
const {findConfigPath, Project} = await import(
|
|
190
|
-
'../../foundation/config/project.mjs'
|
|
191
|
-
);
|
|
192
194
|
const configPath = findConfigPath(process.cwd());
|
|
193
195
|
if (!configPath) return;
|
|
194
196
|
const text = fs.readFileSync(configPath, 'utf-8');
|
|
@@ -196,6 +198,9 @@ export async function loadProjectDebugHandler() {
|
|
|
196
198
|
debug.noteConfigGateSkipped();
|
|
197
199
|
return;
|
|
198
200
|
}
|
|
201
|
+
// Only now: a run in a folder with no such config never loads the project
|
|
202
|
+
// module and its discovery.
|
|
203
|
+
const {Project} = await import('../../foundation/config/project.mjs');
|
|
199
204
|
await Project.load(process.cwd());
|
|
200
205
|
} catch {
|
|
201
206
|
// A broken config is the command's problem to report, not ours.
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
* `p` resolved, through symlinks when it exists.
|
|
6
|
+
* @param {string} p
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
9
|
+
export function realDir(p: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Throw {@link AgentDocsHomeError} when `targetDir` is the home folder, or a
|
|
12
|
+
* settings folder in it outside a project.
|
|
13
|
+
* @param {string} targetDir
|
|
14
|
+
*/
|
|
15
|
+
export function assertAgentDocsTarget(targetDir: string): void;
|
|
16
|
+
/**
|
|
17
|
+
* The folder a run started in `cwd` writes agent docs to: the nearest folder at
|
|
18
|
+
* or above it whose package.json declares an `@astryxdesign` package, else the
|
|
19
|
+
* nearest folder with any package.json. The search stops at a repository root
|
|
20
|
+
* and never reaches the home folder, so a stray `~/package.json` cannot pull
|
|
21
|
+
* the docs there.
|
|
22
|
+
* @param {string} cwd
|
|
23
|
+
* @returns {string | null} null when no folder it searches has a package.json;
|
|
24
|
+
* init then writes where it runs, as before.
|
|
25
|
+
*/
|
|
26
|
+
export function resolveAgentDocsRoot(cwd: string): string | null;
|
|
27
|
+
/**
|
|
28
|
+
* The folder `init` run in `cwd` writes the agent docs to: the project root
|
|
29
|
+
* {@link resolveAgentDocsRoot} finds, else `cwd` itself. The one definition
|
|
30
|
+
* that init, its removal, and the per-command setup nudge all use.
|
|
31
|
+
* @param {string} cwd
|
|
32
|
+
* @returns {string}
|
|
33
|
+
*/
|
|
34
|
+
export function agentDocsTargetDir(cwd: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Thrown when agent docs would be written into the home folder, or into a
|
|
37
|
+
* settings folder in it such as `~/.gemini` outside a project. Agents read the
|
|
38
|
+
* files there (for example `~/.claude/CLAUDE.md` or `~/.gemini/GEMINI.md`) in
|
|
39
|
+
* every project, so a project's version-pinned block never goes there. Removal
|
|
40
|
+
* stays allowed.
|
|
41
|
+
*/
|
|
42
|
+
export class AgentDocsHomeError extends Error {
|
|
43
|
+
/** @param {string} dir */
|
|
44
|
+
constructor(dir: string);
|
|
45
|
+
/** The refused folder. */
|
|
46
|
+
dir: string;
|
|
47
|
+
}
|
|
48
|
+
/** Folders that mark a repository root; the project search stops there. */
|
|
49
|
+
export const REPOSITORY_MARKERS: string[];
|
|
@@ -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
|
+
}
|