@compivia/plugin-sdk 0.0.1302 → 0.0.1322
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/harness.d.ts +4 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +50 -21
- package/dist/options.d.ts +12 -0
- package/dist/parse-manifest.d.ts +11 -0
- package/dist/slug.d.ts +13 -3
- package/dist/testing.js +1 -0
- package/package.json +1 -1
package/dist/harness.d.ts
CHANGED
|
@@ -33,6 +33,9 @@ export type AgentLaunch = {
|
|
|
33
33
|
prepare?: () => Promise<void>;
|
|
34
34
|
transcriptPath: string | null;
|
|
35
35
|
};
|
|
36
|
+
/** Результат `launch` плагина: без `prepare` — функция не пересекает границу
|
|
37
|
+
* процесса-хоста (#1030), подготовку плагин выполняет внутри `launch`. */
|
|
38
|
+
export type PluginAgentLaunch = Omit<AgentLaunch, "prepare">;
|
|
36
39
|
/** События вызова shell-инструмента (из runner-core/src/harness/types.ts). */
|
|
37
40
|
export type ShellCallEvent = {
|
|
38
41
|
kind: "start";
|
|
@@ -135,7 +138,7 @@ export type DetectResult = {
|
|
|
135
138
|
export type HarnessDefinition = {
|
|
136
139
|
id: string;
|
|
137
140
|
detect(ctx: HarnessContext): Promise<DetectResult>;
|
|
138
|
-
launch(input: AgentLaunchInput):
|
|
141
|
+
launch(input: AgentLaunchInput): PluginAgentLaunch | Promise<PluginAgentLaunch>;
|
|
139
142
|
classifyLine(line: string): HarnessLine;
|
|
140
143
|
locateSession(sessionId: string): Promise<SessionLocation | null>;
|
|
141
144
|
finalOf(location: SessionLocation, turn?: TurnCursor): Promise<FinalOutcome>;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -5,6 +5,22 @@ var CONTRIBUTION_KINDS = ["harness", "reporter", "slug"];
|
|
|
5
5
|
var CONTRIBUTION_ID_PATTERN = /^[a-z][a-z0-9-]{0,31}$/;
|
|
6
6
|
var CONTRIBUTION_KEY_PATTERN = /^[a-z]+:[a-z][a-z0-9-]{0,31}$/;
|
|
7
7
|
|
|
8
|
+
// src/slug.ts
|
|
9
|
+
var SLUG_MAX_LENGTH = 40;
|
|
10
|
+
var SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
|
|
11
|
+
function normalizeSlug(input, maxWords = 6) {
|
|
12
|
+
let slug = input.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
13
|
+
if (slug === "") return null;
|
|
14
|
+
const words = slug.split("-");
|
|
15
|
+
if (words.length > maxWords) slug = words.slice(0, maxWords).join("-");
|
|
16
|
+
if (slug.length > SLUG_MAX_LENGTH) {
|
|
17
|
+
const cut = slug.lastIndexOf("-", SLUG_MAX_LENGTH);
|
|
18
|
+
if (cut === -1) return null;
|
|
19
|
+
slug = slug.slice(0, cut);
|
|
20
|
+
}
|
|
21
|
+
return SLUG_PATTERN.test(slug) ? slug : null;
|
|
22
|
+
}
|
|
23
|
+
|
|
8
24
|
// src/define.ts
|
|
9
25
|
function defineHarness(def) {
|
|
10
26
|
return def;
|
|
@@ -23,6 +39,11 @@ var PluginManifestError = class extends Error {
|
|
|
23
39
|
this.name = "PluginManifestError";
|
|
24
40
|
}
|
|
25
41
|
};
|
|
42
|
+
var CONTRIBUTION_FIELDS = {
|
|
43
|
+
harness: ["kind", "id", "name", "module", "optionsSchema"],
|
|
44
|
+
reporter: ["kind", "id", "name", "module", "optionsSchema", "secrets"],
|
|
45
|
+
slug: ["kind", "id", "name", "module", "optionsSchema", "secrets"]
|
|
46
|
+
};
|
|
26
47
|
var ENV_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
27
48
|
function isPlainObject(value) {
|
|
28
49
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
@@ -58,7 +79,7 @@ function parseContribution(value, index) {
|
|
|
58
79
|
if (typeof kind !== "string" || !CONTRIBUTION_KINDS.includes(kind)) {
|
|
59
80
|
throw new PluginManifestError(`${path}.kind: expected one of ${CONTRIBUTION_KINDS.join(", ")}`);
|
|
60
81
|
}
|
|
61
|
-
const allowlist =
|
|
82
|
+
const allowlist = CONTRIBUTION_FIELDS[kind];
|
|
62
83
|
unknownFields(value, allowlist, path);
|
|
63
84
|
if (typeof value.id !== "string" || !CONTRIBUTION_ID_PATTERN.test(value.id)) {
|
|
64
85
|
throw new PluginManifestError(`${path}.id: expected a lowercase identifier (max 32 chars)`);
|
|
@@ -70,27 +91,8 @@ function parseContribution(value, index) {
|
|
|
70
91
|
throw new PluginManifestError(`${path}.module: expected a relative path inside the package`);
|
|
71
92
|
}
|
|
72
93
|
const optionsSchema = value.optionsSchema === void 0 ? void 0 : parseOptionsSchema(value.optionsSchema, `${path}.optionsSchema`);
|
|
73
|
-
if (kind === "harness") {
|
|
74
|
-
return {
|
|
75
|
-
kind: "harness",
|
|
76
|
-
id: value.id,
|
|
77
|
-
module: value.module,
|
|
78
|
-
...value.name !== void 0 ? { name: value.name } : {},
|
|
79
|
-
...optionsSchema !== void 0 ? { optionsSchema } : {}
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
if (kind === "slug") {
|
|
83
|
-
return {
|
|
84
|
-
kind: "slug",
|
|
85
|
-
id: value.id,
|
|
86
|
-
module: value.module,
|
|
87
|
-
...value.name !== void 0 ? { name: value.name } : {},
|
|
88
|
-
...optionsSchema !== void 0 ? { optionsSchema } : {},
|
|
89
|
-
...value.secrets !== void 0 ? { secrets: parseSecrets(value.secrets, `${path}.secrets`) } : {}
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
94
|
return {
|
|
93
|
-
kind
|
|
95
|
+
kind,
|
|
94
96
|
id: value.id,
|
|
95
97
|
module: value.module,
|
|
96
98
|
...value.name !== void 0 ? { name: value.name } : {},
|
|
@@ -137,6 +139,30 @@ function parseContributionKey(key) {
|
|
|
137
139
|
return { kind, id };
|
|
138
140
|
}
|
|
139
141
|
|
|
142
|
+
// src/options.ts
|
|
143
|
+
function validatePluginOptions(options, schema) {
|
|
144
|
+
if (schema === void 0) return { ok: true };
|
|
145
|
+
const props = schema.properties ?? {};
|
|
146
|
+
if (schema.additionalProperties === false) {
|
|
147
|
+
for (const key of Object.keys(options)) {
|
|
148
|
+
if (!(key in props)) return { ok: false, detail: `options.${key}: unknown field` };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
for (const key of schema.required ?? []) {
|
|
152
|
+
if (!(key in options)) return { ok: false, detail: `options.${key}: required` };
|
|
153
|
+
}
|
|
154
|
+
for (const [key, raw] of Object.entries(options)) {
|
|
155
|
+
const prop = props[key];
|
|
156
|
+
if (prop === null || typeof prop !== "object") continue;
|
|
157
|
+
const expected = prop.type;
|
|
158
|
+
if (typeof expected !== "string") continue;
|
|
159
|
+
const actual = Array.isArray(raw) ? "array" : raw === null ? "null" : typeof raw;
|
|
160
|
+
const match = expected === "integer" ? typeof raw === "number" && Number.isInteger(raw) : actual === expected;
|
|
161
|
+
if (!match) return { ok: false, detail: `options.${key}: expected ${expected}` };
|
|
162
|
+
}
|
|
163
|
+
return { ok: true };
|
|
164
|
+
}
|
|
165
|
+
|
|
140
166
|
// src/settings.ts
|
|
141
167
|
var ENV_NAME2 = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
142
168
|
function isPlainObject2(value) {
|
|
@@ -335,6 +361,7 @@ function compareStrings(a, b) {
|
|
|
335
361
|
return 0;
|
|
336
362
|
}
|
|
337
363
|
export {
|
|
364
|
+
CONTRIBUTION_FIELDS,
|
|
338
365
|
CONTRIBUTION_ID_PATTERN,
|
|
339
366
|
CONTRIBUTION_KEY_PATTERN,
|
|
340
367
|
CONTRIBUTION_KINDS,
|
|
@@ -347,7 +374,9 @@ export {
|
|
|
347
374
|
defineReporter,
|
|
348
375
|
defineSlugGenerator,
|
|
349
376
|
mergePluginSettings,
|
|
377
|
+
normalizeSlug,
|
|
350
378
|
parseContributionKey,
|
|
351
379
|
parsePluginManifest,
|
|
380
|
+
validatePluginOptions,
|
|
352
381
|
validatePluginsSection
|
|
353
382
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { JsonSchemaObject } from "./parse-manifest.js";
|
|
2
|
+
export type PluginOptionsValidation = {
|
|
3
|
+
ok: true;
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
detail: string;
|
|
7
|
+
};
|
|
8
|
+
/** Валидация options вклада по его optionsSchema — общая для всех видов (спека
|
|
9
|
+
* #1028 §13.2): поддержанное подмножество JSON Schema — required, типы-примитивы
|
|
10
|
+
* в properties, additionalProperties: false. Результат — путь поля без значения
|
|
11
|
+
* (граница утечек). Схемы нет — опции не проверяются. */
|
|
12
|
+
export declare function validatePluginOptions(options: Record<string, unknown>, schema: JsonSchemaObject | undefined): PluginOptionsValidation;
|
package/dist/parse-manifest.d.ts
CHANGED
|
@@ -36,6 +36,16 @@ export type PluginManifest = {
|
|
|
36
36
|
apiVersion: number;
|
|
37
37
|
contributions: PluginContribution[];
|
|
38
38
|
};
|
|
39
|
+
type ContributionOf<K extends PluginContributionKind> = Extract<PluginContribution, {
|
|
40
|
+
kind: K;
|
|
41
|
+
}>;
|
|
42
|
+
/** Поля вклада по видам: строка на каждый вид словаря, и только имена полей его
|
|
43
|
+
* типа (опечатка не проходит компиляцию; полноту строки проверяет типовой
|
|
44
|
+
* тест). Новое поле вида — строка здесь; вид без строки не проходит
|
|
45
|
+
* типизацию (спека #1028 §13). */
|
|
46
|
+
export declare const CONTRIBUTION_FIELDS: {
|
|
47
|
+
[K in PluginContributionKind]: readonly (keyof ContributionOf<K>)[];
|
|
48
|
+
};
|
|
39
49
|
/** Разбор поля `compivia.plugin` из package.json: строгий, лишние поля — отказ. */
|
|
40
50
|
export declare function parsePluginManifest(pkgJson: unknown): PluginManifest;
|
|
41
51
|
/** Канонический ключ вклада: `kind:id`. */
|
|
@@ -47,3 +57,4 @@ export declare function parseContributionKey(key: string): {
|
|
|
47
57
|
kind: PluginContributionKind;
|
|
48
58
|
id: string;
|
|
49
59
|
} | null;
|
|
60
|
+
export {};
|
package/dist/slug.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import type { PluginLogger } from "./harness.js";
|
|
|
2
2
|
import type { JsonSchemaObject } from "./parse-manifest.js";
|
|
3
3
|
/** Класс ветки, для которой генерируется slug. */
|
|
4
4
|
export type SlugKind = "task" | "feature";
|
|
5
|
-
/** Вход генератора: заголовок и (обрезанное
|
|
6
|
-
* подсказка плагину, жёсткий предел всё равно применяет
|
|
5
|
+
/** Вход генератора: заголовок и (обрезанное runner'ом) тело issue; maxWords —
|
|
6
|
+
* подсказка плагину, жёсткий предел всё равно применяет runner
|
|
7
7
|
* (normalizeSlug). */
|
|
8
8
|
export type SlugInput = {
|
|
9
9
|
kind: SlugKind;
|
|
@@ -19,7 +19,7 @@ export type SlugContext = {
|
|
|
19
19
|
logger: PluginLogger;
|
|
20
20
|
};
|
|
21
21
|
/** Контракт вклада `slug` (спека #541 §3.1): `generate → null` — «отказываюсь»
|
|
22
|
-
* (
|
|
22
|
+
* (runner делает fallback на встроенный генератор); бросок/таймаут — сбой.
|
|
23
23
|
* `dispose` идемпотентен. */
|
|
24
24
|
export type SlugGeneratorDefinition = {
|
|
25
25
|
apiVersion: number;
|
|
@@ -32,3 +32,13 @@ export type SlugGeneratorDefinition = {
|
|
|
32
32
|
} | null>;
|
|
33
33
|
dispose?(): Promise<void>;
|
|
34
34
|
};
|
|
35
|
+
/** Нормализация slug (design-doc #540 §4.1, спека #540 §3.1): нижний регистр;
|
|
36
|
+
* `[^a-z0-9]+` → `-`; обрезка дефисов; не больше maxWords слов; не больше
|
|
37
|
+
* 40 символов с обрезкой по границе слова (хвостовое частичное слово
|
|
38
|
+
* снимается вместе с дефисом перед ним; одно слово длиннее 40 — отказ).
|
|
39
|
+
* NFKD не применяется: не-ASCII вырезается — транслитерация (any-ascii) —
|
|
40
|
+
* работа генератора, не этой функции. Пустой результат или нарушение
|
|
41
|
+
* инварианта — null («отказ»). Функция ничего не знает о ветках, запасных
|
|
42
|
+
* словах и трекере. Единый источник для runner'а (нормализация вывода) и
|
|
43
|
+
* движка (проверка ответа). */
|
|
44
|
+
export declare function normalizeSlug(input: string, maxWords?: number): string | null;
|
package/dist/testing.js
CHANGED
|
@@ -124,6 +124,7 @@ function checkLaunch(create) {
|
|
|
124
124
|
expect(typeof result.command === "string" && result.command.length > 0).toBe(true);
|
|
125
125
|
expect(Array.isArray(result.args)).toBe(true);
|
|
126
126
|
expect(result.env).toBeInstanceOf(Object);
|
|
127
|
+
expect("prepare" in result).toBe(false);
|
|
127
128
|
expect(result.transcriptPath === null || typeof result.transcriptPath === "string").toBe(true);
|
|
128
129
|
});
|
|
129
130
|
});
|