@plainconceptsplatform/workflows 0.1.5 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -2
- package/dist/catalog-installation.d.ts +8 -0
- package/dist/catalog-installation.js +29 -5
- package/dist/catalog-installation.test.js +101 -13
- package/dist/index.js +14 -1
- package/dist/tui.d.ts +25 -0
- package/dist/tui.js +254 -0
- package/dist/tui.test.d.ts +1 -0
- package/dist/tui.test.js +246 -0
- package/dist/workflow-catalog.d.ts +6 -1
- package/dist/workflow-catalog.js +5 -0
- package/loops/actions/verify-route-matrix/verify-route-matrix.sh +3 -3
- package/loops/scripts/compile-agent-workflows.mjs +29 -29
- package/loops/workflows/agent-apply-review.md +3 -2
- package/loops/workflows/agent-audit.md +2 -1
- package/loops/workflows/agent-direct.md +9 -8
- package/loops/workflows/agent-implement.md +7 -6
- package/loops/workflows/agent-merge-gate.md +5 -4
- package/loops/workflows/agent-propose.md +2 -1
- package/loops/workflows/agent-refine.md +3 -2
- package/loops/workflows/shared/opencode-ci.md +108 -1
- package/loops/workflows/shared/platform-defaults.md +2 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,11 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
Install and update shared GitHub Agentic Workflows for Plain Concepts Platform repositories.
|
|
4
4
|
|
|
5
|
+
## Quick start
|
|
6
|
+
|
|
7
|
+
The primary entrypoint is the interactive TUI. Run it with no arguments:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @plainconceptsplatform/workflows
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The TUI lists all routes and templates with install status. Arrow keys navigate, space toggles, Enter installs. Selecting any route installs the full managed catalog plus mandatory `opencode.ci.json` and `scripts/compile-agent-workflows.mjs`. Selecting only templates still installs those mandatory files.
|
|
14
|
+
|
|
5
15
|
## Install
|
|
6
16
|
|
|
7
17
|
Before installing workflows, install and configure [`PlainConceptsPlatform/opencode-onboard`](https://github.com/PlainConceptsPlatform/opencode-onboard) in the consumer repository. Loop workers invoke the skills and commands it provides. Verify the required skills and commands are available before compiling workflows.
|
|
8
18
|
|
|
9
|
-
For
|
|
19
|
+
For non-interactive use (advanced):
|
|
10
20
|
|
|
11
21
|
```bash
|
|
12
22
|
npx @plainconceptsplatform/workflows@latest init
|
|
@@ -18,13 +28,14 @@ For a project-local development dependency:
|
|
|
18
28
|
|
|
19
29
|
```bash
|
|
20
30
|
pnpm add -D @plainconceptsplatform/workflows
|
|
31
|
+
pnpm exec workflows # launch interactive TUI
|
|
21
32
|
pnpm exec workflows init
|
|
22
33
|
pnpm exec workflows add
|
|
23
34
|
```
|
|
24
35
|
|
|
25
36
|
`init` inspects the repository and reports its stack and visibility. It does not create or manage repository configuration or a manifest.
|
|
26
37
|
|
|
27
|
-
`add` installs package-owned files. It stops when a managed file differs. Use `pnpm exec workflows update --force` only when you intend to replace managed workflow files.
|
|
38
|
+
`add` installs package-owned files including the mandatory `opencode.ci.json` and `scripts/compile-agent-workflows.mjs`. It stops when a managed file differs. Use `pnpm exec workflows update --force` only when you intend to replace managed workflow files.
|
|
28
39
|
|
|
29
40
|
Install optional standalone templates with `add --template`. Available templates are `agentics-checks`, `agentics-maintenance`, `app-ci-dotnet-next`, and `app-ci-node-monorepo`. CI templates are stack-specific copies, not a combined template. Edit their top-level `env:` values for repository paths, package names, and commands.
|
|
30
41
|
|
|
@@ -7,7 +7,15 @@ export interface CatalogInstallOptions {
|
|
|
7
7
|
readonly force?: boolean;
|
|
8
8
|
readonly sourcePath?: string;
|
|
9
9
|
}
|
|
10
|
+
interface CatalogFile {
|
|
11
|
+
readonly source: string;
|
|
12
|
+
readonly target: string;
|
|
13
|
+
readonly managed: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare function mandatoryFileSpecs(sourcePath: string): CatalogFile[];
|
|
10
16
|
export declare function catalogSourcePath(modulePath?: string): string;
|
|
11
17
|
export declare function installCatalog(repositoryPath: string, options?: CatalogInstallOptions): Promise<CatalogInstallResult>;
|
|
12
18
|
export declare function installTemplate(repositoryPath: string, template: TemplateName, options?: CatalogInstallOptions): Promise<CatalogInstallResult>;
|
|
19
|
+
export declare function installMandatoryFiles(repositoryPath: string, options?: CatalogInstallOptions): Promise<CatalogInstallResult>;
|
|
13
20
|
export declare function isTemplateName(value: string): value is TemplateName;
|
|
21
|
+
export {};
|
|
@@ -2,33 +2,41 @@ import { access, copyFile, mkdir, readFile, readdir } from "node:fs/promises";
|
|
|
2
2
|
import { constants } from "node:fs";
|
|
3
3
|
import { dirname, join, relative, resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
|
-
import { catalogTemplates, templateNames } from "./workflow-catalog.js";
|
|
5
|
+
import { catalogTemplates, mandatoryFiles, templateNames } from "./workflow-catalog.js";
|
|
6
6
|
const sourceMappings = [
|
|
7
7
|
["actions", ".github/actions"],
|
|
8
8
|
["workflows", ".github/workflows"],
|
|
9
9
|
["scripts", "scripts"],
|
|
10
10
|
];
|
|
11
|
+
export function mandatoryFileSpecs(sourcePath) {
|
|
12
|
+
return mandatoryFiles.map((spec) => ({
|
|
13
|
+
source: join(sourcePath, spec.source),
|
|
14
|
+
target: spec.target,
|
|
15
|
+
managed: true,
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
11
18
|
export function catalogSourcePath(modulePath = fileURLToPath(import.meta.url)) {
|
|
12
19
|
return resolve(dirname(modulePath), "..", "loops");
|
|
13
20
|
}
|
|
14
21
|
export async function installCatalog(repositoryPath, options = {}) {
|
|
15
22
|
const sourcePath = options.sourcePath ?? catalogSourcePath();
|
|
16
|
-
const files = await catalogFiles(sourcePath);
|
|
17
|
-
const
|
|
23
|
+
const files = [...await catalogFiles(sourcePath), ...mandatoryFileSpecs(sourcePath)];
|
|
24
|
+
const deduplicated = files.filter((file, index) => files.findIndex((f) => f.target === file.target) === index).sort((left, right) => left.target.localeCompare(right.target));
|
|
25
|
+
const managedFiles = deduplicated.filter((file) => file.managed);
|
|
18
26
|
const conflicts = (await Promise.all(managedFiles.map(async (file) => {
|
|
19
27
|
const destination = join(repositoryPath, file.target);
|
|
20
28
|
return await exists(destination) && !(await filesMatch(file.source, destination)) ? file.target : undefined;
|
|
21
29
|
}))).filter((file) => file !== undefined);
|
|
22
30
|
if (conflicts.length > 0 && !options.force)
|
|
23
31
|
return { installed: [], conflicts };
|
|
24
|
-
await Promise.all(
|
|
32
|
+
await Promise.all(deduplicated.map(async (file) => {
|
|
25
33
|
const destination = join(repositoryPath, file.target);
|
|
26
34
|
if (!file.managed && await exists(destination))
|
|
27
35
|
return;
|
|
28
36
|
await mkdir(dirname(destination), { recursive: true });
|
|
29
37
|
await copyFile(file.source, destination);
|
|
30
38
|
}));
|
|
31
|
-
return { installed:
|
|
39
|
+
return { installed: deduplicated.map((file) => file.target), conflicts };
|
|
32
40
|
}
|
|
33
41
|
export async function installTemplate(repositoryPath, template, options = {}) {
|
|
34
42
|
const sourcePath = options.sourcePath ?? catalogSourcePath();
|
|
@@ -43,6 +51,22 @@ export async function installTemplate(repositoryPath, template, options = {}) {
|
|
|
43
51
|
await copyFile(source, destination);
|
|
44
52
|
return { installed: [target], conflicts };
|
|
45
53
|
}
|
|
54
|
+
export async function installMandatoryFiles(repositoryPath, options = {}) {
|
|
55
|
+
const sourcePath = options.sourcePath ?? catalogSourcePath();
|
|
56
|
+
const files = mandatoryFileSpecs(sourcePath).sort((left, right) => left.target.localeCompare(right.target));
|
|
57
|
+
const conflicts = (await Promise.all(files.map(async (file) => {
|
|
58
|
+
const destination = join(repositoryPath, file.target);
|
|
59
|
+
return await exists(destination) && !(await filesMatch(file.source, destination)) ? file.target : undefined;
|
|
60
|
+
}))).filter((file) => file !== undefined);
|
|
61
|
+
if (conflicts.length > 0 && !options.force)
|
|
62
|
+
return { installed: [], conflicts };
|
|
63
|
+
await Promise.all(files.map(async (file) => {
|
|
64
|
+
const destination = join(repositoryPath, file.target);
|
|
65
|
+
await mkdir(dirname(destination), { recursive: true });
|
|
66
|
+
await copyFile(file.source, destination);
|
|
67
|
+
}));
|
|
68
|
+
return { installed: files.map((file) => file.target), conflicts };
|
|
69
|
+
}
|
|
46
70
|
export function isTemplateName(value) {
|
|
47
71
|
return templateNames.includes(value);
|
|
48
72
|
}
|
|
@@ -2,7 +2,7 @@ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { afterEach, describe, expect, it } from "vitest";
|
|
5
|
-
import { catalogSourcePath, installCatalog, installTemplate } from "./catalog-installation.js";
|
|
5
|
+
import { catalogSourcePath, installCatalog, installMandatoryFiles, installTemplate } from "./catalog-installation.js";
|
|
6
6
|
const temporaryDirectories = [];
|
|
7
7
|
afterEach(async () => {
|
|
8
8
|
await Promise.all(temporaryDirectories.splice(0).map((directory) => rm(directory, { force: true, recursive: true })));
|
|
@@ -15,12 +15,14 @@ describe("catalog installation", () => {
|
|
|
15
15
|
});
|
|
16
16
|
expect(catalogSourcePath(join(packageDirectory, "dist", "catalog-installation.js"))).toBe(join(packageDirectory, "loops"));
|
|
17
17
|
});
|
|
18
|
-
it("installs package-owned loops files", async () => {
|
|
18
|
+
it("installs package-owned loops files including mandatory opencode.ci.json and compile script", async () => {
|
|
19
19
|
const sourcePath = await createDirectory({
|
|
20
20
|
"actions/check/action.yml": "name: Check\n",
|
|
21
21
|
"workflows/agent-check.md": "# Check\n",
|
|
22
22
|
"workflows/shared/defaults.md": "defaults\n",
|
|
23
|
-
"scripts/compile.mjs": "console.log('compile');\n",
|
|
23
|
+
"scripts/compile-agent-workflows.mjs": "console.log('compile');\n",
|
|
24
|
+
"scripts/compile.mjs": "console.log('old compile');\n",
|
|
25
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
24
26
|
"workflows/agent-check.lock.yml": "generated\n",
|
|
25
27
|
"actions/actions-lock.json": "generated\n",
|
|
26
28
|
});
|
|
@@ -30,6 +32,8 @@ describe("catalog installation", () => {
|
|
|
30
32
|
".github/actions/check/action.yml",
|
|
31
33
|
".github/workflows/agent-check.md",
|
|
32
34
|
".github/workflows/shared/defaults.md",
|
|
35
|
+
"opencode.ci.json",
|
|
36
|
+
"scripts/compile-agent-workflows.mjs",
|
|
33
37
|
"scripts/compile.mjs",
|
|
34
38
|
],
|
|
35
39
|
conflicts: [],
|
|
@@ -41,7 +45,8 @@ describe("catalog installation", () => {
|
|
|
41
45
|
const sourcePath = await createDirectory({
|
|
42
46
|
"actions/check/action.yml": "# Managed by @plainconceptsplatform/workflows. Source: loops/actions/check/action.yml. Update with `workflows update --force`; consumer edits may be overwritten.\nname: Check\n",
|
|
43
47
|
"workflows/agent-check.md": `---\n${header}# Check\n`,
|
|
44
|
-
"scripts/compile.mjs": "// Managed by @plainconceptsplatform/workflows. Source: loops/scripts/compile.mjs. Update with `workflows update --force`; consumer edits may be overwritten.\n",
|
|
48
|
+
"scripts/compile-agent-workflows.mjs": "// Managed by @plainconceptsplatform/workflows. Source: loops/scripts/compile-agent-workflows.mjs. Update with `workflows update --force`; consumer edits may be overwritten.\n",
|
|
49
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
45
50
|
"templates/agentics/agentics-checks.yml": `${templateHeader}name: Agentics checks\n`,
|
|
46
51
|
});
|
|
47
52
|
const repositoryPath = await createDirectory({});
|
|
@@ -54,7 +59,8 @@ describe("catalog installation", () => {
|
|
|
54
59
|
const sourcePath = await createDirectory({
|
|
55
60
|
"actions/check/action.yml": "name: Check\n",
|
|
56
61
|
"workflows/agent-check.md": "# Check\n",
|
|
57
|
-
"scripts/compile.mjs": "compile\n",
|
|
62
|
+
"scripts/compile-agent-workflows.mjs": "compile\n",
|
|
63
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
58
64
|
});
|
|
59
65
|
const repositoryPath = await createDirectory({ ".github/workflows/agent-check.md": "# Check\n" });
|
|
60
66
|
await expect(installCatalog(repositoryPath, { sourcePath })).resolves.toMatchObject({ conflicts: [] });
|
|
@@ -63,7 +69,8 @@ describe("catalog installation", () => {
|
|
|
63
69
|
const sourcePath = await createDirectory({
|
|
64
70
|
"actions/check/action.yml": "name: Check\n",
|
|
65
71
|
"workflows/agent-check.md": "# Check\n",
|
|
66
|
-
"scripts/compile.mjs": "compile\n",
|
|
72
|
+
"scripts/compile-agent-workflows.mjs": "compile\n",
|
|
73
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
67
74
|
});
|
|
68
75
|
const repositoryPath = await createDirectory({
|
|
69
76
|
".github/workflows/shared/repo-config.md": "legacy consumer config\n",
|
|
@@ -72,7 +79,8 @@ describe("catalog installation", () => {
|
|
|
72
79
|
installed: [
|
|
73
80
|
".github/actions/check/action.yml",
|
|
74
81
|
".github/workflows/agent-check.md",
|
|
75
|
-
"
|
|
82
|
+
"opencode.ci.json",
|
|
83
|
+
"scripts/compile-agent-workflows.mjs",
|
|
76
84
|
],
|
|
77
85
|
conflicts: [],
|
|
78
86
|
});
|
|
@@ -82,26 +90,30 @@ describe("catalog installation", () => {
|
|
|
82
90
|
const sourcePath = await createDirectory({
|
|
83
91
|
"actions/check/action.yml": "package action\n",
|
|
84
92
|
"workflows/agent-check.md": "package workflow\n",
|
|
85
|
-
"scripts/compile.mjs": "package script\n",
|
|
93
|
+
"scripts/compile-agent-workflows.mjs": "package script\n",
|
|
94
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
86
95
|
});
|
|
87
96
|
const repositoryPath = await createDirectory({
|
|
88
97
|
".github/actions/check/action.yml": "consumer action\n",
|
|
89
98
|
".github/workflows/agent-check.md": "consumer workflow\n",
|
|
90
|
-
"scripts/compile.mjs": "consumer script\n",
|
|
99
|
+
"scripts/compile-agent-workflows.mjs": "consumer script\n",
|
|
100
|
+
"opencode.ci.json": "{ \"model\": \"consumer-model\" }\n",
|
|
91
101
|
});
|
|
92
102
|
await expect(installCatalog(repositoryPath, { sourcePath })).resolves.toEqual({
|
|
93
103
|
installed: [],
|
|
94
104
|
conflicts: [
|
|
95
105
|
".github/actions/check/action.yml",
|
|
96
106
|
".github/workflows/agent-check.md",
|
|
97
|
-
"
|
|
107
|
+
"opencode.ci.json",
|
|
108
|
+
"scripts/compile-agent-workflows.mjs",
|
|
98
109
|
],
|
|
99
110
|
});
|
|
100
111
|
await expect(installCatalog(repositoryPath, { force: true, sourcePath })).resolves.toMatchObject({
|
|
101
112
|
conflicts: [
|
|
102
113
|
".github/actions/check/action.yml",
|
|
103
114
|
".github/workflows/agent-check.md",
|
|
104
|
-
"
|
|
115
|
+
"opencode.ci.json",
|
|
116
|
+
"scripts/compile-agent-workflows.mjs",
|
|
105
117
|
],
|
|
106
118
|
});
|
|
107
119
|
await expect(readFile(join(repositoryPath, ".github/actions/check/action.yml"), "utf8")).resolves.toBe("package action\n");
|
|
@@ -110,10 +122,10 @@ describe("catalog installation", () => {
|
|
|
110
122
|
const sourcePath = await createDirectory({
|
|
111
123
|
"actions/check/action.yml": "name: Check\n",
|
|
112
124
|
"workflows/agent-check.md": "# Check\n",
|
|
113
|
-
"scripts/compile.mjs": "compile\n",
|
|
125
|
+
"scripts/compile-agent-workflows.mjs": "compile\n",
|
|
126
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
114
127
|
"templates/agentics/agentics-checks.yml": "name: Agentics checks\n",
|
|
115
128
|
"templates/ci/app-ci-node-monorepo.yml": "name: Node CI\n",
|
|
116
|
-
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
117
129
|
});
|
|
118
130
|
const repositoryPath = await createDirectory({});
|
|
119
131
|
await installCatalog(repositoryPath, { sourcePath });
|
|
@@ -127,6 +139,82 @@ describe("catalog installation", () => {
|
|
|
127
139
|
conflicts: [],
|
|
128
140
|
});
|
|
129
141
|
});
|
|
142
|
+
it("installCatalog installs mandatory opencode.ci.json and compile script alongside catalog files", async () => {
|
|
143
|
+
const sourcePath = await createDirectory({
|
|
144
|
+
"actions/check/action.yml": "name: Check\n",
|
|
145
|
+
"workflows/agent-check.md": "# Check\n",
|
|
146
|
+
"scripts/compile-agent-workflows.mjs": "compile\n",
|
|
147
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
148
|
+
});
|
|
149
|
+
const repositoryPath = await createDirectory({});
|
|
150
|
+
const result = await installCatalog(repositoryPath, { sourcePath });
|
|
151
|
+
expect(result.installed).toContain("opencode.ci.json");
|
|
152
|
+
expect(result.installed).toContain("scripts/compile-agent-workflows.mjs");
|
|
153
|
+
await expect(readFile(join(repositoryPath, "opencode.ci.json"), "utf8")).resolves.toBe("{ \"model\": \"plainconcepts/glm-5-2\" }\n");
|
|
154
|
+
await expect(readFile(join(repositoryPath, "scripts/compile-agent-workflows.mjs"), "utf8")).resolves.toBe("compile\n");
|
|
155
|
+
});
|
|
156
|
+
it("installMandatoryFiles installs opencode.ci.json and compile script without catalog files", async () => {
|
|
157
|
+
const sourcePath = await createDirectory({
|
|
158
|
+
"scripts/compile-agent-workflows.mjs": "compile\n",
|
|
159
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
160
|
+
});
|
|
161
|
+
const repositoryPath = await createDirectory({});
|
|
162
|
+
const result = await installMandatoryFiles(repositoryPath, { sourcePath });
|
|
163
|
+
expect(result.installed).toEqual(["opencode.ci.json", "scripts/compile-agent-workflows.mjs"]);
|
|
164
|
+
await expect(readFile(join(repositoryPath, "opencode.ci.json"), "utf8")).resolves.toBe("{ \"model\": \"plainconcepts/glm-5-2\" }\n");
|
|
165
|
+
await expect(readFile(join(repositoryPath, "scripts/compile-agent-workflows.mjs"), "utf8")).resolves.toBe("compile\n");
|
|
166
|
+
});
|
|
167
|
+
it("installMandatoryFiles reports conflicts on differing files", async () => {
|
|
168
|
+
const sourcePath = await createDirectory({
|
|
169
|
+
"scripts/compile-agent-workflows.mjs": "package script\n",
|
|
170
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
171
|
+
});
|
|
172
|
+
const repositoryPath = await createDirectory({
|
|
173
|
+
"opencode.ci.json": "{ \"model\": \"consumer\" }\n",
|
|
174
|
+
"scripts/compile-agent-workflows.mjs": "consumer script\n",
|
|
175
|
+
});
|
|
176
|
+
await expect(installMandatoryFiles(repositoryPath, { sourcePath })).resolves.toEqual({
|
|
177
|
+
installed: [],
|
|
178
|
+
conflicts: ["opencode.ci.json", "scripts/compile-agent-workflows.mjs"],
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
it("installMandatoryFiles overwrites with force", async () => {
|
|
182
|
+
const sourcePath = await createDirectory({
|
|
183
|
+
"scripts/compile-agent-workflows.mjs": "package script\n",
|
|
184
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
185
|
+
});
|
|
186
|
+
const repositoryPath = await createDirectory({
|
|
187
|
+
"opencode.ci.json": "{ \"model\": \"consumer\" }\n",
|
|
188
|
+
"scripts/compile-agent-workflows.mjs": "consumer script\n",
|
|
189
|
+
});
|
|
190
|
+
await expect(installMandatoryFiles(repositoryPath, { force: true, sourcePath })).resolves.toMatchObject({
|
|
191
|
+
installed: ["opencode.ci.json", "scripts/compile-agent-workflows.mjs"],
|
|
192
|
+
});
|
|
193
|
+
await expect(readFile(join(repositoryPath, "opencode.ci.json"), "utf8")).resolves.toBe("{ \"model\": \"plainconcepts/glm-5-2\" }\n");
|
|
194
|
+
});
|
|
195
|
+
it("installMandatoryFiles does not install catalog workflow files", async () => {
|
|
196
|
+
const sourcePath = await createDirectory({
|
|
197
|
+
"actions/check/action.yml": "name: Check\n",
|
|
198
|
+
"workflows/agent-check.md": "# Check\n",
|
|
199
|
+
"scripts/compile-agent-workflows.mjs": "compile\n",
|
|
200
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
201
|
+
});
|
|
202
|
+
const repositoryPath = await createDirectory({});
|
|
203
|
+
await installMandatoryFiles(repositoryPath, { sourcePath });
|
|
204
|
+
await expect(readFile(join(repositoryPath, ".github/workflows/agent-check.md"), "utf8")).rejects.toThrow();
|
|
205
|
+
});
|
|
206
|
+
it("installCatalog deduplicates compile script in both scripts/ and mandatory files", async () => {
|
|
207
|
+
const sourcePath = await createDirectory({
|
|
208
|
+
"actions/check/action.yml": "name: Check\n",
|
|
209
|
+
"workflows/agent-check.md": "# Check\n",
|
|
210
|
+
"scripts/compile-agent-workflows.mjs": "same compile script\n",
|
|
211
|
+
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
|
212
|
+
});
|
|
213
|
+
const repositoryPath = await createDirectory({});
|
|
214
|
+
const result = await installCatalog(repositoryPath, { sourcePath });
|
|
215
|
+
const compileEntries = result.installed.filter((path) => path === "scripts/compile-agent-workflows.mjs");
|
|
216
|
+
expect(compileEntries).toHaveLength(1);
|
|
217
|
+
});
|
|
130
218
|
it("installs the opencode.ci.json template to the repository root", async () => {
|
|
131
219
|
const sourcePath = await createDirectory({
|
|
132
220
|
"templates/opencode/opencode.ci.json": "{ \"model\": \"plainconcepts/glm-5-2\" }\n",
|
package/dist/index.js
CHANGED
|
@@ -2,13 +2,22 @@
|
|
|
2
2
|
import { inspectRepository, parseVisibility, resolveVisibility } from "./repository-inspection.js";
|
|
3
3
|
import { installCatalog, installTemplate, isTemplateName } from "./catalog-installation.js";
|
|
4
4
|
import { formatCatalog, listCatalog, searchCatalog } from "./catalog-listing.js";
|
|
5
|
+
import { runInteractive } from "./tui.js";
|
|
5
6
|
import { resolve } from "node:path";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
const HELP_TEXT = `Workflows CLI — install and manage Plain Concepts Platform agentic workflows.
|
|
8
9
|
|
|
10
|
+
Run with no arguments to launch the interactive TUI, the primary way to select and install
|
|
11
|
+
workflows and templates:
|
|
12
|
+
|
|
13
|
+
npx @plainconceptsplatform/workflows
|
|
14
|
+
|
|
15
|
+
Advanced (non-interactive) commands:
|
|
16
|
+
|
|
9
17
|
Usage: workflows <command> [options]
|
|
10
18
|
|
|
11
19
|
Commands:
|
|
20
|
+
(default) Launch the interactive TUI for selecting and installing items.
|
|
12
21
|
init Inspect the repository and report its stack and visibility.
|
|
13
22
|
add Install package-owned workflow files into .github/.
|
|
14
23
|
update Alias for add. Use --force to overwrite managed files.
|
|
@@ -29,10 +38,14 @@ Installed workflows are marked [x] when the corresponding .github/workflows/agen
|
|
|
29
38
|
file exists relative to the current directory.`;
|
|
30
39
|
export async function run(arguments_, repositoryPath = process.cwd()) {
|
|
31
40
|
const [command, ...options] = arguments_;
|
|
32
|
-
if (command === "--help" || command === "-h"
|
|
41
|
+
if (command === "--help" || command === "-h") {
|
|
33
42
|
console.log(HELP_TEXT);
|
|
34
43
|
return 0;
|
|
35
44
|
}
|
|
45
|
+
if (command === undefined) {
|
|
46
|
+
const force = options.includes("--force");
|
|
47
|
+
return runInteractive(repositoryPath, { force });
|
|
48
|
+
}
|
|
36
49
|
if (command === "list") {
|
|
37
50
|
const entries = await listCatalog({ installedPath: repositoryPath });
|
|
38
51
|
console.log(formatCatalog(entries));
|
package/dist/tui.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CatalogEntry } from "./catalog-listing.js";
|
|
2
|
+
export type SelectionStatus = "selecting" | "submitting" | "cancelled";
|
|
3
|
+
export interface SelectionState {
|
|
4
|
+
readonly allItems: readonly CatalogEntry[];
|
|
5
|
+
readonly visibleItems: readonly CatalogEntry[];
|
|
6
|
+
readonly selected: ReadonlySet<string>;
|
|
7
|
+
readonly cursor: number;
|
|
8
|
+
readonly filter: string;
|
|
9
|
+
readonly status: SelectionStatus;
|
|
10
|
+
}
|
|
11
|
+
export interface InteractiveOptions {
|
|
12
|
+
readonly force?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export declare function createSelectionState(entries: readonly CatalogEntry[]): SelectionState;
|
|
15
|
+
export declare function fuzzyMatch(text: string, query: string): boolean;
|
|
16
|
+
export declare function filterItems(items: readonly CatalogEntry[], filter: string): readonly CatalogEntry[];
|
|
17
|
+
export declare function applyFilter(state: SelectionState, filter: string): SelectionState;
|
|
18
|
+
export declare function clearFilter(state: SelectionState): SelectionState;
|
|
19
|
+
export declare function moveCursorUp(state: SelectionState): SelectionState;
|
|
20
|
+
export declare function moveCursorDown(state: SelectionState): SelectionState;
|
|
21
|
+
export declare function toggleSelection(state: SelectionState): SelectionState;
|
|
22
|
+
export declare function submitSelection(state: SelectionState): SelectionState;
|
|
23
|
+
export declare function cancelSelection(state: SelectionState): SelectionState;
|
|
24
|
+
export declare function getItemsToInstall(state: SelectionState, force?: boolean): readonly CatalogEntry[];
|
|
25
|
+
export declare function runInteractive(repositoryPath: string, options?: InteractiveOptions): Promise<number>;
|
package/dist/tui.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
import * as readline from "node:readline";
|
|
2
|
+
import { formatCatalog, listCatalog } from "./catalog-listing.js";
|
|
3
|
+
import { installCatalog, installMandatoryFiles, installTemplate, isTemplateName } from "./catalog-installation.js";
|
|
4
|
+
const ANSI = {
|
|
5
|
+
clear: "\x1b[2J",
|
|
6
|
+
home: "\x1b[H",
|
|
7
|
+
reset: "\x1b[0m",
|
|
8
|
+
bold: "\x1b[1m",
|
|
9
|
+
dim: "\x1b[2m",
|
|
10
|
+
cyan: "\x1b[36m",
|
|
11
|
+
green: "\x1b[32m",
|
|
12
|
+
grey: "\x1b[90m",
|
|
13
|
+
white: "\x1b[37m",
|
|
14
|
+
hideCursor: "\x1b[?25l",
|
|
15
|
+
showCursor: "\x1b[?25h",
|
|
16
|
+
};
|
|
17
|
+
export function createSelectionState(entries) {
|
|
18
|
+
const selected = new Set(entries.filter((entry) => entry.installed).map((entry) => entry.name));
|
|
19
|
+
return {
|
|
20
|
+
allItems: entries,
|
|
21
|
+
visibleItems: entries,
|
|
22
|
+
selected,
|
|
23
|
+
cursor: 0,
|
|
24
|
+
filter: "",
|
|
25
|
+
status: "selecting",
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function fuzzyMatch(text, query) {
|
|
29
|
+
if (query === "")
|
|
30
|
+
return true;
|
|
31
|
+
const haystack = text.toLowerCase();
|
|
32
|
+
const needle = query.toLowerCase();
|
|
33
|
+
let needleIndex = 0;
|
|
34
|
+
for (let i = 0; i < haystack.length && needleIndex < needle.length; i++) {
|
|
35
|
+
if (haystack[i] === needle[needleIndex])
|
|
36
|
+
needleIndex++;
|
|
37
|
+
}
|
|
38
|
+
return needleIndex === needle.length;
|
|
39
|
+
}
|
|
40
|
+
export function filterItems(items, filter) {
|
|
41
|
+
if (filter === "")
|
|
42
|
+
return items;
|
|
43
|
+
return items.filter((entry) => fuzzyMatch(`${entry.name} ${entry.description}`, filter));
|
|
44
|
+
}
|
|
45
|
+
export function applyFilter(state, filter) {
|
|
46
|
+
const visibleItems = filterItems(state.allItems, filter);
|
|
47
|
+
const cursor = visibleItems.length === 0 ? 0 : Math.min(state.cursor, visibleItems.length - 1);
|
|
48
|
+
return { ...state, visibleItems, filter, cursor };
|
|
49
|
+
}
|
|
50
|
+
export function clearFilter(state) {
|
|
51
|
+
return applyFilter(state, "");
|
|
52
|
+
}
|
|
53
|
+
export function moveCursorUp(state) {
|
|
54
|
+
if (state.visibleItems.length === 0)
|
|
55
|
+
return state;
|
|
56
|
+
const cursor = state.cursor === 0 ? state.visibleItems.length - 1 : state.cursor - 1;
|
|
57
|
+
return { ...state, cursor };
|
|
58
|
+
}
|
|
59
|
+
export function moveCursorDown(state) {
|
|
60
|
+
if (state.visibleItems.length === 0)
|
|
61
|
+
return state;
|
|
62
|
+
const cursor = state.cursor === state.visibleItems.length - 1 ? 0 : state.cursor + 1;
|
|
63
|
+
return { ...state, cursor };
|
|
64
|
+
}
|
|
65
|
+
export function toggleSelection(state) {
|
|
66
|
+
if (state.visibleItems.length === 0)
|
|
67
|
+
return state;
|
|
68
|
+
const entry = state.visibleItems[state.cursor];
|
|
69
|
+
if (entry === undefined)
|
|
70
|
+
return state;
|
|
71
|
+
const selected = new Set(state.selected);
|
|
72
|
+
if (selected.has(entry.name)) {
|
|
73
|
+
selected.delete(entry.name);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
selected.add(entry.name);
|
|
77
|
+
}
|
|
78
|
+
return { ...state, selected };
|
|
79
|
+
}
|
|
80
|
+
export function submitSelection(state) {
|
|
81
|
+
return { ...state, status: "submitting" };
|
|
82
|
+
}
|
|
83
|
+
export function cancelSelection(state) {
|
|
84
|
+
return { ...state, status: "cancelled" };
|
|
85
|
+
}
|
|
86
|
+
export function getItemsToInstall(state, force = false) {
|
|
87
|
+
return state.allItems.filter((entry) => state.selected.has(entry.name) && (force || !entry.installed));
|
|
88
|
+
}
|
|
89
|
+
function renderEntry(entry, highlighted, checked) {
|
|
90
|
+
const indicator = highlighted ? `${ANSI.bold}${ANSI.white}>${ANSI.reset}` : " ";
|
|
91
|
+
if (checked) {
|
|
92
|
+
const checkbox = `${ANSI.green}[x]${ANSI.reset}`;
|
|
93
|
+
const name = highlighted ? `${ANSI.white}${ANSI.bold}${entry.name}${ANSI.reset}` : entry.name;
|
|
94
|
+
const desc = `${ANSI.dim} — ${entry.description}${ANSI.reset}`;
|
|
95
|
+
return `${indicator} ${checkbox} ${name}${desc}`;
|
|
96
|
+
}
|
|
97
|
+
const checkbox = `${ANSI.grey}[ ]${ANSI.reset}`;
|
|
98
|
+
const name = highlighted ? `${ANSI.white}${ANSI.bold}${entry.name}${ANSI.reset}` : entry.name;
|
|
99
|
+
const desc = `${ANSI.dim} — ${entry.description}${ANSI.reset}`;
|
|
100
|
+
return `${indicator} ${checkbox} ${name}${desc}`;
|
|
101
|
+
}
|
|
102
|
+
function render(state) {
|
|
103
|
+
const lines = [];
|
|
104
|
+
lines.push(`${ANSI.cyan}${ANSI.bold}Plain Concepts Platform — Agentic Workflows${ANSI.reset}`);
|
|
105
|
+
lines.push(`${ANSI.dim}Select items to install. Already-installed items are pre-checked.${ANSI.reset}`);
|
|
106
|
+
lines.push("");
|
|
107
|
+
if (state.filter) {
|
|
108
|
+
lines.push(`${ANSI.cyan}Filter:${ANSI.reset} ${state.filter}${ANSI.grey}█${ANSI.reset}`);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
lines.push(`${ANSI.dim}Type to filter, arrows to navigate, space to toggle, Enter to install${ANSI.reset}`);
|
|
112
|
+
}
|
|
113
|
+
lines.push("");
|
|
114
|
+
const routes = state.visibleItems.filter((entry) => entry.kind === "route");
|
|
115
|
+
const templates = state.visibleItems.filter((entry) => entry.kind === "template");
|
|
116
|
+
let index = 0;
|
|
117
|
+
if (routes.length > 0) {
|
|
118
|
+
lines.push(`${ANSI.cyan}Workflows${ANSI.reset}`);
|
|
119
|
+
for (const entry of routes) {
|
|
120
|
+
lines.push(renderEntry(entry, index === state.cursor, state.selected.has(entry.name)));
|
|
121
|
+
index++;
|
|
122
|
+
}
|
|
123
|
+
if (templates.length > 0)
|
|
124
|
+
lines.push("");
|
|
125
|
+
}
|
|
126
|
+
if (templates.length > 0) {
|
|
127
|
+
lines.push(`${ANSI.cyan}Templates${ANSI.reset}`);
|
|
128
|
+
for (const entry of templates) {
|
|
129
|
+
lines.push(renderEntry(entry, index === state.cursor, state.selected.has(entry.name)));
|
|
130
|
+
index++;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (state.visibleItems.length === 0) {
|
|
134
|
+
lines.push(`${ANSI.grey} No items match the filter.${ANSI.reset}`);
|
|
135
|
+
}
|
|
136
|
+
lines.push("");
|
|
137
|
+
lines.push(`${ANSI.grey}↑↓ navigate space toggle type to filter Enter install Esc clear filter q quit${ANSI.reset}`);
|
|
138
|
+
process.stdout.write(`${ANSI.clear}${ANSI.home}${lines.join("\n")}\n`);
|
|
139
|
+
}
|
|
140
|
+
export async function runInteractive(repositoryPath, options = {}) {
|
|
141
|
+
const force = options.force ?? false;
|
|
142
|
+
if (process.stdin.isTTY !== true) {
|
|
143
|
+
const entries = await listCatalog({ installedPath: repositoryPath });
|
|
144
|
+
console.log(formatCatalog(entries));
|
|
145
|
+
console.log("");
|
|
146
|
+
console.log("Run with a TTY for an interactive selection screen, or use: workflows add [--template <name>] [--force]");
|
|
147
|
+
return 0;
|
|
148
|
+
}
|
|
149
|
+
const entries = await listCatalog({ installedPath: repositoryPath });
|
|
150
|
+
let state = createSelectionState(entries);
|
|
151
|
+
readline.emitKeypressEvents(process.stdin);
|
|
152
|
+
process.stdin.setRawMode(true);
|
|
153
|
+
process.stdin.resume();
|
|
154
|
+
process.stdout.write(ANSI.hideCursor);
|
|
155
|
+
render(state);
|
|
156
|
+
return new Promise((resolve) => {
|
|
157
|
+
const onKeypress = (str, key) => {
|
|
158
|
+
if (key?.ctrl && key?.name === "c") {
|
|
159
|
+
cleanup();
|
|
160
|
+
resolve(0);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (str === "q" && state.filter === "" && !key?.ctrl && !key?.meta && !key?.shift) {
|
|
164
|
+
cleanup();
|
|
165
|
+
resolve(0);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
if (key?.name === "escape") {
|
|
169
|
+
state = clearFilter(state);
|
|
170
|
+
render(state);
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
if (key?.name === "up") {
|
|
174
|
+
state = moveCursorUp(state);
|
|
175
|
+
render(state);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (key?.name === "down") {
|
|
179
|
+
state = moveCursorDown(state);
|
|
180
|
+
render(state);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
if (key?.name === "space" || str === " ") {
|
|
184
|
+
state = toggleSelection(state);
|
|
185
|
+
render(state);
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if (key?.name === "return" || key?.name === "enter") {
|
|
189
|
+
cleanup();
|
|
190
|
+
void installSelected(state, repositoryPath, force).then((exitCode) => resolve(exitCode));
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
if (key?.name === "backspace") {
|
|
194
|
+
state = applyFilter(state, state.filter.slice(0, -1));
|
|
195
|
+
render(state);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (str !== undefined &&
|
|
199
|
+
str.length === 1 &&
|
|
200
|
+
str >= " " &&
|
|
201
|
+
str <= "~" &&
|
|
202
|
+
!key?.ctrl &&
|
|
203
|
+
!key?.meta) {
|
|
204
|
+
state = applyFilter(state, state.filter + str);
|
|
205
|
+
render(state);
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
function cleanup() {
|
|
209
|
+
process.stdin.setRawMode(false);
|
|
210
|
+
process.stdin.pause();
|
|
211
|
+
process.stdout.write(`${ANSI.showCursor}${ANSI.reset}`);
|
|
212
|
+
process.stdin.removeListener("keypress", onKeypress);
|
|
213
|
+
}
|
|
214
|
+
process.stdin.on("keypress", onKeypress);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
async function installSelected(state, repositoryPath, force) {
|
|
218
|
+
const items = getItemsToInstall(state, force);
|
|
219
|
+
const routes = items.filter((entry) => entry.kind === "route");
|
|
220
|
+
const templates = items.filter((entry) => entry.kind === "template");
|
|
221
|
+
const allConflicts = [];
|
|
222
|
+
const allInstalled = [];
|
|
223
|
+
if (routes.length > 0) {
|
|
224
|
+
const result = await installCatalog(repositoryPath, { force });
|
|
225
|
+
allConflicts.push(...result.conflicts);
|
|
226
|
+
allInstalled.push(...result.installed);
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const result = await installMandatoryFiles(repositoryPath, { force });
|
|
230
|
+
allConflicts.push(...result.conflicts);
|
|
231
|
+
allInstalled.push(...result.installed);
|
|
232
|
+
}
|
|
233
|
+
for (const template of templates) {
|
|
234
|
+
if (!isTemplateName(template.name))
|
|
235
|
+
continue;
|
|
236
|
+
const result = await installTemplate(repositoryPath, template.name, { force });
|
|
237
|
+
allConflicts.push(...result.conflicts);
|
|
238
|
+
allInstalled.push(...result.installed);
|
|
239
|
+
}
|
|
240
|
+
if (allConflicts.length > 0 && !force) {
|
|
241
|
+
console.error(`Conflicts found. Re-run with --force to overwrite:\n${allConflicts.join("\n")}`);
|
|
242
|
+
return 1;
|
|
243
|
+
}
|
|
244
|
+
if (allInstalled.length > 0) {
|
|
245
|
+
console.log(`Installed ${allInstalled.length} item(s):`);
|
|
246
|
+
for (const file of allInstalled) {
|
|
247
|
+
console.log(` ${file}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
console.log("All selected items are already installed.");
|
|
252
|
+
}
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|