@brainervirus/workit-core 2.8.0 → 3.0.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.
@@ -1,37 +0,0 @@
1
- #!/usr/bin/env bun
2
- // DG-09: installers run the shared offline doctor after writing configuration and
3
- // return nonzero when a required registration/config check fails. `installer:
4
- // true` limits the enforced checks to the ones the installer just guaranteed, so
5
- // a dev/stub checkout without built assets does not fail a post-install run.
6
- // CA-02: `cursor --stale` is the installer's self-heal pre-check — it exits 2
7
- // when the doctor's stale_install check fails and 0 otherwise. A
8
- // registry-unreachable comparison warns as registry_unreachable and is NOT
9
- // stale (CA-04): no false stale_install and no install failure. Other check
10
- // failures are left to the post-install gate.
11
- import { runDoctor } from "../src/core/doctor";
12
-
13
- const hostArg = process.argv[2];
14
- const host = hostArg === "cursor" ? "cursor" : hostArg === "cli" ? "cli" : "opencode";
15
- const staleOnly = process.argv.includes("--stale");
16
- const report = runDoctor({ host, installer: true });
17
-
18
- if (staleOnly) {
19
- const stale = report.checks.find((c) => c.id === "stale_install");
20
- if (stale?.status === "fail") {
21
- process.stderr.write(`STALE: ${stale.detail}\n`);
22
- if (stale.fix) process.stderr.write(` fix: ${stale.fix}\n`);
23
- process.exit(2);
24
- }
25
- process.exit(0);
26
- }
27
-
28
- if (report.exitCode !== 0) {
29
- for (const check of report.checks) {
30
- if (check.status === "fail") {
31
- process.stderr.write(`FATAL: workit doctor ${check.id}: ${check.detail}\n`);
32
- if (check.fix) process.stderr.write(` fix: ${check.fix}\n`);
33
- }
34
- }
35
- process.exit(1);
36
- }
37
- process.exit(0);
@@ -1,180 +0,0 @@
1
- import { createHash } from "node:crypto";
2
- import { existsSync, readFileSync } from "node:fs";
3
- import path from "node:path";
4
- import { isConfigObject, mergePreset, type BranchPreset, type ToolkitConfig } from "./config";
5
- import { writeFileAtomic } from "./safe-write";
6
-
7
- export type ConversionInput = {
8
- configDir: string;
9
- };
10
-
11
- export type ConversionMapping = {
12
- key: string;
13
- from: unknown;
14
- to: unknown;
15
- note?: string;
16
- };
17
-
18
- export type ConversionUnresolved = {
19
- key: string;
20
- reason: string;
21
- };
22
-
23
- export type ConversionPreview = {
24
- mappings: ConversionMapping[];
25
- preserved: string[];
26
- unresolved: ConversionUnresolved[];
27
- };
28
-
29
- const REDACT_KEYS = /token|secret|password|credential/i;
30
-
31
- const readJsonObject = (file: string): Record<string, unknown> | null => {
32
- if (!existsSync(file)) return null;
33
- try {
34
- const parsed = JSON.parse(readFileSync(file, "utf8"));
35
- return isConfigObject(parsed) ? parsed : null;
36
- } catch {
37
- return null;
38
- }
39
- };
40
-
41
- const redactValue = (key: string, value: unknown): unknown => {
42
- if (REDACT_KEYS.test(key)) return "[redacted]";
43
- if (typeof value === "string" && value.length > 8 && !value.includes(" ")) return "[redacted]";
44
- return value;
45
- };
46
-
47
- export const redactConversionPreview = (preview: ConversionPreview): ConversionPreview => ({
48
- mappings: preview.mappings.map((m) => ({
49
- ...m,
50
- from: redactValue(m.key, m.from),
51
- to: redactValue(m.key, m.to),
52
- })),
53
- preserved: preview.preserved,
54
- unresolved: preview.unresolved,
55
- });
56
-
57
- export function previewConversion(input: ConversionInput): ConversionPreview {
58
- const configFile = path.join(input.configDir, "config.json");
59
- const config = readJsonObject(configFile);
60
- const mappings: ConversionMapping[] = [];
61
- const unresolved: ConversionUnresolved[] = [];
62
- const preserved: string[] = [];
63
-
64
- if (config) {
65
- if (config.locale !== undefined) {
66
- mappings.push({ key: "locale", from: config.locale, to: config.locale });
67
- }
68
- if (config.branchPolicy !== undefined && isConfigObject(config.branchPolicy)) {
69
- const bp = config.branchPolicy as ToolkitConfig["branchPolicy"] & {
70
- allowed?: string[];
71
- protected?: string[];
72
- };
73
- const preset = bp.preset ?? "gitflow";
74
- const merged = mergePreset(
75
- preset,
76
- {
77
- allowed: Array.isArray(bp.allowed) ? bp.allowed : undefined,
78
- protectedNames: Array.isArray(bp.protected) ? bp.protected : undefined,
79
- },
80
- { branchPolicy: bp },
81
- );
82
- mappings.push({
83
- key: "branchPolicy",
84
- from: config.branchPolicy,
85
- to: merged,
86
- note: "preset-derived allowed/protected reset through mergePreset",
87
- });
88
- if (preset === "custom" && Array.isArray(bp.allowed)) {
89
- if (bp.allowed.includes("*")) {
90
- unresolved.push({
91
- key: "branchPolicy.allowed",
92
- reason: 'unsupported permissive value "*" requires an explicit v1 choice',
93
- });
94
- }
95
- }
96
- }
97
- if (config.workflowMode !== undefined) {
98
- unresolved.push({
99
- key: "legacyWorkflowMode",
100
- reason: "0.x workflow mode has no automatic v1 equivalent; choose how to continue",
101
- });
102
- }
103
- }
104
-
105
- for (const name of ["youtrack.json", "vcs.json", "workspaces.json"]) {
106
- const file = path.join(input.configDir, name);
107
- if (!existsSync(file)) continue;
108
- const parsed = readJsonObject(file);
109
- if (parsed)
110
- mappings.push({ key: name, from: parsed, to: parsed, note: "carry forward unchanged" });
111
- }
112
-
113
- for (const token of ["youtrack.token", "gitlab.token", "github.token"]) {
114
- const file = path.join(input.configDir, token);
115
- if (existsSync(file)) preserved.push(file);
116
- }
117
-
118
- return { mappings, preserved, unresolved };
119
- }
120
-
121
- export const conversionDigest = (preview: ConversionPreview): string =>
122
- createHash("sha256")
123
- .update(JSON.stringify(redactConversionPreview(preview)))
124
- .digest("hex");
125
-
126
- export type ConversionApplyResult = {
127
- configPath: string;
128
- choicesPath: string;
129
- };
130
-
131
- /** Apply approved conversion mappings and record explicit resolution choices. */
132
- export function applyConversionConfig(
133
- configDir: string,
134
- preview: ConversionPreview,
135
- resolutions: Record<string, string>,
136
- ): ConversionApplyResult {
137
- const configFile = path.join(configDir, "config.json");
138
- const raw = readJsonObject(configFile) ?? {};
139
- const next: Record<string, unknown> = { ...raw };
140
-
141
- for (const mapping of preview.mappings) {
142
- if (mapping.key === "locale") {
143
- next[mapping.key] = mapping.to;
144
- }
145
- if (mapping.key === "branchPolicy" && !resolutions["branchPolicy.allowed"]) {
146
- next.branchPolicy = mapping.to;
147
- }
148
- }
149
-
150
- if (resolutions["branchPolicy.allowed"]) {
151
- const bp = isConfigObject(next.branchPolicy)
152
- ? (next.branchPolicy as ToolkitConfig["branchPolicy"])
153
- : { preset: "custom" as BranchPreset, allowed: [], protected: [] };
154
- const preset = bp.preset ?? "custom";
155
- next.branchPolicy = mergePreset(
156
- preset,
157
- {
158
- allowed: resolutions["branchPolicy.allowed"]
159
- .split(",")
160
- .map((s) => s.trim())
161
- .filter(Boolean),
162
- },
163
- { branchPolicy: bp },
164
- );
165
- }
166
-
167
- if (resolutions["legacyWorkflowMode"]) {
168
- delete next.workflowMode;
169
- }
170
-
171
- writeFileAtomic(configFile, JSON.stringify(next, null, 2) + "\n");
172
-
173
- const choicesPath = path.join(configDir, "cutover-choices.json");
174
- writeFileAtomic(
175
- choicesPath,
176
- JSON.stringify({ resolutions, applied_at: new Date().toISOString() }, null, 2) + "\n",
177
- );
178
-
179
- return { configPath: configFile, choicesPath };
180
- }