@plico-ai/core 0.0.0-stage → 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,4 @@
1
+ Plico
2
+ Copyright 2026 Plico contributors
3
+
4
+ This product includes software developed by the Plico contributors.
package/README.md CHANGED
@@ -1,3 +1,10 @@
1
- # Temporary Holding Version
1
+ # @plico-ai/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Core project-loading and validation helpers for Plico.
4
+
5
+ ## API
6
+
7
+ - `loadProject(root)` loads `plico.config.ts` and returns the normalized project config
8
+ - `validateProject(root)` validates the project shape, required files and directories, and duplicate tool names
9
+
10
+ This package stays local-first and file-first. It does not know about runtime execution or provider-specific agent abstractions.
@@ -0,0 +1,8 @@
1
+ import { type Frontmatter } from "./frontmatter.js";
2
+ import type { ValidationIssue } from "./types.js";
3
+ /** Frontmatter keys `agent.md` understands. Later features add keys here without breaking projects. */
4
+ export declare const AGENT_FRONTMATTER_KEYS: readonly string[];
5
+ /** Splits `agent.md` into its frontmatter and the instructions the model sees. */
6
+ export declare function parseAgentFile(text: string): Frontmatter;
7
+ /** One warning per frontmatter key that `agent.md` does not understand. */
8
+ export declare function unknownAgentKeyWarnings(path: string, data: Frontmatter["data"]): ValidationIssue[];
@@ -0,0 +1,17 @@
1
+ import { parseFrontmatter } from "./frontmatter.js";
2
+ /** Frontmatter keys `agent.md` understands. Later features add keys here without breaking projects. */
3
+ export const AGENT_FRONTMATTER_KEYS = [];
4
+ /** Splits `agent.md` into its frontmatter and the instructions the model sees. */
5
+ export function parseAgentFile(text) {
6
+ return parseFrontmatter(text);
7
+ }
8
+ /** One warning per frontmatter key that `agent.md` does not understand. */
9
+ export function unknownAgentKeyWarnings(path, data) {
10
+ return Object.keys(data)
11
+ .filter((key) => !AGENT_FRONTMATTER_KEYS.includes(key))
12
+ .map((key) => ({
13
+ path,
14
+ message: `Unknown frontmatter key "${key}" in ${path}. It is ignored and never sent to the model.`,
15
+ severity: "warning",
16
+ }));
17
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Project files import `@plico-ai/sdk` for `defineConfig` and `defineTool`. Those helpers return
3
+ * their argument unchanged, so any copy works. A project run by a global `plico` CLI may have no
4
+ * node_modules of its own; resolution falls back to the copy that ships with this install.
5
+ */
6
+ export declare const SPECIFIER = "@plico-ai/sdk";
7
+ /** The file URL the `@plico-ai/sdk` specifier should resolve to for a file in `fromFile`'s project. */
8
+ export declare function resolveAuthoringModule(fromFile: string): string;
9
+ /** Point `import "@plico-ai/sdk"` in a transpiled project file at an absolute file URL. */
10
+ export declare function rewriteAuthoringImports(code: string, fromFile: string): string;
11
+ /** Make `import "@plico-ai/sdk"` and `require("@plico-ai/sdk")` fall back to this install when a tool file cannot resolve it. */
12
+ export declare function installAuthoringFallback(): void;
@@ -0,0 +1,64 @@
1
+ import Module, { createRequire, register } from "node:module";
2
+ import { dirname } from "node:path";
3
+ import { pathToFileURL } from "node:url";
4
+ /**
5
+ * Project files import `@plico-ai/sdk` for `defineConfig` and `defineTool`. Those helpers return
6
+ * their argument unchanged, so any copy works. A project run by a global `plico` CLI may have no
7
+ * node_modules of its own; resolution falls back to the copy that ships with this install.
8
+ */
9
+ export const SPECIFIER = "@plico-ai/sdk";
10
+ function ownEntry() {
11
+ return createRequire(import.meta.url).resolve(SPECIFIER);
12
+ }
13
+ /** The file URL the `@plico-ai/sdk` specifier should resolve to for a file in `fromFile`'s project. */
14
+ export function resolveAuthoringModule(fromFile) {
15
+ try {
16
+ return pathToFileURL(createRequire(fromFile).resolve(SPECIFIER)).href;
17
+ }
18
+ catch {
19
+ return pathToFileURL(ownEntry()).href;
20
+ }
21
+ }
22
+ /** Point `import "@plico-ai/sdk"` in a transpiled project file at an absolute file URL. */
23
+ export function rewriteAuthoringImports(code, fromFile) {
24
+ return code.replace(/(\bfrom\s*|\bimport\s*)(["'])@plico-ai\/sdk\2/g, (_match, keyword) => `${keyword}${JSON.stringify(resolveAuthoringModule(fromFile))}`);
25
+ }
26
+ const ESM_HOOKS = `
27
+ let fallback;
28
+ export function initialize(data) { fallback = data.url; }
29
+ export async function resolve(specifier, context, nextResolve) {
30
+ try {
31
+ return await nextResolve(specifier, context);
32
+ } catch (error) {
33
+ if (specifier === "${SPECIFIER}" && error?.code === "ERR_MODULE_NOT_FOUND") {
34
+ return { url: fallback, shortCircuit: true };
35
+ }
36
+ throw error;
37
+ }
38
+ }
39
+ `;
40
+ let installed = false;
41
+ /** Make `import "@plico-ai/sdk"` and `require("@plico-ai/sdk")` fall back to this install when a tool file cannot resolve it. */
42
+ export function installAuthoringFallback() {
43
+ if (installed)
44
+ return;
45
+ installed = true;
46
+ const entry = ownEntry();
47
+ register(`data:text/javascript,${encodeURIComponent(ESM_HOOKS)}`, {
48
+ parentURL: pathToFileURL(`${dirname(entry)}/`).href,
49
+ data: { url: pathToFileURL(entry).href },
50
+ });
51
+ const internals = Module;
52
+ const original = internals._resolveFilename;
53
+ internals._resolveFilename = function resolveWithFallback(request, ...rest) {
54
+ try {
55
+ return original.call(this, request, ...rest);
56
+ }
57
+ catch (error) {
58
+ const code = error.code;
59
+ if (request === SPECIFIER && code === "MODULE_NOT_FOUND")
60
+ return entry;
61
+ throw error;
62
+ }
63
+ };
64
+ }
@@ -0,0 +1,2 @@
1
+ import type { LoadedProject } from "./types.js";
2
+ export declare function loadProject(root: string): Promise<LoadedProject>;
package/dist/config.js ADDED
@@ -0,0 +1,307 @@
1
+ import { readFile, stat } from "node:fs/promises";
2
+ import { transform } from "esbuild";
3
+ import { rewriteAuthoringImports } from "./authoring.js";
4
+ import { configLoadMessage, missingFileMessage, ProjectConfigError } from "./errors.js";
5
+ import { getProjectPaths, getProjectRelativePaths } from "./layout.js";
6
+ export async function loadProject(root) {
7
+ const configPath = getProjectPaths(root).configFile;
8
+ const config = await readProjectConfig(configPath);
9
+ return {
10
+ root,
11
+ configPath,
12
+ config,
13
+ };
14
+ }
15
+ async function readProjectConfig(configPath) {
16
+ const relativePaths = getProjectRelativePaths();
17
+ try {
18
+ await stat(configPath);
19
+ }
20
+ catch (error) {
21
+ throw new ProjectConfigError(configPath, [
22
+ {
23
+ path: relativePaths.configFile,
24
+ message: missingFileMessage(error),
25
+ severity: "error",
26
+ },
27
+ ]);
28
+ }
29
+ let configModule;
30
+ try {
31
+ configModule = await importTranspiledProjectConfig(configPath);
32
+ }
33
+ catch (error) {
34
+ throw new ProjectConfigError(configPath, [
35
+ {
36
+ path: relativePaths.configFile,
37
+ message: configLoadMessage(error),
38
+ severity: "error",
39
+ },
40
+ ]);
41
+ }
42
+ const exportedConfig = readDefaultExport(configModule, configPath);
43
+ return normalizeProjectConfig(exportedConfig, configPath);
44
+ }
45
+ async function importTranspiledProjectConfig(configPath) {
46
+ const source = await readFile(configPath, "utf8");
47
+ const transpiled = await transform(source, {
48
+ loader: "ts",
49
+ format: "esm",
50
+ target: "es2022",
51
+ sourcefile: configPath,
52
+ });
53
+ const code = rewriteAuthoringImports(transpiled.code, configPath);
54
+ const encoded = Buffer.from(code, "utf8").toString("base64");
55
+ const moduleUrl = `data:text/javascript;base64,${encoded}`;
56
+ return import(moduleUrl);
57
+ }
58
+ function readDefaultExport(configModule, configPath) {
59
+ const relativePaths = getProjectRelativePaths();
60
+ if (!isRecord(configModule) || !Object.hasOwn(configModule, "default")) {
61
+ throw new ProjectConfigError(configPath, [
62
+ {
63
+ path: relativePaths.configFile,
64
+ message: `Missing default export in ${relativePaths.configFile}`,
65
+ severity: "error",
66
+ },
67
+ ]);
68
+ }
69
+ return unwrapDefaultExport(configModule.default);
70
+ }
71
+ function normalizeProjectConfig(value, configPath) {
72
+ const issues = validateProjectConfigShape(value);
73
+ if (issues.length > 0) {
74
+ throw new ProjectConfigError(configPath, issues);
75
+ }
76
+ const config = value;
77
+ const normalized = {
78
+ schemaVersion: config.schemaVersion,
79
+ name: config.name,
80
+ artifacts: { access: config.artifacts?.access ?? "read-write" },
81
+ };
82
+ if (typeof config.description === "string") {
83
+ normalized.description = config.description;
84
+ }
85
+ if (typeof config.template === "string") {
86
+ normalized.template = config.template;
87
+ }
88
+ if (config.model !== undefined) {
89
+ normalized.model = { provider: config.model.provider, name: config.model.name };
90
+ if (config.model.baseURL !== undefined)
91
+ normalized.model.baseURL = config.model.baseURL;
92
+ if (config.model.apiKeyEnv !== undefined)
93
+ normalized.model.apiKeyEnv = config.model.apiKeyEnv;
94
+ if (config.model.maxSteps !== undefined)
95
+ normalized.model.maxSteps = config.model.maxSteps;
96
+ if (config.model.retries !== undefined)
97
+ normalized.model.retries = config.model.retries;
98
+ if (config.model.retryDelayMs !== undefined)
99
+ normalized.model.retryDelayMs = config.model.retryDelayMs;
100
+ }
101
+ if (config.execution !== undefined) {
102
+ normalized.execution = {};
103
+ if (config.execution.leaseMs !== undefined)
104
+ normalized.execution.leaseMs = config.execution.leaseMs;
105
+ }
106
+ if (config.threads !== undefined) {
107
+ normalized.threads = {};
108
+ if (config.threads.title !== undefined)
109
+ normalized.threads.title = config.threads.title;
110
+ }
111
+ if (config.approvals !== undefined) {
112
+ normalized.approvals = {};
113
+ if (config.approvals.default !== undefined)
114
+ normalized.approvals.default = config.approvals.default;
115
+ if (config.approvals.timeoutMs !== undefined)
116
+ normalized.approvals.timeoutMs = config.approvals.timeoutMs;
117
+ if (config.approvals.tools !== undefined)
118
+ normalized.approvals.tools = { ...config.approvals.tools };
119
+ }
120
+ return normalized;
121
+ }
122
+ function validateProjectConfigShape(value) {
123
+ const relativePaths = getProjectRelativePaths();
124
+ const issues = [];
125
+ if (!isRecord(value) || Array.isArray(value)) {
126
+ issues.push({
127
+ path: relativePaths.configFile,
128
+ message: "Expected default export to be an object",
129
+ severity: "error",
130
+ });
131
+ return issues;
132
+ }
133
+ if (!Object.hasOwn(value, "schemaVersion")) {
134
+ issues.push({
135
+ path: relativePaths.configFile,
136
+ message: "Missing required field: schemaVersion",
137
+ severity: "error",
138
+ });
139
+ }
140
+ else if (!Number.isInteger(value.schemaVersion)) {
141
+ issues.push({
142
+ path: relativePaths.configFile,
143
+ message: "Expected schemaVersion to be an integer",
144
+ severity: "error",
145
+ });
146
+ }
147
+ if (!Object.hasOwn(value, "name")) {
148
+ issues.push({
149
+ path: relativePaths.configFile,
150
+ message: "Missing required field: name",
151
+ severity: "error",
152
+ });
153
+ }
154
+ else if (typeof value.name !== "string") {
155
+ issues.push({
156
+ path: relativePaths.configFile,
157
+ message: "Expected name to be a string",
158
+ severity: "error",
159
+ });
160
+ }
161
+ if (Object.hasOwn(value, "description") && typeof value.description !== "string") {
162
+ issues.push({
163
+ path: relativePaths.configFile,
164
+ message: "Expected description to be a string",
165
+ severity: "error",
166
+ });
167
+ }
168
+ if (Object.hasOwn(value, "template") && typeof value.template !== "string") {
169
+ issues.push({
170
+ path: relativePaths.configFile,
171
+ message: "Expected template to be a string",
172
+ severity: "error",
173
+ });
174
+ }
175
+ if (Object.hasOwn(value, "artifacts") &&
176
+ (!isRecord(value.artifacts) ||
177
+ Array.isArray(value.artifacts) ||
178
+ (value.artifacts.access !== "read-write" &&
179
+ value.artifacts.access !== "read-only" &&
180
+ value.artifacts.access !== "off"))) {
181
+ issues.push({
182
+ path: relativePaths.configFile,
183
+ message: 'Expected artifacts.access to be "read-write", "read-only", or "off"',
184
+ severity: "error",
185
+ });
186
+ }
187
+ if (Object.hasOwn(value, "model")) {
188
+ const model = value.model;
189
+ if (!isRecord(model) ||
190
+ Array.isArray(model) ||
191
+ typeof model.provider !== "string" ||
192
+ !model.provider.trim() ||
193
+ typeof model.name !== "string" ||
194
+ !model.name.trim() ||
195
+ (Object.hasOwn(model, "baseURL") &&
196
+ (typeof model.baseURL !== "string" || !model.baseURL.trim())) ||
197
+ (Object.hasOwn(model, "apiKeyEnv") &&
198
+ (typeof model.apiKeyEnv !== "string" || !/^[A-Za-z_]\w*$/.test(model.apiKeyEnv))) ||
199
+ (Object.hasOwn(model, "maxSteps") &&
200
+ (!Number.isSafeInteger(model.maxSteps) || Number(model.maxSteps) <= 0)) ||
201
+ (Object.hasOwn(model, "retries") &&
202
+ (!Number.isSafeInteger(model.retries) ||
203
+ Number(model.retries) < 0 ||
204
+ Number(model.retries) > 10)) ||
205
+ (Object.hasOwn(model, "retryDelayMs") &&
206
+ (!Number.isSafeInteger(model.retryDelayMs) ||
207
+ Number(model.retryDelayMs) < 0 ||
208
+ Number(model.retryDelayMs) > 60000))) {
209
+ issues.push({
210
+ path: relativePaths.configFile,
211
+ message: "Expected non-empty model.provider and model.name, string model.baseURL and model.apiKeyEnv (a variable name), positive model.maxSteps, retries between 0 and 10, and retryDelayMs between 0 and 60000",
212
+ severity: "error",
213
+ });
214
+ }
215
+ }
216
+ if (Object.hasOwn(value, "execution")) {
217
+ const execution = value.execution;
218
+ if (!isRecord(execution) ||
219
+ Array.isArray(execution) ||
220
+ (Object.hasOwn(execution, "leaseMs") &&
221
+ (!Number.isSafeInteger(execution.leaseMs) || Number(execution.leaseMs) <= 0))) {
222
+ issues.push({
223
+ path: relativePaths.configFile,
224
+ message: "Expected execution.leaseMs to be a positive integer",
225
+ severity: "error",
226
+ });
227
+ }
228
+ }
229
+ if (Object.hasOwn(value, "threads")) {
230
+ const threads = value.threads;
231
+ if (!isRecord(threads) ||
232
+ Array.isArray(threads) ||
233
+ (Object.hasOwn(threads, "title") && threads.title !== "keywords" && threads.title !== "model")) {
234
+ issues.push({
235
+ path: relativePaths.configFile,
236
+ message: 'Expected threads.title to be "keywords" or "model"',
237
+ severity: "error",
238
+ });
239
+ }
240
+ }
241
+ if (Object.hasOwn(value, "approvals")) {
242
+ const approvals = value.approvals;
243
+ if (!isRecord(approvals) || Array.isArray(approvals)) {
244
+ issues.push({
245
+ path: relativePaths.configFile,
246
+ message: "Expected approvals to be an object",
247
+ severity: "error",
248
+ });
249
+ }
250
+ else {
251
+ if (Object.hasOwn(approvals, "default") &&
252
+ approvals.default !== "none" &&
253
+ approvals.default !== "required") {
254
+ issues.push({
255
+ path: relativePaths.configFile,
256
+ message: 'Expected approvals.default to be "none" or "required"',
257
+ severity: "error",
258
+ });
259
+ }
260
+ if (Object.hasOwn(approvals, "timeoutMs") &&
261
+ (!Number.isSafeInteger(approvals.timeoutMs) || Number(approvals.timeoutMs) <= 0)) {
262
+ issues.push({
263
+ path: relativePaths.configFile,
264
+ message: "Expected approvals.timeoutMs to be a positive integer",
265
+ severity: "error",
266
+ });
267
+ }
268
+ if (Object.hasOwn(approvals, "tools")) {
269
+ const tools = approvals.tools;
270
+ if (!isRecord(tools) || Array.isArray(tools)) {
271
+ issues.push({
272
+ path: relativePaths.configFile,
273
+ message: "Expected approvals.tools to be an object",
274
+ severity: "error",
275
+ });
276
+ }
277
+ else {
278
+ for (const [name, value2] of Object.entries(tools)) {
279
+ if (value2 !== "none" && value2 !== "required") {
280
+ issues.push({
281
+ path: relativePaths.configFile,
282
+ message: `Expected approvals.tools.${name} to be "none" or "required"`,
283
+ severity: "error",
284
+ });
285
+ }
286
+ }
287
+ }
288
+ }
289
+ }
290
+ }
291
+ return issues;
292
+ }
293
+ function isRecord(value) {
294
+ return typeof value === "object" && value !== null;
295
+ }
296
+ function unwrapDefaultExport(value) {
297
+ let current = value;
298
+ while (isRecord(current) && Object.hasOwn(current, "default")) {
299
+ const keys = Object.keys(current);
300
+ const looksLikeLoaderWrapper = keys.length === 1 || (keys.length === 2 && keys.includes("module.exports"));
301
+ if (!looksLikeLoaderWrapper) {
302
+ break;
303
+ }
304
+ current = current.default;
305
+ }
306
+ return current;
307
+ }
@@ -0,0 +1,9 @@
1
+ import type { ValidationIssue } from "./types.js";
2
+ export declare class ProjectConfigError extends Error {
3
+ readonly configPath: string;
4
+ readonly issues: ValidationIssue[];
5
+ constructor(configPath: string, issues: ValidationIssue[]);
6
+ }
7
+ export declare function missingFileMessage(error: unknown): string;
8
+ export declare function missingFileMessageFor(path: string, error: unknown): string;
9
+ export declare function configLoadMessage(error: unknown): string;