@c4a/context 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +24 -0
- package/README.zh-CN.md +19 -0
- package/docs/README.md +1 -0
- package/docs/guides/agent-guide.md +7 -0
- package/docs/guides/package-outputs.md +19 -5
- package/docs/reference/code-extractors.md +88 -0
- package/docs/reference/package-templates.md +52 -0
- package/docs/reference/project-api.md +35 -0
- package/index.d.ts +28 -0
- package/index.js +55 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -67,6 +67,21 @@ code extractor. Use `customPhase()` only for orchestration that does not publish
|
|
|
67
67
|
knowledge candidates; it is not a replacement for source, extraction, Review,
|
|
68
68
|
and package lifecycle rules.
|
|
69
69
|
|
|
70
|
+
Context CLI intentionally does not bundle every language or repository parser.
|
|
71
|
+
Optional structural libraries can be installed by the knowledge project and
|
|
72
|
+
used inside `extractCustom()`:
|
|
73
|
+
|
|
74
|
+
| Package | Structural facts |
|
|
75
|
+
|---|---|
|
|
76
|
+
| `@c4a/extract-go` | Go declarations, imports, calls, and common HTTP route registrations |
|
|
77
|
+
| `@c4a/extract-rush` | Rush projects, tags, entry signals, workspace dependencies, and owner boundaries |
|
|
78
|
+
| `@c4a/extract-ts` | TypeScript extraction plus reusable React Router route facts |
|
|
79
|
+
|
|
80
|
+
These libraries do not create Context phases or candidates by themselves. The
|
|
81
|
+
project maps their deterministic facts to its own candidate identities and
|
|
82
|
+
review summaries; Context continues to own evidence validation, freshness,
|
|
83
|
+
Review, close, and package output.
|
|
84
|
+
|
|
70
85
|
## Knowledge Collections
|
|
71
86
|
|
|
72
87
|
Approved Markdown is organized under `knowledge/<collection>/`:
|
|
@@ -126,6 +141,15 @@ it is not repeated inside knowledge paths. Context still accepts
|
|
|
126
141
|
no longer changes build output and new declarations do not need it. Skill names
|
|
127
142
|
remain author-maintained and independent.
|
|
128
143
|
|
|
144
|
+
New KB setup should offer `assets: { delivery: "git-raw" }` first. Build
|
|
145
|
+
rewrites resource links to Git raw URLs; committing and publishing the resource
|
|
146
|
+
files remains the package author's responsibility. Non-Git workspaces may use
|
|
147
|
+
an explicit `urlPrefix`; without one they can bundle resources or explicitly
|
|
148
|
+
omit them and retain unresolved references. Bundled delivery may
|
|
149
|
+
install `sharp` in the workspace and configure `assets.optimize`; Context
|
|
150
|
+
itself has no image dependency and never changes source snapshots or approved
|
|
151
|
+
resources.
|
|
152
|
+
|
|
129
153
|
For advanced routing and retrieval, a template may carry a local script such as
|
|
130
154
|
`query.ts`, with a Skill describing when and how an Agent should call it. The
|
|
131
155
|
Skill can also route the Agent to MCP servers, CLI commands, or other tools to
|
package/README.zh-CN.md
CHANGED
|
@@ -57,6 +57,18 @@ export default defineProject({
|
|
|
57
57
|
非 TypeScript 或需要聚合代码事实时使用 `extractCustom()`。`customPhase()`
|
|
58
58
|
只用于不发布知识候选的项目专用编排,不能绕开来源、提取、审核和打包生命周期。
|
|
59
59
|
|
|
60
|
+
Context CLI 不会把所有语言和仓库解析器都打入自身。知识项目可以按需安装结构
|
|
61
|
+
提取库,并在 `extractCustom()` 中使用:
|
|
62
|
+
|
|
63
|
+
| 包 | 提供的结构事实 |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `@c4a/extract-go` | Go 声明、导入、调用和常见 HTTP 路由注册 |
|
|
66
|
+
| `@c4a/extract-rush` | Rush 项目、标签、入口信号、工作区依赖和所有者边界 |
|
|
67
|
+
| `@c4a/extract-ts` | TypeScript 提取,以及可复用的 React Router 路由事实 |
|
|
68
|
+
|
|
69
|
+
这些库本身不会创建 Context 阶段或候选。项目负责把确定性事实映射为自己的候选
|
|
70
|
+
身份和审核摘要;证据校验、新鲜度、审核、close 和打包仍由 Context 管理。
|
|
71
|
+
|
|
60
72
|
## 知识分类
|
|
61
73
|
|
|
62
74
|
审核通过的 Markdown 会存放在 `knowledge/<collection>/`:
|
|
@@ -104,6 +116,13 @@ kb/
|
|
|
104
116
|
`distribution.knowledgeNamespace` 仍可被读取,但不再改变构建结果;新声明无需配置它。
|
|
105
117
|
Skill 名称继续由作者独立维护。
|
|
106
118
|
|
|
119
|
+
新建 KB 时优先选择 `assets: { delivery: "git-raw" }`:构建器把资源链接改写到
|
|
120
|
+
Git raw 地址;资源的提交和发布由知识包作者负责,Context 不做远端探测。
|
|
121
|
+
非 Git 工作区也可以配置显式 `urlPrefix`,引用另一个仓库已经发布的资源;没有
|
|
122
|
+
可用 Git 或显式前缀时,可选择 `delivery: "bundle"` 随包分发,或显式选择
|
|
123
|
+
`delivery: "omit"` 不输出资源并保留失效引用。随包分发还可以在工作区安装 `sharp` 并通过
|
|
124
|
+
`assets.optimize` 仅优化生成的知识包;Context 本身不依赖图片处理库。
|
|
125
|
+
|
|
107
126
|
如果需要更强的路由和检索能力,模板可以携带 `query.ts` 一类本地脚本,再由 Skill 约定 Agent 何时、如何调用。Skill 也可以把 Agent 路由到 MCP、CLI 或其他工具,组成适合当前知识包的 Agentic Search 流程。
|
|
108
127
|
|
|
109
128
|
长期维护、多来源的知识生产工作区可以从
|
package/docs/README.md
CHANGED
|
@@ -19,6 +19,7 @@ general reference; do not preload the whole manual set.
|
|
|
19
19
|
- [Package Outputs](./guides/package-outputs.md) — how to choose between an agent knowledge-base package, LLM text, or no package output.
|
|
20
20
|
- [Lark Resource Materialization](./guides/lark-resources.md) — how embedded resources move from source evidence to approved knowledge and package assets.
|
|
21
21
|
- [Project API](./reference/project-api.md) — `defineProject`, sources, phases, review, and packages.
|
|
22
|
+
- [Code Extractor Selection](./reference/code-extractors.md) — inspect module technology signals and choose a built-in extractor, reusable structural package, or project adapter.
|
|
22
23
|
- [Package Templates](./reference/package-templates.md) — `kbPackage`, `llmsPackage`, template variables, and examples.
|
|
23
24
|
- [Template Variables](./reference/template-variables.md) — Handlebars variables, loops, comments, and default knowledge inventories.
|
|
24
25
|
|
|
@@ -72,6 +72,13 @@ node_modules/@c4a/context/docs/reference/project-api.md
|
|
|
72
72
|
node_modules/@c4a/context/docs/reference/package-templates.md
|
|
73
73
|
```
|
|
74
74
|
|
|
75
|
+
When configuring code extraction, use the Route-selected
|
|
76
|
+
`reference/code-extractors.md` manual. Run the Gate's read-only source
|
|
77
|
+
inspection first, use its manifest signals to select a matching extractor, and
|
|
78
|
+
read that package's public README before implementing an `extractCustom()`
|
|
79
|
+
adapter. Do not probe compiled package output or treat TypeScript as the default
|
|
80
|
+
for a non-TypeScript module.
|
|
81
|
+
|
|
75
82
|
## Workspace State Rules
|
|
76
83
|
|
|
77
84
|
- `src/index.ts` declares sources, phases, and packages.
|
|
@@ -90,11 +90,25 @@ task workflows. Authors may explicitly accept the generic default when it is
|
|
|
90
90
|
intentionally sufficient.
|
|
91
91
|
|
|
92
92
|
When approved pages reference materialized document resources, Context keeps
|
|
93
|
-
their production copies in content-addressed `knowledge/assets/` paths.
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
their production copies in content-addressed `knowledge/assets/` paths. New KB
|
|
94
|
+
setup should offer Git raw delivery first. It rewrites package links to either
|
|
95
|
+
an automatically derived raw prefix or an explicit author-provided prefix.
|
|
96
|
+
Context does not check whether resource files are committed, pushed, or
|
|
97
|
+
remotely readable; that is the package author's responsibility. With no
|
|
98
|
+
explicit prefix, supported remotes use an immutable commit URL. An explicit
|
|
99
|
+
prefix can contain `{commit}` when the Context workspace is in Git, or name a
|
|
100
|
+
mutable branch when that lifecycle is intentional; a literal prefix also works
|
|
101
|
+
when resources are published from a separate repository.
|
|
102
|
+
|
|
103
|
+
Workspaces without usable Git or an explicit raw prefix can choose bundled
|
|
104
|
+
delivery, which copies only selected resources to `others/assets/`, or explicit
|
|
105
|
+
omission, which does not copy resources and reports that links remain
|
|
106
|
+
unresolved. Bundled output may
|
|
107
|
+
optionally install `sharp` in the workspace and configure
|
|
108
|
+
`assets.optimize`; Context itself has no image dependency. Optimization changes
|
|
109
|
+
only `dist/`, content-addresses smaller WebP output, and leaves `sources/` and
|
|
110
|
+
`knowledge/assets/` unchanged. Source audit XML and capture reports are never
|
|
111
|
+
distributed as reader assets. See [Lark Resource Materialization](./lark-resources.md).
|
|
98
112
|
|
|
99
113
|
The same inventory exposes `structure.relationship_coverage`. It records
|
|
100
114
|
whether selected codegraph pages have current source-backed AST relationship
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Code Extractor Selection
|
|
2
|
+
|
|
3
|
+
Use this manual only when the current code-extraction Route asks the Agent to
|
|
4
|
+
choose or declare an extractor. The CLI reports repository facts; the Agent
|
|
5
|
+
chooses how those facts become source-backed code knowledge.
|
|
6
|
+
|
|
7
|
+
## Inspect Before Declaring
|
|
8
|
+
|
|
9
|
+
Run every read-only inspection command returned by the extraction-scope Gate.
|
|
10
|
+
The result identifies each confirmed module and its recognized `manifests`.
|
|
11
|
+
Treat these as deterministic technology signals, not as product semantics:
|
|
12
|
+
|
|
13
|
+
| Signal | Technology candidate |
|
|
14
|
+
|---|---|
|
|
15
|
+
| `package.json` | TypeScript, TSX, JavaScript, or JSX |
|
|
16
|
+
| `go.mod` | Go |
|
|
17
|
+
| `Cargo.toml` | Rust |
|
|
18
|
+
| `pyproject.toml` or `setup.py` | Python |
|
|
19
|
+
| `pom.xml` or `build.gradle` | Java or JVM |
|
|
20
|
+
| multiple manifests | a mixed module that may need more than one extractor |
|
|
21
|
+
|
|
22
|
+
Do not select `extractTs()` merely because a repository contains some
|
|
23
|
+
TypeScript. Decide against the exact confirmed module and include boundary. A
|
|
24
|
+
mixed module may compose multiple structural passes; parser selection is not an
|
|
25
|
+
exclusive repository-wide switch.
|
|
26
|
+
|
|
27
|
+
## Selection Order
|
|
28
|
+
|
|
29
|
+
Use the narrowest reusable capability that covers the confirmed source:
|
|
30
|
+
|
|
31
|
+
1. Use a Context-owned phase when its contract matches the source.
|
|
32
|
+
2. Otherwise use a reusable structural package inside `extractCustom()`.
|
|
33
|
+
3. If no reusable package covers the syntax or repository protocol, implement a
|
|
34
|
+
project-owned adapter and keep it in the Context workspace.
|
|
35
|
+
|
|
36
|
+
Current reusable capabilities are:
|
|
37
|
+
|
|
38
|
+
| Source fact | Preferred capability | Lifecycle integration |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| TypeScript/TSX package or file scope | `extractTs()` | Context-owned phase |
|
|
41
|
+
| Go declarations, imports, calls, and common HTTP routes | `@c4a/extract-go` | call from `extractCustom()` |
|
|
42
|
+
| Rush workspace packages, tags, dependencies, entries, and owners | `@c4a/extract-rush` | call from `extractCustom()`; may complement a language extractor |
|
|
43
|
+
| React Router route declarations | `extractReactRouterRoutes()` from `@c4a/extract-ts` | call from `extractCustom()`; complements TypeScript symbols |
|
|
44
|
+
| Rust, Python, Java/JVM, or an unsupported framework/protocol | no assumed built-in parser | project-owned `extractCustom()` adapter |
|
|
45
|
+
|
|
46
|
+
An optional package does not create a new CLI phase. Add it as an explicit
|
|
47
|
+
workspace dependency, then map its structural facts to candidates in the
|
|
48
|
+
project callback. Do not add a parser package when its documented coverage does
|
|
49
|
+
not match the inspected source.
|
|
50
|
+
|
|
51
|
+
## Read The Contract Before Extending
|
|
52
|
+
|
|
53
|
+
Before editing `src/index.ts`, read the relevant installed public manual or
|
|
54
|
+
package README. Do not infer APIs from bundled JavaScript.
|
|
55
|
+
|
|
56
|
+
- Context lifecycle and `extractCustom()`:
|
|
57
|
+
`node_modules/@c4a/context/docs/reference/project-api.md`
|
|
58
|
+
- Generic plugin protocol:
|
|
59
|
+
`node_modules/@c4a/extract/README.md`
|
|
60
|
+
- TypeScript:
|
|
61
|
+
`node_modules/@c4a/extract-ts/README.md`
|
|
62
|
+
- Go:
|
|
63
|
+
`node_modules/@c4a/extract-go/README.md`
|
|
64
|
+
- Rush:
|
|
65
|
+
`node_modules/@c4a/extract-rush/README.md`
|
|
66
|
+
|
|
67
|
+
If an optional package is not installed, use this capability matrix to decide
|
|
68
|
+
whether it is relevant, add only that dependency, and then read its shipped
|
|
69
|
+
README before implementing the callback.
|
|
70
|
+
|
|
71
|
+
A project-owned adapter may use an existing parser, compiler API, or command
|
|
72
|
+
whose output is deterministic. It must return source-backed candidates through
|
|
73
|
+
`extractCustom()`; it must not write lifecycle, knowledge, or Review files.
|
|
74
|
+
Framework-specific classification and rendering remain in the project. The CLI
|
|
75
|
+
and structural parser must not infer product meaning.
|
|
76
|
+
|
|
77
|
+
## Decision To Report
|
|
78
|
+
|
|
79
|
+
Before the first extraction preview, state briefly:
|
|
80
|
+
|
|
81
|
+
- the inspected module and manifest signals;
|
|
82
|
+
- the selected Context phase or structural package;
|
|
83
|
+
- whether coverage is complete or which facts remain project-owned; and
|
|
84
|
+
- why another available extractor is not needed.
|
|
85
|
+
|
|
86
|
+
If no current capability can parse the source reliably, stop at configuration
|
|
87
|
+
and report the missing generic capability. Do not silently emit an empty
|
|
88
|
+
codegraph or reuse an unrelated parser.
|
|
@@ -31,6 +31,10 @@ kbPackage({
|
|
|
31
31
|
foldDirectoryIndexes: true,
|
|
32
32
|
maxInlineEntries: 50,
|
|
33
33
|
},
|
|
34
|
+
assets: {
|
|
35
|
+
delivery: "git-raw",
|
|
36
|
+
urlPrefix: "https://code.example.com/team/knowledge/raw/{commit}",
|
|
37
|
+
},
|
|
34
38
|
});
|
|
35
39
|
```
|
|
36
40
|
|
|
@@ -52,8 +56,56 @@ llmsPackage({
|
|
|
52
56
|
| `template` | yes | Project-relative template directory or `{ path, vars }`. |
|
|
53
57
|
| `select` | no | Approved knowledge selector. Omit to include all approved knowledge. Supports internal `collections`, OKF `okfRoots`, and `include` / `exclude` path patterns relative to `knowledge/`. |
|
|
54
58
|
| `navigation` | no | KB directory-index policy. Defaults to `{ foldDirectoryIndexes: true, maxInlineEntries: 50 }`. |
|
|
59
|
+
| `assets` | no | Resource delivery: Git raw links, bundled files, or explicit omission. New KB setup should offer Git raw first. Omit for legacy byte-for-byte bundling. |
|
|
55
60
|
| `distribution` | no | Legacy input accepted from older workspaces. It no longer changes package paths and should not be added to new declarations. |
|
|
56
61
|
|
|
62
|
+
Use Git raw delivery when resources are published from a Git repository.
|
|
63
|
+
Without `urlPrefix`, the Context workspace must be inside Git; GitHub remotes
|
|
64
|
+
are derived automatically and pinned to the current commit. Other hosts and
|
|
65
|
+
workspaces outside Git accept an explicit HTTPS prefix; Context appends the
|
|
66
|
+
project-relative `knowledge/assets/...` path. Context does not check whether
|
|
67
|
+
the resources are committed, pushed, or remotely readable; publishing them is
|
|
68
|
+
the package author's responsibility.
|
|
69
|
+
`{commit}` is replaced when present. A literal branch in the prefix is allowed
|
|
70
|
+
but intentionally follows that mutable branch. The configured raw host must be
|
|
71
|
+
reachable by the eventual package consumers.
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
assets: {
|
|
75
|
+
delivery: "git-raw",
|
|
76
|
+
urlPrefix: "https://code.example.com/team/knowledge/raw/{commit}",
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
When the workspace is not in Git and has no explicit raw prefix, choose bundled
|
|
81
|
+
delivery or explicit omission:
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
assets: { delivery: "bundle" }
|
|
85
|
+
assets: { delivery: "omit" } // keeps unresolved links and reports them
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Bundled resources are copied byte-for-byte unless image optimization is
|
|
89
|
+
configured. When optimizable PNG/JPEG resources exceed 20 MiB, build and status
|
|
90
|
+
return `package.assets.optimization-recommended`. To optimize bundled output:
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
bun add -D sharp
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
assets: {
|
|
98
|
+
delivery: "bundle",
|
|
99
|
+
optimize: { processor: "sharp", mode: "lossless-webp" },
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`optimize.mode: "webp"` additionally accepts `quality` from 1 to 100. Both modes accept
|
|
104
|
+
an optional positive `maxDimension`; images are never enlarged. Context adopts
|
|
105
|
+
a generated image only when it is smaller, uses a digest-derived `.webp` path,
|
|
106
|
+
and rewrites package links. A configured but missing processor blocks before
|
|
107
|
+
the previous `dist/` package is replaced.
|
|
108
|
+
|
|
57
109
|
`template` is required. Do not call `kbPackage({ name })` or
|
|
58
110
|
`llmsPackage({ name })`.
|
|
59
111
|
|
|
@@ -739,6 +739,41 @@ Review summary and source-backed evidence). It must not write `knowledge/`,
|
|
|
739
739
|
Review snapshots directly. Context owns those files and preserves rejected and
|
|
740
740
|
unchanged-approved decisions across reruns.
|
|
741
741
|
|
|
742
|
+
#### Optional structural extractors
|
|
743
|
+
|
|
744
|
+
For the manifest-to-capability decision and unsupported-language extension
|
|
745
|
+
boundary, read [Code Extractor Selection](./code-extractors.md) before declaring
|
|
746
|
+
the phase.
|
|
747
|
+
|
|
748
|
+
`extractCustom()` may consume optional community packages without making them
|
|
749
|
+
Context CLI dependencies:
|
|
750
|
+
|
|
751
|
+
```ts
|
|
752
|
+
import { indexGoRepository } from "@c4a/extract-go";
|
|
753
|
+
import { extractCustom } from "@c4a/context";
|
|
754
|
+
|
|
755
|
+
extractCustom({
|
|
756
|
+
id: "extract:service:codegraph",
|
|
757
|
+
sources: [service],
|
|
758
|
+
collection: "codegraph",
|
|
759
|
+
extract: async ({ projectRoot }) => {
|
|
760
|
+
const facts = await indexGoRepository(resolveServiceCheckout(projectRoot));
|
|
761
|
+
return { candidates: buildServiceCandidates(facts) };
|
|
762
|
+
},
|
|
763
|
+
});
|
|
764
|
+
```
|
|
765
|
+
|
|
766
|
+
Available structural libraries include:
|
|
767
|
+
|
|
768
|
+
- `@c4a/extract-go`: Go declarations, imports, calls, and common HTTP routes;
|
|
769
|
+
- `@c4a/extract-rush`: Rush projects, tags, entries, dependencies, and owners;
|
|
770
|
+
- `@c4a/extract-ts`: TypeScript extraction and `extractReactRouterRoutes()`.
|
|
771
|
+
|
|
772
|
+
The packages return syntax and repository facts only. They do not classify
|
|
773
|
+
product meaning, choose candidate identities, or write lifecycle state. The
|
|
774
|
+
knowledge project owns that mapping. Context CLI does not auto-install these
|
|
775
|
+
packages and does not expose a built-in Go or Rush phase.
|
|
776
|
+
|
|
742
777
|
### `reviewValidity`
|
|
743
778
|
|
|
744
779
|
Declare the review step for a collection:
|
package/index.d.ts
CHANGED
|
@@ -22,6 +22,32 @@ export type PackageDistributionDefinition = {
|
|
|
22
22
|
/** @deprecated Accepted for older workspaces; package output roots are flat. */
|
|
23
23
|
knowledgeNamespace: string;
|
|
24
24
|
};
|
|
25
|
+
export type PackageAssetOptimizationDefinition = {
|
|
26
|
+
/** Image codec provider resolved from the Context workspace. */
|
|
27
|
+
processor: "sharp";
|
|
28
|
+
/** Lossless is the safe default; lossy WebP must be selected explicitly. */
|
|
29
|
+
mode?: "lossless-webp" | "webp";
|
|
30
|
+
/** WebP quality for lossy mode. */
|
|
31
|
+
quality?: number;
|
|
32
|
+
/** Optional longest-edge limit. Images are never enlarged. */
|
|
33
|
+
maxDimension?: number;
|
|
34
|
+
};
|
|
35
|
+
export type PackageAssetDefinition = {
|
|
36
|
+
/** Publish references to immutable Git-hosted resources instead of copying resource bytes. */
|
|
37
|
+
delivery: "git-raw";
|
|
38
|
+
/** Git remote used to derive the repository URL. */
|
|
39
|
+
remote?: string;
|
|
40
|
+
/** Optional HTTPS raw root. Context appends knowledge/assets/**; {commit} is supported. */
|
|
41
|
+
urlPrefix?: string;
|
|
42
|
+
} | {
|
|
43
|
+
/** Copy resources into the package. */
|
|
44
|
+
delivery: "bundle";
|
|
45
|
+
/** Optional image optimization, resolved from the Context workspace. */
|
|
46
|
+
optimize?: PackageAssetOptimizationDefinition;
|
|
47
|
+
} | {
|
|
48
|
+
/** Do not copy resources. Existing relative references remain unresolved. */
|
|
49
|
+
delivery: "omit";
|
|
50
|
+
};
|
|
25
51
|
export type BasePackageDefinition = {
|
|
26
52
|
name: string;
|
|
27
53
|
reads: readonly PhaseResourceReference[];
|
|
@@ -34,6 +60,7 @@ export type KbPackageDefinition = BasePackageDefinition & {
|
|
|
34
60
|
kind: "package.kb";
|
|
35
61
|
navigation: PackageNavigationDefinition;
|
|
36
62
|
distribution?: PackageDistributionDefinition;
|
|
63
|
+
assets?: PackageAssetDefinition;
|
|
37
64
|
};
|
|
38
65
|
export type LlmsPackageDefinition = BasePackageDefinition & {
|
|
39
66
|
kind: "package.llms";
|
|
@@ -55,6 +82,7 @@ export declare const kbPackage: (definition: {
|
|
|
55
82
|
select?: PackageSelectDefinition;
|
|
56
83
|
navigation?: Partial<PackageNavigationDefinition>;
|
|
57
84
|
distribution?: PackageDistributionDefinition;
|
|
85
|
+
assets?: PackageAssetDefinition;
|
|
58
86
|
}) => KbPackageDefinition;
|
|
59
87
|
export declare const llmsPackage: (definition: {
|
|
60
88
|
name: string;
|
package/index.js
CHANGED
|
@@ -11914,6 +11914,58 @@ var normalizePackageDistribution = (distribution) => {
|
|
|
11914
11914
|
}
|
|
11915
11915
|
return { knowledgeNamespace };
|
|
11916
11916
|
};
|
|
11917
|
+
var normalizePackageAssetOptimization = (assets) => {
|
|
11918
|
+
if (assets.processor !== "sharp") {
|
|
11919
|
+
throw new TypeError(`Package assets.optimize.processor must be "sharp": ${String(assets.processor)}`);
|
|
11920
|
+
}
|
|
11921
|
+
const mode = assets.mode ?? "lossless-webp";
|
|
11922
|
+
if (mode !== "lossless-webp" && mode !== "webp") {
|
|
11923
|
+
throw new TypeError(`Package assets.optimize.mode must be "lossless-webp" or "webp": ${String(mode)}`);
|
|
11924
|
+
}
|
|
11925
|
+
if (assets.quality !== undefined && (!Number.isSafeInteger(assets.quality) || assets.quality < 1 || assets.quality > 100)) {
|
|
11926
|
+
throw new TypeError(`Package assets.optimize.quality must be a safe integer from 1 to 100: ${assets.quality}`);
|
|
11927
|
+
}
|
|
11928
|
+
if (mode === "lossless-webp" && assets.quality !== undefined) {
|
|
11929
|
+
throw new TypeError('Package assets.optimize.quality is only valid when assets.optimize.mode is "webp".');
|
|
11930
|
+
}
|
|
11931
|
+
if (assets.maxDimension !== undefined && (!Number.isSafeInteger(assets.maxDimension) || assets.maxDimension < 1)) {
|
|
11932
|
+
throw new TypeError(`Package assets.optimize.maxDimension must be a positive safe integer: ${assets.maxDimension}`);
|
|
11933
|
+
}
|
|
11934
|
+
return {
|
|
11935
|
+
processor: "sharp",
|
|
11936
|
+
mode,
|
|
11937
|
+
...assets.quality === undefined ? {} : { quality: assets.quality },
|
|
11938
|
+
...assets.maxDimension === undefined ? {} : { maxDimension: assets.maxDimension }
|
|
11939
|
+
};
|
|
11940
|
+
};
|
|
11941
|
+
var normalizePackageAssets = (assets) => {
|
|
11942
|
+
if (assets === undefined)
|
|
11943
|
+
return;
|
|
11944
|
+
if (assets.delivery === "bundle") {
|
|
11945
|
+
return {
|
|
11946
|
+
delivery: "bundle",
|
|
11947
|
+
...assets.optimize === undefined ? {} : { optimize: normalizePackageAssetOptimization(assets.optimize) }
|
|
11948
|
+
};
|
|
11949
|
+
}
|
|
11950
|
+
if (assets.delivery === "omit")
|
|
11951
|
+
return { delivery: "omit" };
|
|
11952
|
+
if (assets.delivery !== "git-raw") {
|
|
11953
|
+
throw new TypeError(`Package assets.delivery must be "git-raw", "bundle", or "omit": ${String(assets.delivery)}`);
|
|
11954
|
+
}
|
|
11955
|
+
const remote = assets.remote?.trim();
|
|
11956
|
+
if (remote !== undefined && !/^[A-Za-z0-9._-]+$/u.test(remote)) {
|
|
11957
|
+
throw new TypeError(`Package assets.remote must be a safe Git remote name: ${assets.remote}`);
|
|
11958
|
+
}
|
|
11959
|
+
const urlPrefix = assets.urlPrefix?.trim().replace(/\/+$/u, "");
|
|
11960
|
+
if (urlPrefix !== undefined && !urlPrefix.startsWith("https://")) {
|
|
11961
|
+
throw new TypeError("Package assets.urlPrefix must be an HTTPS URL; it may contain {commit}.");
|
|
11962
|
+
}
|
|
11963
|
+
return {
|
|
11964
|
+
delivery: "git-raw",
|
|
11965
|
+
...remote === undefined ? {} : { remote },
|
|
11966
|
+
...urlPrefix === undefined ? {} : { urlPrefix }
|
|
11967
|
+
};
|
|
11968
|
+
};
|
|
11917
11969
|
var assertSelectOkfRoots = (roots) => {
|
|
11918
11970
|
for (const root of roots) {
|
|
11919
11971
|
assertOkfRoot(root, "Package select.okfRoots");
|
|
@@ -11959,11 +12011,13 @@ var createPackageDefinitionBase = (kind, definition) => {
|
|
|
11959
12011
|
var kbPackage = (definition) => {
|
|
11960
12012
|
const base = createPackageDefinitionBase("kb", definition);
|
|
11961
12013
|
const distribution = normalizePackageDistribution(definition.distribution);
|
|
12014
|
+
const assets = normalizePackageAssets(definition.assets);
|
|
11962
12015
|
return {
|
|
11963
12016
|
kind: "package.kb",
|
|
11964
12017
|
...base,
|
|
11965
12018
|
navigation: normalizePackageNavigation(definition.navigation),
|
|
11966
|
-
...distribution === undefined ? {} : { distribution }
|
|
12019
|
+
...distribution === undefined ? {} : { distribution },
|
|
12020
|
+
...assets === undefined ? {} : { assets }
|
|
11967
12021
|
};
|
|
11968
12022
|
};
|
|
11969
12023
|
var llmsPackage = (definition) => ({
|