@milkenjoyer/toolchain 0.22.1 → 0.24.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/DEPLOY.md +37 -0
- package/README.md +2 -0
- package/TESTING.md +3 -1
- package/dist/deploy-approval.d.mts +16 -0
- package/dist/deploy-approval.mjs +44 -0
- package/dist/deploy-plan.d.mts +25 -0
- package/dist/deploy-plan.mjs +78 -0
- package/dist/{guard-n0LC_buo.mjs → guard-D33fM6yS.mjs} +17 -19
- package/dist/guard.d.mts +1 -1
- package/dist/guard.mjs +3 -1
- package/dist/{lint-Bx4NP_kA.mjs → lint-C24rC9QX.mjs} +66 -39
- package/dist/lint.d.mts +3 -1
- package/dist/lint.mjs +1 -1
- package/dist/standard.mjs +1 -1
- package/package.json +10 -1
- package/src/deploy-approval.ts +101 -0
- package/src/deploy-plan.ts +134 -0
- package/src/guard.ts +22 -36
- package/src/lint/exceptions.ts +50 -0
- package/src/lint.ts +35 -25
package/DEPLOY.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Production plan gate
|
|
2
|
+
|
|
3
|
+
`@milkenjoyer/toolchain/deploy-plan` exports `parsePlan(output)`, `blockingChanges(changes, approved)` and `gatePlan({ output, approved })`. Use the same captured native Alchemy plan immediately before apply. A failed plan command, `Unreadable` or `Blocked` result refuses apply and files or updates a p0 through the trusted deploy observer. Only `Allowed` proceeds.
|
|
4
|
+
|
|
5
|
+
The parser accepts native plain plan output, including timestamped INFO logs, binding rows, action rows, cron names and Siglata's secret-pruning warnings. It requires one summary and reconciles its counts with named changes. Unknown, duplicate or incomplete rows refuse. The gate conservatively requires exact approval names for delete, replace, orphaned, unbind, drop and delete secret; it has no stateful-resource exemption list or wildcard approvals.
|
|
6
|
+
|
|
7
|
+
## Owner authority
|
|
8
|
+
|
|
9
|
+
`@milkenjoyer/toolchain/deploy-approval` exports `readDeletionApproval`:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
const { approved, evidence } = await readDeletionApproval({
|
|
13
|
+
github,
|
|
14
|
+
repository: "example/office",
|
|
15
|
+
targetSha,
|
|
16
|
+
authority: [{ commentId: 42, issueNumber: 9, updatedAt }],
|
|
17
|
+
});
|
|
18
|
+
const result = gatePlan({ output, approved });
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`github` is the runner's authenticated Octokit instance. `targetSha` is the full 40-character lowercase merge SHA. `authority` contains `DeletionAuthority` records supplied by trusted local runner configuration, defaulting to `[]`. The observer stores its per-target records outside product checkouts at `~/.local/state/agent-kit/deploy-approvals.json`, mode 0600. Only an explicit inbox attestation writes a record, with the comment's exact `updated_at` and a linked attestation receipt. The file is not itself proof of owner authority. Never populate it from product source, PR bodies, arbitrary issue markers or the GitHub author alone: agents also use the owner's GitHub login.
|
|
22
|
+
|
|
23
|
+
The helper resolves the target's merged PR through GitHub's commit-to-PR SDK endpoint. Its merge SHA and main base must match. A local `Fixes #9` or `Refs #9` reference in that PR links the issue. Cross-repository references do not authorize deletion. Every attested comment must belong to a linked issue, still have its attested timestamp, and have author `birbprophet`. Its entire body follows this grammar, with no code fence or surrounding prose:
|
|
24
|
+
|
|
25
|
+
```text
|
|
26
|
+
Owner ruling: allow production deletion
|
|
27
|
+
Target: 0123456789abcdef0123456789abcdef01234567
|
|
28
|
+
--allow-delete Archive,Office/RetiredStore
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Names are comma-separated exact native plan IDs, without spaces around commas. Cron expressions may contain spaces and stars inside parentheses. The full SHA binds the ruling to one target. Any invalid record, edited comment, wrong author, unlinked issue, wrong SHA or unreadable GitHub response grants no approvals. The returned evidence lists the verified comment URLs. An empty authority list makes no GitHub requests and grants no destructive permission.
|
|
32
|
+
|
|
33
|
+
## Rollout
|
|
34
|
+
|
|
35
|
+
The package is the shared home for agent-kit#549. Products move their published pin and import it. This replaces their permissive or duplicated plan parsers; it does not replace native Alchemy protection or their live-verifier gate. Siglata integrates first through agent-kit#545's trusted serial Mac mini deployer. Vibebattler and OptionHouse wait for their verifier holds.
|
|
36
|
+
|
|
37
|
+
PR-time plans follow a production state reader with read-only credentials. Connect read access alone does not restrict the Cloudflare credential inside an item. Ordinary deploy keys remain on the trusted Mac mini; they never run PR code. Alchemy's current state bearer also authorizes writes, and its fresh Cloudflare login uses an edge-preview session, so a read-only Workers/D1/R2/KV token alone cannot complete that path. No plan-reader token is provisioned until that path can run without writes.
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
Test hygiene rules and quarantine syntax: [TESTING.md](TESTING.md).
|
|
2
2
|
|
|
3
|
+
Production plan gates and owner approvals: [DEPLOY.md](DEPLOY.md).
|
|
4
|
+
|
|
3
5
|
# Configure pre-push hooks
|
|
4
6
|
|
|
5
7
|
A shared absolute Git hooks path must dispatch through the invoking worktree. `@milkenjoyer/toolchain/hooks` supplies `configurePrePush` to run native Vite+ setup and install that dispatcher as one operation.
|
package/TESTING.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Test hygiene
|
|
2
2
|
|
|
3
|
-
Toolchain 0.22.0 enables these `birbprophet` rules at error in `lint()`. `guard` rejects lowering them outside
|
|
3
|
+
Toolchain 0.22.0 enables these `birbprophet` rules at error in `lint()`. `guard` rejects lowering them outside issue-linked exact-file exceptions. They apply to `.test`, `.spec` and `.fake` TypeScript/JavaScript files and files inside `test`, `tests` or `__tests__` directories. Timeout/retry configuration is also checked in Vite and Vitest config files. The timeout rule also rejects `--retry` in the containing package's scripts.
|
|
4
4
|
|
|
5
5
|
| Rule | Required repair | Replaces |
|
|
6
6
|
| --- | --- | --- |
|
|
@@ -23,4 +23,6 @@ The issue marker must be on the immediately preceding line. Empty, zero and miss
|
|
|
23
23
|
|
|
24
24
|
Existing agent-kit violations are listed by exact filename and rule in `exceptions.ts`, linked to #532. Remove each exception as that cleanup repairs its file. No directory-wide exemption is shipped.
|
|
25
25
|
|
|
26
|
+
A consumer can pass its cleanup list to `lint({ exceptions })`. Each entry names `files`, `rules` and a full GitHub `issue` URL, using the exported `Exception` type. The preset rejects file patterns and missing issue links. Its generated settings retain that list for `ruleFindings` and `standard`; merge custom settings with the preset's settings to keep those issue links. Existing violations stay with the repo's cleanup campaign; new files keep the shared rules at error.
|
|
27
|
+
|
|
26
28
|
Siglata, vibebattler and OptionHouse need `@milkenjoyer/toolchain` pinned to `0.22.0` or a later compatible release. Their `0.18`/`0.10` pins do not contain these rules. Update the dependency pin after publication; consume the package's preset rather than copying rule files. Siglata #3564 and OptionHouse #1142 own their ongoing ports. Each repo's cleanup campaign owns its existing violations.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Octokit } from "@octokit/rest";
|
|
2
|
+
export type DeletionAuthority = {
|
|
3
|
+
readonly commentId: number;
|
|
4
|
+
readonly issueNumber: number;
|
|
5
|
+
readonly updatedAt: string;
|
|
6
|
+
};
|
|
7
|
+
export type DeletionApproval = {
|
|
8
|
+
readonly approved: ReadonlyArray<string>;
|
|
9
|
+
readonly evidence: ReadonlyArray<string>;
|
|
10
|
+
};
|
|
11
|
+
export declare const readDeletionApproval: ({ github, repository, targetSha, authority }: {
|
|
12
|
+
readonly github: Octokit;
|
|
13
|
+
readonly repository: string;
|
|
14
|
+
readonly targetSha: string;
|
|
15
|
+
readonly authority: ReadonlyArray<DeletionAuthority>;
|
|
16
|
+
}) => Promise<DeletionApproval>;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// src/deploy-approval.ts
|
|
2
|
+
const NONE = {
|
|
3
|
+
approved: [],
|
|
4
|
+
evidence: []
|
|
5
|
+
};
|
|
6
|
+
const SHA = /^[0-9a-f]{40}$/u;
|
|
7
|
+
const RULING = /^Owner ruling: allow production deletion\nTarget: (?<sha>[0-9a-f]{40})\n--allow-delete (?<names>[^\r\n]+)$/u;
|
|
8
|
+
const NAME = /^[^\s,*[\]]+(?:\([^()\r\n]*\))?[^\s,*[\]]*$/u;
|
|
9
|
+
const LOCAL_ISSUE = /\b(?:fix(?:es|ed)?|close[sd]?|resolve[sd]?|refs?)\s+#(?<number>[1-9]\d*)\b/giu;
|
|
10
|
+
const readDeletionApproval = async ({ github, repository, targetSha, authority }) => {
|
|
11
|
+
const [owner, repo, extra] = repository.split("/");
|
|
12
|
+
if (owner === void 0 || repo === void 0 || owner === "" || repo === "" || extra !== void 0 || !SHA.test(targetSha) || authority.length === 0) return NONE;
|
|
13
|
+
try {
|
|
14
|
+
const pulls = await github.paginate(github.repos.listPullRequestsAssociatedWithCommit, {
|
|
15
|
+
owner,
|
|
16
|
+
repo,
|
|
17
|
+
commit_sha: targetSha,
|
|
18
|
+
per_page: 100
|
|
19
|
+
});
|
|
20
|
+
const linked = new Set(pulls.filter((pull) => pull.merge_commit_sha === targetSha && pull.merged_at !== null && pull.base.repo.full_name === repository && pull.base.ref === "main").flatMap((pull) => [...(pull.body ?? "").matchAll(LOCAL_ISSUE)].map((match) => Number(match.groups?.number))));
|
|
21
|
+
const approved = /* @__PURE__ */ new Set();
|
|
22
|
+
const evidence = [];
|
|
23
|
+
for (const record of authority) {
|
|
24
|
+
if (!linked.has(record.issueNumber) || !Number.isSafeInteger(record.commentId) || record.commentId <= 0 || record.updatedAt === "") return NONE;
|
|
25
|
+
const { data: comment } = await github.issues.getComment({
|
|
26
|
+
owner,
|
|
27
|
+
repo,
|
|
28
|
+
comment_id: record.commentId
|
|
29
|
+
});
|
|
30
|
+
const ruling = RULING.exec(comment.body ?? "")?.groups;
|
|
31
|
+
const names = ruling?.names?.split(",");
|
|
32
|
+
if (comment.user?.login !== "birbprophet" || comment.issue_url !== `https://api.github.com/repos/${repository}/issues/${record.issueNumber}` || comment.updated_at !== record.updatedAt || ruling?.sha !== targetSha || names === void 0 || names.some((name) => !NAME.test(name)) || new Set(names).size !== names.length) return NONE;
|
|
33
|
+
for (const name of names) approved.add(name);
|
|
34
|
+
evidence.push(`https://github.com/${repository}/issues/${record.issueNumber}#issuecomment-${record.commentId}`);
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
approved: [...approved],
|
|
38
|
+
evidence
|
|
39
|
+
};
|
|
40
|
+
} catch {
|
|
41
|
+
return NONE;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
export { readDeletionApproval };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import * as Option from "effect/Option";
|
|
2
|
+
export type PlanChange = {
|
|
3
|
+
readonly resource: string;
|
|
4
|
+
readonly action: string;
|
|
5
|
+
};
|
|
6
|
+
export type DeployPlan = {
|
|
7
|
+
readonly summary: string;
|
|
8
|
+
readonly changes: ReadonlyArray<PlanChange>;
|
|
9
|
+
};
|
|
10
|
+
export declare const parsePlan: (output: string) => Option.Option<DeployPlan>;
|
|
11
|
+
export declare const blockingChanges: (changes: ReadonlyArray<PlanChange>, approved: ReadonlyArray<string>) => ReadonlyArray<PlanChange>;
|
|
12
|
+
export type PlanGate = {
|
|
13
|
+
readonly kind: "Unreadable";
|
|
14
|
+
} | {
|
|
15
|
+
readonly kind: "Blocked";
|
|
16
|
+
readonly plan: DeployPlan;
|
|
17
|
+
readonly blocked: ReadonlyArray<PlanChange>;
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: "Allowed";
|
|
20
|
+
readonly plan: DeployPlan;
|
|
21
|
+
};
|
|
22
|
+
export declare const gatePlan: ({ output, approved }: {
|
|
23
|
+
readonly output: string;
|
|
24
|
+
readonly approved: ReadonlyArray<string>;
|
|
25
|
+
}) => PlanGate;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import * as Option from "effect/Option";
|
|
2
|
+
// src/deploy-plan.ts
|
|
3
|
+
const RESOURCE = /^\[(?<resource>[^\]\s[()]+(?:\([^()\][]*\))?)\] (?<action>create|update|noop|adopted|delete|replace|orphaned|unbind|run|drop|delete secret)(?: \([^\n]*\))*(?: \[action\])?$/u;
|
|
4
|
+
const COUNT = /^(?<count>[1-9]\d*) (?<kind>to (?:create|update|noop|adopted|delete|replace|orphaned)|binding changes|tasks)$/u;
|
|
5
|
+
const DESTRUCTIVE = /* @__PURE__ */ new Set([
|
|
6
|
+
"delete",
|
|
7
|
+
"replace",
|
|
8
|
+
"orphaned",
|
|
9
|
+
"unbind",
|
|
10
|
+
"drop",
|
|
11
|
+
"delete secret"
|
|
12
|
+
]);
|
|
13
|
+
const parsePlan = (output) => {
|
|
14
|
+
const lines = output.split("\n").map((line) => line.trim().replace(/^(?:\[[^\]]+\] )?(?:INFO|WARN)(?: \([^)]*\))?:\s*/u, ""));
|
|
15
|
+
const summaries = lines.filter((line) => line.startsWith("Plan: "));
|
|
16
|
+
const [summary] = summaries;
|
|
17
|
+
if (summaries.length !== 1 || summary === void 0) return Option.none();
|
|
18
|
+
const counts = /* @__PURE__ */ new Map();
|
|
19
|
+
const body = summary.slice(6);
|
|
20
|
+
if (body !== "no changes" && body !== "no resources") for (const part of body.split(", ")) {
|
|
21
|
+
const groups = COUNT.exec(part)?.groups;
|
|
22
|
+
const kind = groups?.kind;
|
|
23
|
+
const count = Number(groups?.count);
|
|
24
|
+
if (kind === void 0 || !Number.isSafeInteger(count) || counts.has(kind)) return Option.none();
|
|
25
|
+
counts.set(kind, count);
|
|
26
|
+
}
|
|
27
|
+
const changes = [];
|
|
28
|
+
const names = /* @__PURE__ */ new Set();
|
|
29
|
+
for (const [index, line] of lines.entries()) {
|
|
30
|
+
if (index <= lines.indexOf(summary) && !line.endsWith("] delete secret")) continue;
|
|
31
|
+
if (!line.startsWith("[")) continue;
|
|
32
|
+
const groups = RESOURCE.exec(line)?.groups;
|
|
33
|
+
const resource = groups?.resource;
|
|
34
|
+
const action = groups?.action;
|
|
35
|
+
if (resource === void 0 || action === void 0 || names.has(resource)) return Option.none();
|
|
36
|
+
names.add(resource);
|
|
37
|
+
changes.push({
|
|
38
|
+
resource,
|
|
39
|
+
action
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
const actual = (action) => changes.filter((change) => change.action === action).length;
|
|
43
|
+
const noops = counts.get("to noop");
|
|
44
|
+
if (noops !== void 0 && actual("noop") !== noops) return Option.none();
|
|
45
|
+
for (const action of [
|
|
46
|
+
"delete",
|
|
47
|
+
"replace",
|
|
48
|
+
"orphaned"
|
|
49
|
+
]) if (actual(action) !== (counts.get(`to ${action}`) ?? 0)) return Option.none();
|
|
50
|
+
if (actual("run") + actual("drop") !== (counts.get("tasks") ?? 0)) return Option.none();
|
|
51
|
+
const bindings = counts.get("binding changes") ?? 0;
|
|
52
|
+
if (actual("unbind") > bindings) return Option.none();
|
|
53
|
+
for (const action of [
|
|
54
|
+
"create",
|
|
55
|
+
"update",
|
|
56
|
+
"adopted"
|
|
57
|
+
]) if (actual(action) < (counts.get(`to ${action}`) ?? 0)) return Option.none();
|
|
58
|
+
if (changes.filter(({ action }) => action !== "noop" && action !== "run" && action !== "drop" && action !== "delete secret").length !== [...counts].reduce((total, [kind, count]) => total + (kind === "tasks" || kind === "to noop" ? 0 : count), 0) || body === "no resources" && changes.length !== 0) return Option.none();
|
|
59
|
+
return Option.some({
|
|
60
|
+
summary,
|
|
61
|
+
changes
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const blockingChanges = (changes, approved) => changes.filter(({ resource, action }) => DESTRUCTIVE.has(action) && !approved.includes(resource));
|
|
65
|
+
const gatePlan = ({ output, approved }) => {
|
|
66
|
+
const parsed = parsePlan(output);
|
|
67
|
+
if (Option.isNone(parsed)) return { kind: "Unreadable" };
|
|
68
|
+
const blocked = blockingChanges(parsed.value.changes, approved);
|
|
69
|
+
return blocked.length === 0 ? {
|
|
70
|
+
kind: "Allowed",
|
|
71
|
+
plan: parsed.value
|
|
72
|
+
} : {
|
|
73
|
+
kind: "Blocked",
|
|
74
|
+
plan: parsed.value,
|
|
75
|
+
blocked
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
export { blockingChanges, gatePlan, parsePlan };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { d as otherTags, l as latestOf, u as onLatestLine } from "./compatible-CRaMYpBM.mjs";
|
|
2
2
|
import { i as enforcedTsgoRules } from "./effect-tsgo-D0QfeKGD.mjs";
|
|
3
3
|
import { t as exceptions } from "./exceptions-D0yZUk8P.mjs";
|
|
4
|
-
import { a as toolchainScopes, n as effectRules, r as foldkitPreset, t as birbprophetRules } from "./lint-
|
|
4
|
+
import { a as toolchainScopes, n as effectRules, o as configuredExceptions, r as foldkitPreset, s as exceptionFindings, t as birbprophetRules } from "./lint-C24rC9QX.mjs";
|
|
5
5
|
import { c as lead, f as versionOf } from "./versions-KbYa8kbF.mjs";
|
|
6
6
|
import * as Effect from "effect/Effect";
|
|
7
7
|
import * as Schema from "effect/Schema";
|
|
@@ -120,23 +120,21 @@ const inheritedFindings = (where, { extends: extendedConfigs = [] }) => Arr.flat
|
|
|
120
120
|
const path = `${where}extends[${index}]`;
|
|
121
121
|
return [...overrideFindings(path, overrides, []), ...inheritedFindings(`${path}.`, extended)];
|
|
122
122
|
});
|
|
123
|
-
const ruleFindings = dual((args) => args[0] !== void 0 && !Schema.is(Schema.Array(Schema.Unknown))(args[0]), ({ overrides = [], ...config }, list = exceptions) =>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
])
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
...ISSUE.test(exception.issue) ? [] : [`exception ${index} has no issue link: ${exception.issue}`]
|
|
139
|
-
]);
|
|
123
|
+
const ruleFindings = dual((args) => args[0] !== void 0 && !Schema.is(Schema.Array(Schema.Unknown))(args[0]), ({ overrides = [], ...config }, list = exceptions) => {
|
|
124
|
+
const local = configuredExceptions(config);
|
|
125
|
+
const configured = local.kind === "Read" ? local.exceptions : [];
|
|
126
|
+
return [
|
|
127
|
+
...local.kind === "Invalid" ? ["the config has invalid issue-linked exceptions"] : [],
|
|
128
|
+
...exceptionFindings(configured),
|
|
129
|
+
...Arr.flatMap(guarded, (rule) => Option.match(settingOf(config.rules, rule), {
|
|
130
|
+
onNone: () => [`${rule} is not set`],
|
|
131
|
+
onSome: (setting) => atError(setting) ? [] : [`${rule} is ${severityOf(setting)}`]
|
|
132
|
+
})),
|
|
133
|
+
...overrideFindings("the config's", overrides, [...list, ...configured]),
|
|
134
|
+
...scopeFindings(overrides),
|
|
135
|
+
...inheritedFindings("", config)
|
|
136
|
+
];
|
|
137
|
+
});
|
|
140
138
|
const familyTagFindings = (registry, family) => Option.match(latestOf(registry, family), {
|
|
141
139
|
onNone: () => [`${lead(family)} has no latest tag in the registry record`],
|
|
142
140
|
onSome: (latest) => family.version === latest ? [] : Option.match(Arr.findFirst(otherTags(registry, family), ([, version]) => version === family.version), {
|
|
@@ -145,4 +143,4 @@ const familyTagFindings = (registry, family) => Option.match(latestOf(registry,
|
|
|
145
143
|
})
|
|
146
144
|
});
|
|
147
145
|
const tagFindings = dual(2, (current, registry) => Arr.flatMap(current.families, (family) => familyTagFindings(registry, family)));
|
|
148
|
-
export {
|
|
146
|
+
export { tagFindings as a, manifestRanges as c, ruleFindings as i, resolveCatalog as l, isFoldkitViteInput as n, PLAIN as o, pinFindings as r, exactFindings as s, foldkitViteFindings as t };
|
package/dist/guard.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import { r as Packuments } from "./compatible-BKEJ_p20.mjs";
|
|
|
2
2
|
import { t as Exception } from "./exceptions-LNZ022dl.mjs";
|
|
3
3
|
import { t as Catalog } from "./versions-DqZd0jF9.mjs";
|
|
4
4
|
import { OxlintConfig } from "vite-plus/lint";
|
|
5
|
+
export declare const exceptionFindings: (list?: ReadonlyArray<Exception>) => ReadonlyArray<string>;
|
|
5
6
|
type Ranges = Readonly<Record<string, string>>;
|
|
6
7
|
export declare const manifestRanges: (text: string) => ReadonlyArray<readonly [string, Ranges]>;
|
|
7
8
|
export declare const exactFindings: {
|
|
@@ -18,7 +19,6 @@ export declare const ruleFindings: {
|
|
|
18
19
|
(list?: ReadonlyArray<Exception>): (config: OxlintConfig) => ReadonlyArray<string>;
|
|
19
20
|
(config: OxlintConfig, list?: ReadonlyArray<Exception>): ReadonlyArray<string>;
|
|
20
21
|
};
|
|
21
|
-
export declare const exceptionFindings: (list?: ReadonlyArray<Exception>) => ReadonlyArray<string>;
|
|
22
22
|
export declare const tagFindings: {
|
|
23
23
|
(registry: Packuments): (current: Catalog) => ReadonlyArray<string>;
|
|
24
24
|
(current: Catalog, registry: Packuments): ReadonlyArray<string>;
|
package/dist/guard.mjs
CHANGED
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { s as exceptionFindings } from "./lint-C24rC9QX.mjs";
|
|
2
|
+
import { a as tagFindings, c as manifestRanges, i as ruleFindings, n as isFoldkitViteInput, r as pinFindings, s as exactFindings, t as foldkitViteFindings } from "./guard-D33fM6yS.mjs";
|
|
3
|
+
export { exactFindings, exceptionFindings, foldkitViteFindings, isFoldkitViteInput, manifestRanges, pinFindings, ruleFindings, tagFindings };
|
|
@@ -10,6 +10,28 @@ import * as R from "effect/Record";
|
|
|
10
10
|
import * as Str from "effect/String";
|
|
11
11
|
import foldkitRecommended from "@foldkit/oxlint-plugin/recommended.json" with { type: "json" };
|
|
12
12
|
import ultraciteCore from "ultracite/oxlint/core";
|
|
13
|
+
// src/lint/exceptions.ts
|
|
14
|
+
const exceptionSetting = "birbprophet/exceptions";
|
|
15
|
+
const ExceptionList = Schema.Array(Schema.Struct({
|
|
16
|
+
files: Schema.Array(Schema.String),
|
|
17
|
+
rules: Schema.Array(Schema.String),
|
|
18
|
+
issue: Schema.String
|
|
19
|
+
}));
|
|
20
|
+
const configuredExceptions = (config) => {
|
|
21
|
+
const value = config.settings?.["birbprophet/exceptions"] ?? [];
|
|
22
|
+
return Schema.is(ExceptionList)(value) ? {
|
|
23
|
+
kind: "Read",
|
|
24
|
+
exceptions: value
|
|
25
|
+
} : { kind: "Invalid" };
|
|
26
|
+
};
|
|
27
|
+
const GLOB = /[*?[\]{}!]/u;
|
|
28
|
+
const ISSUE = /^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/\d+$/u;
|
|
29
|
+
const exceptionFindings = (list = exceptions) => Arr.flatMap(list, (exception, index) => [
|
|
30
|
+
...Arr.isReadonlyArrayEmpty(exception.files) ? [`exception ${index} names no file`] : [],
|
|
31
|
+
...Arr.flatMap(exception.files, (file) => GLOB.test(file) ? [`exception ${index} names ${file}, a pattern rather than a file`] : []),
|
|
32
|
+
...Arr.isReadonlyArrayEmpty(exception.rules) ? [`exception ${index} names no rule`] : [],
|
|
33
|
+
...ISSUE.test(exception.issue) ? [] : [`exception ${index} has no issue link: ${exception.issue}`]
|
|
34
|
+
]);
|
|
13
35
|
// src/lint.ts
|
|
14
36
|
const plugins = [
|
|
15
37
|
"typescript",
|
|
@@ -97,44 +119,49 @@ const exceptionTier = (exception) => ({
|
|
|
97
119
|
files: [...exception.files],
|
|
98
120
|
rules: R.fromEntries(Arr.map(exception.rules, (rule) => [rule, "off"]))
|
|
99
121
|
});
|
|
100
|
-
const lint = ({ ignores = [] } = {}) =>
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
{
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
122
|
+
const lint = ({ ignores = [], exceptions: local = [] } = {}) => {
|
|
123
|
+
const findings = exceptionFindings(local);
|
|
124
|
+
if (findings.length > 0) throw new Error(findings.join("\n"));
|
|
125
|
+
return {
|
|
126
|
+
...local.length > 0 ? { settings: { [exceptionSetting]: local } } : {},
|
|
127
|
+
plugins,
|
|
128
|
+
categories,
|
|
129
|
+
jsPlugins: [
|
|
130
|
+
{
|
|
131
|
+
name: "vite-plus",
|
|
132
|
+
specifier: resolved("vite-plus/oxlint-plugin")
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "foldkit",
|
|
136
|
+
specifier: sibling("foldkit-plugin")
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: plugin.meta.name,
|
|
140
|
+
specifier: sibling("effect-plugin")
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
name: plugin$1.meta.name,
|
|
144
|
+
specifier: sibling("plugin")
|
|
145
|
+
}
|
|
146
|
+
],
|
|
147
|
+
options: {
|
|
148
|
+
typeAware: true,
|
|
149
|
+
typeCheck: true
|
|
111
150
|
},
|
|
112
|
-
{
|
|
113
|
-
|
|
114
|
-
|
|
151
|
+
rules: {
|
|
152
|
+
...foldkitPreset.rules,
|
|
153
|
+
...staticRules,
|
|
154
|
+
"vite-plus/prefer-vite-plus-imports": "error",
|
|
155
|
+
...effectRules,
|
|
156
|
+
...birbprophetRules,
|
|
157
|
+
...effectTsgoRules
|
|
115
158
|
},
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
rules: {
|
|
126
|
-
...foldkitPreset.rules,
|
|
127
|
-
...staticRules,
|
|
128
|
-
"vite-plus/prefer-vite-plus-imports": "error",
|
|
129
|
-
...effectRules,
|
|
130
|
-
...birbprophetRules,
|
|
131
|
-
...effectTsgoRules
|
|
132
|
-
},
|
|
133
|
-
overrides: [
|
|
134
|
-
...foldkitPreset.overrides,
|
|
135
|
-
...toolchainScopes,
|
|
136
|
-
...Arr.map(exceptions, exceptionTier)
|
|
137
|
-
],
|
|
138
|
-
ignorePatterns: [...coreIgnores, ...ignores]
|
|
139
|
-
});
|
|
140
|
-
export { toolchainScopes as a, lint as i, effectRules as n, foldkitPreset as r, birbprophetRules as t };
|
|
159
|
+
overrides: [
|
|
160
|
+
...foldkitPreset.overrides,
|
|
161
|
+
...toolchainScopes,
|
|
162
|
+
...Arr.map([...exceptions, ...local], exceptionTier)
|
|
163
|
+
],
|
|
164
|
+
ignorePatterns: [...coreIgnores, ...ignores]
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
export { toolchainScopes as a, lint as i, effectRules as n, configuredExceptions as o, foldkitPreset as r, exceptionFindings as s, birbprophetRules as t };
|
package/dist/lint.d.mts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { t as Exception } from "./exceptions-LNZ022dl.mjs";
|
|
1
2
|
import { OxlintConfig, OxlintOverride } from "vite-plus/lint";
|
|
2
3
|
export type LintOptions = {
|
|
3
4
|
readonly ignores?: ReadonlyArray<string>;
|
|
5
|
+
readonly exceptions?: ReadonlyArray<Exception>;
|
|
4
6
|
};
|
|
5
7
|
export declare const foldkitPreset: {
|
|
6
8
|
readonly jsPlugins: readonly {
|
|
@@ -21,4 +23,4 @@ export declare const foldkitPreset: {
|
|
|
21
23
|
export declare const toolchainScopes: ReadonlyArray<OxlintOverride>;
|
|
22
24
|
export declare const effectRules: Record<string, "error">;
|
|
23
25
|
export declare const birbprophetRules: Record<string, "error">;
|
|
24
|
-
export declare const lint: ({ ignores }?: LintOptions) => OxlintConfig;
|
|
26
|
+
export declare const lint: ({ ignores, exceptions: local }?: LintOptions) => OxlintConfig;
|
package/dist/lint.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as birbprophetRules, n as effectRules, r as foldkitPreset, i as lint, a as toolchainScopes } from "./lint-
|
|
1
|
+
export { t as birbprophetRules, n as effectRules, r as foldkitPreset, i as lint, a as toolchainScopes } from "./lint-C24rC9QX.mjs";
|
package/dist/standard.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { f as versionOf } from "./versions-KbYa8kbF.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { c as manifestRanges, i as ruleFindings, l as resolveCatalog, o as PLAIN, s as exactFindings } from "./guard-D33fM6yS.mjs";
|
|
4
4
|
import { t as fmt } from "./fmt-C6autuPP.mjs";
|
|
5
5
|
import { n as criticalFindings, t as decode } from "./specs-file-Ck9ZOt46.mjs";
|
|
6
6
|
import * as Console from "effect/Console";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@milkenjoyer/toolchain",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/birbprophet/agent-kit.git",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
},
|
|
18
18
|
"files": [
|
|
19
19
|
"dist",
|
|
20
|
+
"DEPLOY.md",
|
|
20
21
|
"STARTS.md",
|
|
21
22
|
"TESTING.md",
|
|
22
23
|
"formal-tools/tla2tools-1.8.0.jar",
|
|
@@ -30,6 +31,14 @@
|
|
|
30
31
|
],
|
|
31
32
|
"type": "module",
|
|
32
33
|
"exports": {
|
|
34
|
+
"./deploy-plan": {
|
|
35
|
+
"types": "./dist/deploy-plan.d.mts",
|
|
36
|
+
"default": "./dist/deploy-plan.mjs"
|
|
37
|
+
},
|
|
38
|
+
"./deploy-approval": {
|
|
39
|
+
"types": "./dist/deploy-approval.d.mts",
|
|
40
|
+
"default": "./dist/deploy-approval.mjs"
|
|
41
|
+
},
|
|
33
42
|
"./arithmetic": {
|
|
34
43
|
"types": "./dist/arithmetic.d.mts",
|
|
35
44
|
"default": "./dist/arithmetic.mjs"
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { Octokit } from "@octokit/rest";
|
|
2
|
+
|
|
3
|
+
export type DeletionAuthority = {
|
|
4
|
+
readonly commentId: number;
|
|
5
|
+
readonly issueNumber: number;
|
|
6
|
+
readonly updatedAt: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export type DeletionApproval = {
|
|
10
|
+
readonly approved: ReadonlyArray<string>;
|
|
11
|
+
readonly evidence: ReadonlyArray<string>;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const NONE: DeletionApproval = { approved: [], evidence: [] };
|
|
15
|
+
const SHA = /^[0-9a-f]{40}$/u;
|
|
16
|
+
const RULING =
|
|
17
|
+
/^Owner ruling: allow production deletion\nTarget: (?<sha>[0-9a-f]{40})\n--allow-delete (?<names>[^\r\n]+)$/u;
|
|
18
|
+
const NAME = /^[^\s,*[\]]+(?:\([^()\r\n]*\))?[^\s,*[\]]*$/u;
|
|
19
|
+
const LOCAL_ISSUE =
|
|
20
|
+
/\b(?:fix(?:es|ed)?|close[sd]?|resolve[sd]?|refs?)\s+#(?<number>[1-9]\d*)\b/giu;
|
|
21
|
+
|
|
22
|
+
export const readDeletionApproval = async ({
|
|
23
|
+
github,
|
|
24
|
+
repository,
|
|
25
|
+
targetSha,
|
|
26
|
+
authority,
|
|
27
|
+
}: {
|
|
28
|
+
readonly github: Octokit;
|
|
29
|
+
readonly repository: string;
|
|
30
|
+
readonly targetSha: string;
|
|
31
|
+
readonly authority: ReadonlyArray<DeletionAuthority>;
|
|
32
|
+
}): Promise<DeletionApproval> => {
|
|
33
|
+
const [owner, repo, extra] = repository.split("/");
|
|
34
|
+
if (
|
|
35
|
+
owner === undefined ||
|
|
36
|
+
repo === undefined ||
|
|
37
|
+
owner === "" ||
|
|
38
|
+
repo === "" ||
|
|
39
|
+
extra !== undefined ||
|
|
40
|
+
!SHA.test(targetSha) ||
|
|
41
|
+
authority.length === 0
|
|
42
|
+
)
|
|
43
|
+
return NONE;
|
|
44
|
+
try {
|
|
45
|
+
const pulls = await github.paginate(
|
|
46
|
+
github.repos.listPullRequestsAssociatedWithCommit,
|
|
47
|
+
{ owner, repo, commit_sha: targetSha, per_page: 100 }
|
|
48
|
+
);
|
|
49
|
+
const linked = new Set(
|
|
50
|
+
pulls
|
|
51
|
+
.filter(
|
|
52
|
+
(pull) =>
|
|
53
|
+
pull.merge_commit_sha === targetSha &&
|
|
54
|
+
pull.merged_at !== null &&
|
|
55
|
+
pull.base.repo.full_name === repository &&
|
|
56
|
+
pull.base.ref === "main"
|
|
57
|
+
)
|
|
58
|
+
.flatMap((pull) =>
|
|
59
|
+
[...(pull.body ?? "").matchAll(LOCAL_ISSUE)].map((match) =>
|
|
60
|
+
Number(match.groups?.number)
|
|
61
|
+
)
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
const approved = new Set<string>();
|
|
65
|
+
const evidence: string[] = [];
|
|
66
|
+
for (const record of authority) {
|
|
67
|
+
if (
|
|
68
|
+
!linked.has(record.issueNumber) ||
|
|
69
|
+
!Number.isSafeInteger(record.commentId) ||
|
|
70
|
+
record.commentId <= 0 ||
|
|
71
|
+
record.updatedAt === ""
|
|
72
|
+
)
|
|
73
|
+
return NONE;
|
|
74
|
+
const { data: comment } = await github.issues.getComment({
|
|
75
|
+
owner,
|
|
76
|
+
repo,
|
|
77
|
+
comment_id: record.commentId,
|
|
78
|
+
});
|
|
79
|
+
const ruling = RULING.exec(comment.body ?? "")?.groups;
|
|
80
|
+
const names = ruling?.names?.split(",");
|
|
81
|
+
if (
|
|
82
|
+
comment.user?.login !== "birbprophet" ||
|
|
83
|
+
comment.issue_url !==
|
|
84
|
+
`https://api.github.com/repos/${repository}/issues/${record.issueNumber}` ||
|
|
85
|
+
comment.updated_at !== record.updatedAt ||
|
|
86
|
+
ruling?.sha !== targetSha ||
|
|
87
|
+
names === undefined ||
|
|
88
|
+
names.some((name) => !NAME.test(name)) ||
|
|
89
|
+
new Set(names).size !== names.length
|
|
90
|
+
)
|
|
91
|
+
return NONE;
|
|
92
|
+
for (const name of names) approved.add(name);
|
|
93
|
+
evidence.push(
|
|
94
|
+
`https://github.com/${repository}/issues/${record.issueNumber}#issuecomment-${record.commentId}`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
return { approved: [...approved], evidence };
|
|
98
|
+
} catch {
|
|
99
|
+
return NONE;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as Option from "effect/Option";
|
|
2
|
+
|
|
3
|
+
export type PlanChange = {
|
|
4
|
+
readonly resource: string;
|
|
5
|
+
readonly action: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type DeployPlan = {
|
|
9
|
+
readonly summary: string;
|
|
10
|
+
readonly changes: ReadonlyArray<PlanChange>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const RESOURCE =
|
|
14
|
+
/^\[(?<resource>[^\]\s[()]+(?:\([^()\][]*\))?)\] (?<action>create|update|noop|adopted|delete|replace|orphaned|unbind|run|drop|delete secret)(?: \([^\n]*\))*(?: \[action\])?$/u;
|
|
15
|
+
const COUNT =
|
|
16
|
+
/^(?<count>[1-9]\d*) (?<kind>to (?:create|update|noop|adopted|delete|replace|orphaned)|binding changes|tasks)$/u;
|
|
17
|
+
const DESTRUCTIVE = new Set([
|
|
18
|
+
"delete",
|
|
19
|
+
"replace",
|
|
20
|
+
"orphaned",
|
|
21
|
+
"unbind",
|
|
22
|
+
"drop",
|
|
23
|
+
"delete secret",
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
export const parsePlan = (output: string): Option.Option<DeployPlan> => {
|
|
27
|
+
const lines = output
|
|
28
|
+
.split("\n")
|
|
29
|
+
.map((line) =>
|
|
30
|
+
line
|
|
31
|
+
.trim()
|
|
32
|
+
.replace(/^(?:\[[^\]]+\] )?(?:INFO|WARN)(?: \([^)]*\))?:\s*/u, "")
|
|
33
|
+
);
|
|
34
|
+
const summaries = lines.filter((line) => line.startsWith("Plan: "));
|
|
35
|
+
const [summary] = summaries;
|
|
36
|
+
if (summaries.length !== 1 || summary === undefined) return Option.none();
|
|
37
|
+
const counts = new Map<string, number>();
|
|
38
|
+
const body = summary.slice("Plan: ".length);
|
|
39
|
+
if (body !== "no changes" && body !== "no resources") {
|
|
40
|
+
for (const part of body.split(", ")) {
|
|
41
|
+
const groups = COUNT.exec(part)?.groups;
|
|
42
|
+
const kind = groups?.kind;
|
|
43
|
+
const count = Number(groups?.count);
|
|
44
|
+
if (
|
|
45
|
+
kind === undefined ||
|
|
46
|
+
!Number.isSafeInteger(count) ||
|
|
47
|
+
counts.has(kind)
|
|
48
|
+
)
|
|
49
|
+
return Option.none();
|
|
50
|
+
counts.set(kind, count);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const changes: PlanChange[] = [];
|
|
54
|
+
const names = new Set<string>();
|
|
55
|
+
for (const [index, line] of lines.entries()) {
|
|
56
|
+
if (index <= lines.indexOf(summary) && !line.endsWith("] delete secret"))
|
|
57
|
+
continue;
|
|
58
|
+
if (!line.startsWith("[")) continue;
|
|
59
|
+
const groups = RESOURCE.exec(line)?.groups;
|
|
60
|
+
const resource = groups?.resource;
|
|
61
|
+
const action = groups?.action;
|
|
62
|
+
if (resource === undefined || action === undefined || names.has(resource))
|
|
63
|
+
return Option.none();
|
|
64
|
+
names.add(resource);
|
|
65
|
+
changes.push({ resource, action });
|
|
66
|
+
}
|
|
67
|
+
const actual = (action: string) =>
|
|
68
|
+
changes.filter((change) => change.action === action).length;
|
|
69
|
+
const noops = counts.get("to noop");
|
|
70
|
+
if (noops !== undefined && actual("noop") !== noops) return Option.none();
|
|
71
|
+
for (const action of ["delete", "replace", "orphaned"]) {
|
|
72
|
+
if (actual(action) !== (counts.get(`to ${action}`) ?? 0))
|
|
73
|
+
return Option.none();
|
|
74
|
+
}
|
|
75
|
+
if (actual("run") + actual("drop") !== (counts.get("tasks") ?? 0))
|
|
76
|
+
return Option.none();
|
|
77
|
+
const bindings = counts.get("binding changes") ?? 0;
|
|
78
|
+
if (actual("unbind") > bindings) return Option.none();
|
|
79
|
+
for (const action of ["create", "update", "adopted"]) {
|
|
80
|
+
if (actual(action) < (counts.get(`to ${action}`) ?? 0))
|
|
81
|
+
return Option.none();
|
|
82
|
+
}
|
|
83
|
+
const resourcesAndBindings = changes.filter(
|
|
84
|
+
({ action }) =>
|
|
85
|
+
action !== "noop" &&
|
|
86
|
+
action !== "run" &&
|
|
87
|
+
action !== "drop" &&
|
|
88
|
+
action !== "delete secret"
|
|
89
|
+
).length;
|
|
90
|
+
const expected = [...counts].reduce(
|
|
91
|
+
(total, [kind, count]) =>
|
|
92
|
+
total + (kind === "tasks" || kind === "to noop" ? 0 : count),
|
|
93
|
+
0
|
|
94
|
+
);
|
|
95
|
+
if (
|
|
96
|
+
resourcesAndBindings !== expected ||
|
|
97
|
+
(body === "no resources" && changes.length !== 0)
|
|
98
|
+
)
|
|
99
|
+
return Option.none();
|
|
100
|
+
return Option.some({ summary, changes });
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const blockingChanges = (
|
|
104
|
+
changes: ReadonlyArray<PlanChange>,
|
|
105
|
+
approved: ReadonlyArray<string>
|
|
106
|
+
): ReadonlyArray<PlanChange> =>
|
|
107
|
+
changes.filter(
|
|
108
|
+
({ resource, action }) =>
|
|
109
|
+
DESTRUCTIVE.has(action) && !approved.includes(resource)
|
|
110
|
+
);
|
|
111
|
+
|
|
112
|
+
export type PlanGate =
|
|
113
|
+
| { readonly kind: "Unreadable" }
|
|
114
|
+
| {
|
|
115
|
+
readonly kind: "Blocked";
|
|
116
|
+
readonly plan: DeployPlan;
|
|
117
|
+
readonly blocked: ReadonlyArray<PlanChange>;
|
|
118
|
+
}
|
|
119
|
+
| { readonly kind: "Allowed"; readonly plan: DeployPlan };
|
|
120
|
+
|
|
121
|
+
export const gatePlan = ({
|
|
122
|
+
output,
|
|
123
|
+
approved,
|
|
124
|
+
}: {
|
|
125
|
+
readonly output: string;
|
|
126
|
+
readonly approved: ReadonlyArray<string>;
|
|
127
|
+
}): PlanGate => {
|
|
128
|
+
const parsed = parsePlan(output);
|
|
129
|
+
if (Option.isNone(parsed)) return { kind: "Unreadable" };
|
|
130
|
+
const blocked = blockingChanges(parsed.value.changes, approved);
|
|
131
|
+
return blocked.length === 0
|
|
132
|
+
? { kind: "Allowed", plan: parsed.value }
|
|
133
|
+
: { kind: "Blocked", plan: parsed.value, blocked };
|
|
134
|
+
};
|
package/src/guard.ts
CHANGED
|
@@ -21,6 +21,8 @@ import {
|
|
|
21
21
|
foldkitPreset,
|
|
22
22
|
toolchainScopes,
|
|
23
23
|
} from "./lint.ts";
|
|
24
|
+
import { configuredExceptions, exceptionFindings } from "./lint/exceptions.ts";
|
|
25
|
+
export { exceptionFindings } from "./lint/exceptions.ts";
|
|
24
26
|
import { manifestRanges, type Ranges } from "./standard/manifest.ts";
|
|
25
27
|
export { exactFindings, manifestRanges } from "./standard/manifest.ts";
|
|
26
28
|
import { type Catalog, type Family, lead, versionOf } from "./versions.ts";
|
|
@@ -233,44 +235,28 @@ export const ruleFindings: {
|
|
|
233
235
|
(
|
|
234
236
|
{ overrides = [], ...config }: OxlintConfig,
|
|
235
237
|
list: ReadonlyArray<Exception> = shared
|
|
236
|
-
): ReadonlyArray<string> =>
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
238
|
+
): ReadonlyArray<string> => {
|
|
239
|
+
const local = configuredExceptions(config);
|
|
240
|
+
const configured = local.kind === "Read" ? local.exceptions : [];
|
|
241
|
+
return [
|
|
242
|
+
...(local.kind === "Invalid"
|
|
243
|
+
? ["the config has invalid issue-linked exceptions"]
|
|
244
|
+
: []),
|
|
245
|
+
...exceptionFindings(configured),
|
|
246
|
+
...Arr.flatMap(guarded, (rule) =>
|
|
247
|
+
Option.match(settingOf(config.rules, rule), {
|
|
248
|
+
onNone: () => [`${rule} is not set`],
|
|
249
|
+
onSome: (setting) =>
|
|
250
|
+
atError(setting) ? [] : [`${rule} is ${severityOf(setting)}`],
|
|
251
|
+
})
|
|
252
|
+
),
|
|
253
|
+
...overrideFindings("the config's", overrides, [...list, ...configured]),
|
|
254
|
+
...scopeFindings(overrides),
|
|
255
|
+
...inheritedFindings("", config),
|
|
256
|
+
];
|
|
257
|
+
}
|
|
248
258
|
);
|
|
249
259
|
|
|
250
|
-
const GLOB = /[*?[\]{}!]/u;
|
|
251
|
-
|
|
252
|
-
const ISSUE = /^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/\d+$/u;
|
|
253
|
-
|
|
254
|
-
export const exceptionFindings = (
|
|
255
|
-
list: ReadonlyArray<Exception> = shared
|
|
256
|
-
): ReadonlyArray<string> =>
|
|
257
|
-
Arr.flatMap(list, (exception, index) => [
|
|
258
|
-
...(Arr.isReadonlyArrayEmpty(exception.files)
|
|
259
|
-
? [`exception ${index} names no file`]
|
|
260
|
-
: []),
|
|
261
|
-
...Arr.flatMap(exception.files, (file) =>
|
|
262
|
-
GLOB.test(file)
|
|
263
|
-
? [`exception ${index} names ${file}, a pattern rather than a file`]
|
|
264
|
-
: []
|
|
265
|
-
),
|
|
266
|
-
...(Arr.isReadonlyArrayEmpty(exception.rules)
|
|
267
|
-
? [`exception ${index} names no rule`]
|
|
268
|
-
: []),
|
|
269
|
-
...(ISSUE.test(exception.issue)
|
|
270
|
-
? []
|
|
271
|
-
: [`exception ${index} has no issue link: ${exception.issue}`]),
|
|
272
|
-
]);
|
|
273
|
-
|
|
274
260
|
const familyTagFindings = (
|
|
275
261
|
registry: Packuments,
|
|
276
262
|
family: Family
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as Arr from "effect/Array";
|
|
2
|
+
import * as Schema from "effect/Schema";
|
|
3
|
+
import type { OxlintConfig } from "vite-plus/lint";
|
|
4
|
+
|
|
5
|
+
import { type Exception, exceptions as shared } from "../exceptions.ts";
|
|
6
|
+
|
|
7
|
+
export const exceptionSetting = "birbprophet/exceptions";
|
|
8
|
+
|
|
9
|
+
const ExceptionList = Schema.Array(
|
|
10
|
+
Schema.Struct({
|
|
11
|
+
files: Schema.Array(Schema.String),
|
|
12
|
+
rules: Schema.Array(Schema.String),
|
|
13
|
+
issue: Schema.String,
|
|
14
|
+
})
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const configuredExceptions = (
|
|
18
|
+
config: OxlintConfig
|
|
19
|
+
):
|
|
20
|
+
| { readonly kind: "Read"; readonly exceptions: ReadonlyArray<Exception> }
|
|
21
|
+
| { readonly kind: "Invalid" } => {
|
|
22
|
+
const value = config.settings?.[exceptionSetting] ?? [];
|
|
23
|
+
return Schema.is(ExceptionList)(value)
|
|
24
|
+
? { kind: "Read", exceptions: value }
|
|
25
|
+
: { kind: "Invalid" };
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const GLOB = /[*?[\]{}!]/u;
|
|
29
|
+
|
|
30
|
+
const ISSUE = /^https:\/\/github\.com\/[\w.-]+\/[\w.-]+\/issues\/\d+$/u;
|
|
31
|
+
|
|
32
|
+
export const exceptionFindings = (
|
|
33
|
+
list: ReadonlyArray<Exception> = shared
|
|
34
|
+
): ReadonlyArray<string> =>
|
|
35
|
+
Arr.flatMap(list, (exception, index) => [
|
|
36
|
+
...(Arr.isReadonlyArrayEmpty(exception.files)
|
|
37
|
+
? [`exception ${index} names no file`]
|
|
38
|
+
: []),
|
|
39
|
+
...Arr.flatMap(exception.files, (file) =>
|
|
40
|
+
GLOB.test(file)
|
|
41
|
+
? [`exception ${index} names ${file}, a pattern rather than a file`]
|
|
42
|
+
: []
|
|
43
|
+
),
|
|
44
|
+
...(Arr.isReadonlyArrayEmpty(exception.rules)
|
|
45
|
+
? [`exception ${index} names no rule`]
|
|
46
|
+
: []),
|
|
47
|
+
...(ISSUE.test(exception.issue)
|
|
48
|
+
? []
|
|
49
|
+
: [`exception ${index} has no issue link: ${exception.issue}`]),
|
|
50
|
+
]);
|
package/src/lint.ts
CHANGED
|
@@ -10,11 +10,13 @@ import type { OxlintConfig, OxlintOverride } from "vite-plus/lint";
|
|
|
10
10
|
import effectPlugin from "./effect-plugin.ts";
|
|
11
11
|
import { effectTsgoPlugin, effectTsgoRules } from "./effect-tsgo.ts";
|
|
12
12
|
import { type Exception, exceptions } from "./exceptions.ts";
|
|
13
|
+
import { exceptionFindings, exceptionSetting } from "./lint/exceptions.ts";
|
|
13
14
|
import birbprophetPlugin from "./plugin.ts";
|
|
14
15
|
import { staticRules } from "./rules.ts";
|
|
15
16
|
|
|
16
17
|
export type LintOptions = {
|
|
17
18
|
readonly ignores?: ReadonlyArray<string>;
|
|
19
|
+
readonly exceptions?: ReadonlyArray<Exception>;
|
|
18
20
|
};
|
|
19
21
|
|
|
20
22
|
const plugins: OxlintConfig["plugins"] = [
|
|
@@ -143,28 +145,36 @@ const exceptionTier = (exception: Exception): OxlintOverride => ({
|
|
|
143
145
|
),
|
|
144
146
|
});
|
|
145
147
|
|
|
146
|
-
export const lint = ({
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
148
|
+
export const lint = ({
|
|
149
|
+
ignores = [],
|
|
150
|
+
exceptions: local = [],
|
|
151
|
+
}: LintOptions = {}): OxlintConfig => {
|
|
152
|
+
const findings = exceptionFindings(local);
|
|
153
|
+
if (findings.length > 0) throw new Error(findings.join("\n"));
|
|
154
|
+
return {
|
|
155
|
+
...(local.length > 0 ? { settings: { [exceptionSetting]: local } } : {}),
|
|
156
|
+
plugins,
|
|
157
|
+
categories,
|
|
158
|
+
jsPlugins: [
|
|
159
|
+
{ name: "vite-plus", specifier: resolved("vite-plus/oxlint-plugin") },
|
|
160
|
+
{ name: "foldkit", specifier: sibling("foldkit-plugin") },
|
|
161
|
+
{ name: effectPlugin.meta.name, specifier: sibling("effect-plugin") },
|
|
162
|
+
{ name: birbprophetPlugin.meta.name, specifier: sibling("plugin") },
|
|
163
|
+
],
|
|
164
|
+
options: { typeAware: true, typeCheck: true },
|
|
165
|
+
rules: {
|
|
166
|
+
...foldkitPreset.rules,
|
|
167
|
+
...staticRules,
|
|
168
|
+
"vite-plus/prefer-vite-plus-imports": "error",
|
|
169
|
+
...effectRules,
|
|
170
|
+
...birbprophetRules,
|
|
171
|
+
...effectTsgoRules,
|
|
172
|
+
},
|
|
173
|
+
overrides: [
|
|
174
|
+
...foldkitPreset.overrides,
|
|
175
|
+
...toolchainScopes,
|
|
176
|
+
...Arr.map([...exceptions, ...local], exceptionTier),
|
|
177
|
+
],
|
|
178
|
+
ignorePatterns: [...coreIgnores, ...ignores],
|
|
179
|
+
};
|
|
180
|
+
};
|