mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-08-14 23:07:29 +00:00
Scaffold LogicSRC and CommandBoard plugins
This commit is contained in:
parent
59927e140c
commit
5c9ea821f6
67 changed files with 5958 additions and 0 deletions
30
packages/cli/package.json
Normal file
30
packages/cli/package.json
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "@logicsrc/cli",
|
||||
"version": "0.1.0",
|
||||
"description": "CommandBoard.run CLI.",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"bin": {
|
||||
"commandboard": "./dist/index.js",
|
||||
"cb": "./dist/index.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"dev": "tsx src/index.ts",
|
||||
"test": "vitest run src"
|
||||
},
|
||||
"dependencies": {
|
||||
"@logicsrc/plugin-core": "file:../plugin-core",
|
||||
"@logicsrc/plugin-coinpay": "file:../../plugins/coinpay",
|
||||
"@logicsrc/plugin-sh1pt": "file:../../plugins/sh1pt",
|
||||
"@logicsrc/plugin-ugig": "file:../../plugins/ugig",
|
||||
"@logicsrc/tui": "file:../tui",
|
||||
"@logicsrc/validators": "file:../validators",
|
||||
"commander": "^14.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"tsx": "^4.21.0",
|
||||
"vitest": "^4.0.8"
|
||||
}
|
||||
}
|
||||
25
packages/cli/src/fixtures.ts
Normal file
25
packages/cli/src/fixtures.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
export const boards = [
|
||||
{ path: "/general", title: "General", posts: 18, tasks: 2 },
|
||||
{ path: "/gigs", title: "Gigs", posts: 42, tasks: 12 },
|
||||
{ path: "/agents", title: "Agents", posts: 16, tasks: 5 },
|
||||
{ path: "/qa", title: "QA", posts: 9, tasks: 7 }
|
||||
];
|
||||
|
||||
export const tasks = [
|
||||
{
|
||||
id: "task_123",
|
||||
title: "Test checkout flow",
|
||||
board: "/qa",
|
||||
budget: "25 USDC",
|
||||
status: "submitted",
|
||||
assignee: "qa-agent-01.coinpay"
|
||||
},
|
||||
{
|
||||
id: "task_456",
|
||||
title: "Publish uGig integration smoke test",
|
||||
board: "/gigs",
|
||||
budget: "40 USDC",
|
||||
status: "funded",
|
||||
assignee: null
|
||||
}
|
||||
];
|
||||
22
packages/cli/src/format.ts
Normal file
22
packages/cli/src/format.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
export type OutputFormat = "json" | "table" | "markdown";
|
||||
|
||||
export function print(data: unknown, format: OutputFormat) {
|
||||
if (format === "json") {
|
||||
console.log(JSON.stringify(data, null, 2));
|
||||
return;
|
||||
}
|
||||
|
||||
if (format === "markdown") {
|
||||
if (Array.isArray(data)) {
|
||||
for (const item of data) {
|
||||
console.log(`- ${Object.entries(item as Record<string, unknown>).map(([key, value]) => `**${key}:** ${String(value)}`).join(", ")}`);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(Object.entries(data as Record<string, unknown>).map(([key, value]) => `**${key}:** ${String(value)}`).join("\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
console.table(data);
|
||||
}
|
||||
12
packages/cli/src/index.test.ts
Normal file
12
packages/cli/src/index.test.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { defaultPluginRegistry } from "./registry.js";
|
||||
|
||||
describe("CLI registry", () => {
|
||||
it("loads default v1 plugins", () => {
|
||||
const ids = defaultPluginRegistry().snapshot().plugins.map((plugin: { id: string }) => plugin.id);
|
||||
|
||||
expect(ids).toContain("coinpay");
|
||||
expect(ids).toContain("ugig");
|
||||
expect(ids).toContain("sh1pt");
|
||||
});
|
||||
});
|
||||
211
packages/cli/src/index.ts
Normal file
211
packages/cli/src/index.ts
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
#!/usr/bin/env node
|
||||
import { readFileSync } from "node:fs";
|
||||
import { Command } from "commander";
|
||||
import { renderPluginStatus, renderTui } from "@logicsrc/tui";
|
||||
import { assertSchemaKind, parseDocument, validate } from "@logicsrc/validators";
|
||||
import { boards, tasks } from "./fixtures.js";
|
||||
import { print, type OutputFormat } from "./format.js";
|
||||
import { defaultPluginRegistry } from "./registry.js";
|
||||
|
||||
const program = new Command();
|
||||
|
||||
program
|
||||
.name("commandboard")
|
||||
.alias("cb")
|
||||
.description("CommandBoard.run CLI for LogicSRC boards, tasks, agents, payments, plugins, and TUI.")
|
||||
.version("0.1.0");
|
||||
|
||||
program
|
||||
.command("login")
|
||||
.option("--did <did>", "CoinPay DID")
|
||||
.option("--oauth <provider>", "OAuth provider")
|
||||
.description("Start a login flow.")
|
||||
.action((options) => {
|
||||
const mode = options.did ? `CoinPay DID ${options.did}` : options.oauth ? `${options.oauth} OAuth` : "browser/device";
|
||||
console.log(`Login flow ready: ${mode}`);
|
||||
console.log("Token storage target: $HOME/.commandboard/auth.json");
|
||||
});
|
||||
|
||||
program.command("logout").description("Clear local auth token.").action(() => {
|
||||
console.log("Logged out. Local auth token would be removed from $HOME/.commandboard/auth.json.");
|
||||
});
|
||||
|
||||
program.command("whoami").description("Show current DID and account context.").action(() => {
|
||||
print({ did: process.env.COMMANDBOARD_DID || "anthony.coinpay", api_url: process.env.COMMANDBOARD_API_URL || "http://localhost:4010" }, "table");
|
||||
});
|
||||
|
||||
program
|
||||
.command("boards")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.description("List boards.")
|
||||
.action((options) => print(boards, options.format as OutputFormat));
|
||||
|
||||
program
|
||||
.command("read")
|
||||
.argument("<board>", "Board path")
|
||||
.option("--limit <limit>", "Number of posts", "20")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.description("Read a board feed.")
|
||||
.action((board, options) => {
|
||||
print(
|
||||
[
|
||||
{ type: "TASK", board, title: "QA checkout flow", meta: "25 USDC" },
|
||||
{ type: "POST", board, title: "New agent plugin idea", meta: "4 replies" },
|
||||
{ type: "RUN", board, title: "qa-agent completed task_123", meta: "completed" }
|
||||
].slice(0, Number(options.limit)),
|
||||
options.format as OutputFormat
|
||||
);
|
||||
});
|
||||
|
||||
program
|
||||
.command("post")
|
||||
.argument("<board>", "Board path")
|
||||
.argument("[message]", "Post body")
|
||||
.option("--file <file>", "Read post body from a file")
|
||||
.description("Create a post.")
|
||||
.action((board, message, options) => {
|
||||
const body = options.file ? readFileSync(options.file, "utf8") : message;
|
||||
console.log(`Created post on ${board}: ${body}`);
|
||||
});
|
||||
|
||||
const task = program.command("task").description("Task commands.");
|
||||
|
||||
task
|
||||
.command("list")
|
||||
.option("--open", "Only open tasks")
|
||||
.option("--board <board>", "Filter by board")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.action((options) => {
|
||||
const filtered = tasks.filter((item) => (!options.open || item.status === "open" || item.status === "funded") && (!options.board || item.board === options.board));
|
||||
print(filtered, options.format as OutputFormat);
|
||||
});
|
||||
|
||||
task
|
||||
.command("get")
|
||||
.argument("<id>", "Task id")
|
||||
.option("--raw-schema", "Print LogicSRC schema")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.action((id, options) => {
|
||||
const item = tasks.find((entry) => entry.id === id);
|
||||
if (!item) {
|
||||
throw new Error(`Task not found: ${id}`);
|
||||
}
|
||||
print(options.rawSchema ? toTaskSchema(item) : item, options.format as OutputFormat);
|
||||
});
|
||||
|
||||
task
|
||||
.command("create")
|
||||
.option("--board <board>", "Board path", "/gigs")
|
||||
.option("--title <title>", "Task title", "Untitled task")
|
||||
.option("--budget <budget>", "Budget, for example 25usdc")
|
||||
.option("--schema <file>", "LogicSRC task schema file")
|
||||
.action((options) => {
|
||||
if (options.schema) {
|
||||
validateFile("task", options.schema);
|
||||
}
|
||||
console.log(`Created task "${options.title}" on ${options.board}${options.budget ? ` with budget ${options.budget}` : ""}`);
|
||||
});
|
||||
|
||||
task.command("validate").argument("<file>", "Task YAML or JSON file").action((file) => validateFile("task", file));
|
||||
task.command("claim").argument("<id>", "Task id").action((id) => console.log(`Claimed ${id}`));
|
||||
task.command("submit").argument("<id>", "Task id").option("--file <file>", "Deliverable file").action((id, options) => console.log(`Submitted ${id}${options.file ? ` with ${options.file}` : ""}`));
|
||||
task.command("approve").argument("<id>", "Task id").action((id) => console.log(`Approved ${id}; escrow release requested through CoinPay.`));
|
||||
task.command("reject").argument("<id>", "Task id").option("--reason <reason>", "Rejection reason").action((id, options) => console.log(`Rejected ${id}${options.reason ? `: ${options.reason}` : ""}`));
|
||||
task.command("dispute").argument("<id>", "Task id").action((id) => console.log(`Opened dispute for ${id}`));
|
||||
|
||||
program.command("wallet").description("Show wallet balance.").action(() => {
|
||||
print({ did: process.env.COMMANDBOARD_DID || "anthony.coinpay", provider: "CoinPay", balance: "42 USDC" }, "table");
|
||||
});
|
||||
|
||||
program.command("events").description("Listen to LogicSRC event stream.").argument("[listen]", "listen").option("--board <board>").option("--type <type>").action((_listen, options) => {
|
||||
console.log(`Listening for events${options.board ? ` on ${options.board}` : ""}${options.type ? ` of type ${options.type}` : ""}...`);
|
||||
console.log(JSON.stringify({ type: "logicsrc.event", event: "task.created", resource_id: "task_789" }));
|
||||
});
|
||||
|
||||
program.command("plugins").option("--format <format>", "table, json, or markdown", "table").description("Show plugin status.").action((options) => {
|
||||
const snapshot = defaultPluginRegistry().snapshot();
|
||||
print(snapshot.plugins, options.format as OutputFormat);
|
||||
});
|
||||
|
||||
const sh1pt = program.command("sh1pt").description("sh1pt project, action, release, and delivery commands.");
|
||||
|
||||
sh1pt
|
||||
.command("projects")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.description("List synced sh1pt projects.")
|
||||
.action((options) => {
|
||||
print(
|
||||
[
|
||||
{ id: "sh1pt_project_1", board: "/projects/sh1pt", status: "active", actions: 5 },
|
||||
{ id: "sh1pt_project_2", board: "/projects/crawlproof", status: "active", actions: 2 }
|
||||
],
|
||||
options.format as OutputFormat
|
||||
);
|
||||
});
|
||||
|
||||
sh1pt
|
||||
.command("actions")
|
||||
.option("--format <format>", "table, json, or markdown", "table")
|
||||
.description("List sh1pt actions available for task publishing.")
|
||||
.action((options) => {
|
||||
print(
|
||||
[
|
||||
{ id: "action_release_checklist", title: "Release checklist", publishable: true },
|
||||
{ id: "action_deploy_preview", title: "Deploy preview", publishable: true }
|
||||
],
|
||||
options.format as OutputFormat
|
||||
);
|
||||
});
|
||||
|
||||
sh1pt.command("publish").argument("<action>", "sh1pt action id").option("--board <board>", "Target board", "/projects/sh1pt").description("Publish a sh1pt action as a CommandBoard task.").action((action, options) => {
|
||||
console.log(`Published sh1pt action ${action} to ${options.board}`);
|
||||
});
|
||||
|
||||
program.command("tui").description("Launch the tmux-friendly TUI.").action(() => {
|
||||
console.log(renderTui());
|
||||
console.log("\nPlugin status:\n" + renderPluginStatus());
|
||||
});
|
||||
|
||||
program.command("update").alias("upgrade").description("Update the local CommandBoard.run CLI.").action(() => {
|
||||
console.log("Current version: 0.1.0");
|
||||
console.log("Latest version: 0.1.0");
|
||||
console.log("CommandBoard.run CLI is already up to date.");
|
||||
console.log("Config preserved at $HOME/.commandboard");
|
||||
});
|
||||
|
||||
program.command("remove").alias("uninstall").option("--purge", "Remove config and auth tokens").description("Remove local CommandBoard.run CLI.").action((options) => {
|
||||
console.log("Removed CommandBoard.run CLI.");
|
||||
console.log(options.purge ? "Removed config and auth tokens from $HOME/.commandboard." : "Preserved config at $HOME/.commandboard. Run with --purge to remove config and auth tokens.");
|
||||
});
|
||||
|
||||
function validateFile(kindArg: string, file: string) {
|
||||
const kind = assertSchemaKind(kindArg);
|
||||
const input = readFileSync(file, "utf8");
|
||||
const result = validate(kind, parseDocument(input, file));
|
||||
if (!result.ok) {
|
||||
for (const error of result.errors) {
|
||||
console.error(`- ${error.instancePath || "/"} ${error.message}`);
|
||||
}
|
||||
throw new Error(`Invalid LogicSRC ${kind} schema: ${file}`);
|
||||
}
|
||||
console.log(`Valid LogicSRC ${kind} schema: ${file}`);
|
||||
}
|
||||
|
||||
function toTaskSchema(item: (typeof tasks)[number]) {
|
||||
return {
|
||||
type: "logicsrc.task",
|
||||
version: "0.1",
|
||||
title: item.title,
|
||||
description: item.title,
|
||||
board: item.board,
|
||||
creator_did: "anthony.coinpay",
|
||||
status: item.status,
|
||||
budget: { amount: Number.parseFloat(item.budget), currency: item.budget.replace(/[0-9. ]/g, "") || "USDC" },
|
||||
assignee_did: item.assignee ?? undefined
|
||||
};
|
||||
}
|
||||
|
||||
program.parseAsync(process.argv).catch((error: unknown) => {
|
||||
console.error(error instanceof Error ? error.message : String(error));
|
||||
process.exitCode = 1;
|
||||
});
|
||||
8
packages/cli/src/registry.ts
Normal file
8
packages/cli/src/registry.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { createPluginRegistry } from "@logicsrc/plugin-core";
|
||||
import { coinPayPlugin } from "@logicsrc/plugin-coinpay";
|
||||
import { sh1ptPlugin } from "@logicsrc/plugin-sh1pt";
|
||||
import { uGigPlugin } from "@logicsrc/plugin-ugig";
|
||||
|
||||
export function defaultPluginRegistry() {
|
||||
return createPluginRegistry([coinPayPlugin, uGigPlugin, sh1ptPlugin]);
|
||||
}
|
||||
8
packages/cli/tsconfig.json
Normal file
8
packages/cli/tsconfig.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
18
packages/plugin-core/package.json
Normal file
18
packages/plugin-core/package.json
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"name": "@logicsrc/plugin-core",
|
||||
"version": "0.1.0",
|
||||
"description": "LogicSRC plugin runtime primitives.",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"test": "vitest run src"
|
||||
},
|
||||
"dependencies": {
|
||||
"@logicsrc/validators": "file:../validators"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "^4.0.8"
|
||||
}
|
||||
}
|
||||
33
packages/plugin-core/src/index.test.ts
Normal file
33
packages/plugin-core/src/index.test.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import { describe, expect, it } from "vitest";
|
||||
import { createPluginRegistry } from "./index.js";
|
||||
import type { PluginDefinition } from "./types.js";
|
||||
|
||||
const examplePlugin: PluginDefinition = {
|
||||
manifest: {
|
||||
id: "example",
|
||||
name: "Example",
|
||||
version: "1.0.0",
|
||||
type: ["testing"],
|
||||
default: false,
|
||||
capabilities: ["tests.run"],
|
||||
commands: ["test"],
|
||||
env: ["EXAMPLE_TOKEN"]
|
||||
}
|
||||
};
|
||||
|
||||
describe("PluginRegistry", () => {
|
||||
it("indexes enabled plugins by capability", () => {
|
||||
const registry = createPluginRegistry([examplePlugin]);
|
||||
|
||||
expect(registry.byCapability("tests.run")).toHaveLength(1);
|
||||
expect(registry.snapshot().capabilities["tests.run"]).toEqual(["example"]);
|
||||
});
|
||||
|
||||
it("honors disabled config", () => {
|
||||
const registry = createPluginRegistry([examplePlugin], {
|
||||
example: { enabled: false }
|
||||
});
|
||||
|
||||
expect(registry.enabled()).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
104
packages/plugin-core/src/index.ts
Normal file
104
packages/plugin-core/src/index.ts
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
import { validate } from "@logicsrc/validators";
|
||||
import type { LoadedPlugin, PluginConfig, PluginDefinition, PluginManifest, PluginRegistrySnapshot } from "./types.js";
|
||||
|
||||
export class PluginManifestError extends Error {
|
||||
constructor(id: string, message: string) {
|
||||
super(`Invalid plugin manifest for ${id}: ${message}`);
|
||||
}
|
||||
}
|
||||
|
||||
export class PluginRegistry {
|
||||
private readonly plugins = new Map<string, LoadedPlugin>();
|
||||
|
||||
register(definition: PluginDefinition, config: PluginConfig = {}) {
|
||||
validateManifest(definition.manifest);
|
||||
|
||||
const id = definition.manifest.id;
|
||||
if (this.plugins.has(id)) {
|
||||
throw new Error(`Plugin "${id}" is already registered`);
|
||||
}
|
||||
|
||||
const mergedConfig = {
|
||||
...definition.configDefaults,
|
||||
...config
|
||||
};
|
||||
|
||||
this.plugins.set(id, {
|
||||
definition,
|
||||
config: mergedConfig,
|
||||
enabled: mergedConfig.enabled !== false
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
get(id: string) {
|
||||
return this.plugins.get(id);
|
||||
}
|
||||
|
||||
list() {
|
||||
return [...this.plugins.values()];
|
||||
}
|
||||
|
||||
enabled() {
|
||||
return this.list().filter((plugin) => plugin.enabled);
|
||||
}
|
||||
|
||||
byCapability(capability: string) {
|
||||
return this.enabled().filter((plugin) => plugin.definition.manifest.capabilities.includes(capability));
|
||||
}
|
||||
|
||||
snapshot(): PluginRegistrySnapshot {
|
||||
const capabilities: Record<string, string[]> = {};
|
||||
|
||||
for (const plugin of this.enabled()) {
|
||||
for (const capability of plugin.definition.manifest.capabilities) {
|
||||
capabilities[capability] ??= [];
|
||||
capabilities[capability].push(plugin.definition.manifest.id);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
plugins: this.list().map((plugin) => ({
|
||||
id: plugin.definition.manifest.id,
|
||||
name: plugin.definition.manifest.name,
|
||||
version: plugin.definition.manifest.version,
|
||||
enabled: plugin.enabled,
|
||||
default: plugin.definition.manifest.default,
|
||||
type: plugin.definition.manifest.type,
|
||||
capabilities: plugin.definition.manifest.capabilities,
|
||||
commands: plugin.definition.manifest.commands
|
||||
})),
|
||||
capabilities
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function validateManifest(manifest: PluginManifest) {
|
||||
const result = validate("plugin", manifest);
|
||||
if (!result.ok) {
|
||||
const message = result.errors.map((error: { instancePath?: string; message?: string }) => `${error.instancePath || "/"} ${error.message}`).join("; ");
|
||||
throw new PluginManifestError(manifest.id ?? "unknown", message);
|
||||
}
|
||||
}
|
||||
|
||||
export function createPluginRegistry(definitions: PluginDefinition[], config: Record<string, PluginConfig> = {}) {
|
||||
const registry = new PluginRegistry();
|
||||
|
||||
for (const definition of definitions) {
|
||||
registry.register(definition, config[definition.manifest.id] ?? {});
|
||||
}
|
||||
|
||||
return registry;
|
||||
}
|
||||
|
||||
export type {
|
||||
LoadedPlugin,
|
||||
PluginConfig,
|
||||
PluginDefinition,
|
||||
PluginEventHandler,
|
||||
PluginManifest,
|
||||
PluginPanel,
|
||||
PluginRegistrySnapshot,
|
||||
PluginRoute
|
||||
} from "./types.js";
|
||||
60
packages/plugin-core/src/types.ts
Normal file
60
packages/plugin-core/src/types.ts
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
export interface PluginManifest {
|
||||
id: string;
|
||||
name: string;
|
||||
version: string;
|
||||
type: string[];
|
||||
default: boolean;
|
||||
capabilities: string[];
|
||||
commands: string[];
|
||||
env: string[];
|
||||
}
|
||||
|
||||
export interface PluginConfig {
|
||||
enabled?: boolean;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface PluginDefinition {
|
||||
manifest: PluginManifest;
|
||||
configDefaults?: PluginConfig;
|
||||
routes?: PluginRoute[];
|
||||
events?: PluginEventHandler[];
|
||||
permissions?: string[];
|
||||
tuiPanels?: PluginPanel[];
|
||||
}
|
||||
|
||||
export interface PluginRoute {
|
||||
method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
||||
path: string;
|
||||
capability: string;
|
||||
}
|
||||
|
||||
export interface PluginEventHandler {
|
||||
event: string;
|
||||
capability: string;
|
||||
}
|
||||
|
||||
export interface PluginPanel {
|
||||
id: string;
|
||||
title: string;
|
||||
}
|
||||
|
||||
export interface LoadedPlugin {
|
||||
definition: PluginDefinition;
|
||||
config: PluginConfig;
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
export interface PluginRegistrySnapshot {
|
||||
plugins: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
version: string;
|
||||
enabled: boolean;
|
||||
default: boolean;
|
||||
type: string[];
|
||||
capabilities: string[];
|
||||
commands: string[];
|
||||
}>;
|
||||
capabilities: Record<string, string[]>;
|
||||
}
|
||||
8
packages/plugin-core/tsconfig.json
Normal file
8
packages/plugin-core/tsconfig.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
20
packages/schemas/fixtures/agent.yaml
Normal file
20
packages/schemas/fixtures/agent.yaml
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
type: logicsrc.agent
|
||||
version: "0.1"
|
||||
name: Playwright QA Agent
|
||||
did: qa-agent-01.coinpay
|
||||
owner_did: anthony.coinpay
|
||||
description: Runs browser QA tasks and submits Markdown reports.
|
||||
skills:
|
||||
- qa
|
||||
- playwright
|
||||
- browser-testing
|
||||
pricing:
|
||||
model: per_task
|
||||
amount: 10
|
||||
currency: USDC
|
||||
permissions_requested:
|
||||
- task:read
|
||||
- task:claim
|
||||
- task:submit
|
||||
- browser:visit_url
|
||||
- files:write
|
||||
26
packages/schemas/fixtures/task.yaml
Normal file
26
packages/schemas/fixtures/task.yaml
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
type: logicsrc.task
|
||||
version: "0.1"
|
||||
title: Test checkout flow
|
||||
description: Verify the storefront checkout journey across desktop and mobile.
|
||||
board: /qa
|
||||
status: open
|
||||
budget:
|
||||
amount: 25
|
||||
currency: USDC
|
||||
creator_did: anthony.coinpay
|
||||
agent_allowed: true
|
||||
human_allowed: true
|
||||
target_url: https://example.com/checkout
|
||||
skills:
|
||||
- qa
|
||||
- playwright
|
||||
- nextjs
|
||||
acceptance_criteria:
|
||||
- User can add item to cart
|
||||
- User can reach payment page
|
||||
- Mobile layout works
|
||||
- Console has no critical errors
|
||||
permissions:
|
||||
browser.visit_url: true
|
||||
github.create_issue: true
|
||||
files.read_attached: true
|
||||
19
packages/schemas/package.json
Normal file
19
packages/schemas/package.json
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"name": "@logicsrc/schemas",
|
||||
"version": "0.1.0",
|
||||
"description": "LogicSRC JSON schemas for tasks, agents, runs, events, and plugins.",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./task": "./schemas/logicsrc-task.schema.json",
|
||||
"./agent": "./schemas/logicsrc-agent.schema.json",
|
||||
"./run": "./schemas/logicsrc-run.schema.json",
|
||||
"./event": "./schemas/logicsrc-event.schema.json",
|
||||
"./plugin": "./schemas/logicsrc-plugin.schema.json"
|
||||
},
|
||||
"files": [
|
||||
"schemas"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "node -e \"console.log('schemas: no build step')\""
|
||||
}
|
||||
}
|
||||
51
packages/schemas/schemas/logicsrc-agent.schema.json
Normal file
51
packages/schemas/schemas/logicsrc-agent.schema.json
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://schemas.logicsrc.com/logicsrc-agent.schema.json",
|
||||
"title": "LogicSRC Agent",
|
||||
"type": "object",
|
||||
"required": ["type", "version", "name", "did", "owner_did", "skills", "permissions_requested"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"type": { "const": "logicsrc.agent" },
|
||||
"version": { "type": "string", "pattern": "^\\d+\\.\\d+(\\.\\d+)?$" },
|
||||
"name": { "type": "string", "minLength": 1, "maxLength": 120 },
|
||||
"did": { "$ref": "#/$defs/did" },
|
||||
"owner_did": { "$ref": "#/$defs/did" },
|
||||
"description": { "type": "string" },
|
||||
"skills": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": { "type": "string", "minLength": 1 },
|
||||
"uniqueItems": true
|
||||
},
|
||||
"supported_task_types": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 },
|
||||
"uniqueItems": true
|
||||
},
|
||||
"pricing": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"model": { "type": "string", "enum": ["free", "per_task", "hourly", "subscription"] },
|
||||
"amount": { "type": "number", "minimum": 0 },
|
||||
"currency": { "type": "string", "minLength": 2, "maxLength": 12 }
|
||||
}
|
||||
},
|
||||
"permissions_requested": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "pattern": "^[a-z][a-z0-9._-]*(:[a-z][a-z0-9._-]*)?$" },
|
||||
"uniqueItems": true
|
||||
},
|
||||
"webhook_url": { "type": "string", "format": "uri" },
|
||||
"polling_mode": { "type": "boolean" },
|
||||
"public": { "type": "boolean", "default": true },
|
||||
"logicsrc_compatibility_version": { "type": "string" }
|
||||
},
|
||||
"$defs": {
|
||||
"did": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-z0-9][a-z0-9._-]*\\.[a-z0-9][a-z0-9._-]*$"
|
||||
}
|
||||
}
|
||||
}
|
||||
25
packages/schemas/schemas/logicsrc-event.schema.json
Normal file
25
packages/schemas/schemas/logicsrc-event.schema.json
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://schemas.logicsrc.com/logicsrc-event.schema.json",
|
||||
"title": "LogicSRC Event",
|
||||
"type": "object",
|
||||
"required": ["type", "version", "event", "id", "created_at", "actor_did", "resource_type", "resource_id", "data"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"type": { "const": "logicsrc.event" },
|
||||
"version": { "type": "string", "pattern": "^\\d+\\.\\d+(\\.\\d+)?$" },
|
||||
"event": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-z][a-z0-9_]*\\.[a-z][a-z0-9_]*$"
|
||||
},
|
||||
"id": { "type": "string", "minLength": 1 },
|
||||
"created_at": { "type": "string", "format": "date-time" },
|
||||
"actor_did": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-z0-9][a-z0-9._-]*\\.[a-z0-9][a-z0-9._-]*$"
|
||||
},
|
||||
"resource_type": { "type": "string", "minLength": 1 },
|
||||
"resource_id": { "type": "string", "minLength": 1 },
|
||||
"data": { "type": "object" }
|
||||
}
|
||||
}
|
||||
35
packages/schemas/schemas/logicsrc-plugin.schema.json
Normal file
35
packages/schemas/schemas/logicsrc-plugin.schema.json
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://schemas.logicsrc.com/logicsrc-plugin.schema.json",
|
||||
"title": "LogicSRC Plugin Manifest",
|
||||
"type": "object",
|
||||
"required": ["id", "name", "version", "type", "default", "capabilities", "commands", "env"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"id": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
|
||||
"name": { "type": "string", "minLength": 1 },
|
||||
"version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.-]+)?$" },
|
||||
"type": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": { "type": "string", "minLength": 1 },
|
||||
"uniqueItems": true
|
||||
},
|
||||
"default": { "type": "boolean" },
|
||||
"capabilities": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "pattern": "^[a-z][a-z0-9_-]*(\\.[a-z][a-z0-9_-]*)+$" },
|
||||
"uniqueItems": true
|
||||
},
|
||||
"commands": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "pattern": "^[a-z][a-z0-9-]*$" },
|
||||
"uniqueItems": true
|
||||
},
|
||||
"env": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "pattern": "^[A-Z][A-Z0-9_]*$" },
|
||||
"uniqueItems": true
|
||||
}
|
||||
}
|
||||
}
|
||||
69
packages/schemas/schemas/logicsrc-run.schema.json
Normal file
69
packages/schemas/schemas/logicsrc-run.schema.json
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://schemas.logicsrc.com/logicsrc-run.schema.json",
|
||||
"title": "LogicSRC Agent Run",
|
||||
"type": "object",
|
||||
"required": ["type", "version", "run_id", "task_id", "agent_did", "status", "started_at"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"type": { "const": "logicsrc.agent_run" },
|
||||
"version": { "type": "string", "pattern": "^\\d+\\.\\d+(\\.\\d+)?$" },
|
||||
"run_id": { "type": "string", "minLength": 1 },
|
||||
"task_id": { "type": "string", "minLength": 1 },
|
||||
"agent_did": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-z0-9][a-z0-9._-]*\\.[a-z0-9][a-z0-9._-]*$"
|
||||
},
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": ["created", "authorized", "started", "running", "submitted", "completed", "failed", "cancelled", "disputed"]
|
||||
},
|
||||
"started_at": { "type": "string", "format": "date-time" },
|
||||
"completed_at": { "type": "string", "format": "date-time" },
|
||||
"logs": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["timestamp", "action", "status"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"timestamp": { "type": "string", "format": "date-time" },
|
||||
"action": { "type": "string" },
|
||||
"status": { "type": "string" },
|
||||
"resource": { "type": "string" },
|
||||
"message": { "type": "string" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"files_accessed": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"tools_used": {
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},
|
||||
"deliverables": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["type", "url"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"type": { "type": "string" },
|
||||
"url": { "type": "string", "format": "uri" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"cost": {
|
||||
"type": "object",
|
||||
"required": ["amount", "currency"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"amount": { "type": "number", "minimum": 0 },
|
||||
"currency": { "type": "string", "minLength": 2, "maxLength": 12 }
|
||||
}
|
||||
},
|
||||
"payment_status": { "type": "string" }
|
||||
}
|
||||
}
|
||||
114
packages/schemas/schemas/logicsrc-task.schema.json
Normal file
114
packages/schemas/schemas/logicsrc-task.schema.json
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://schemas.logicsrc.com/logicsrc-task.schema.json",
|
||||
"title": "LogicSRC Task",
|
||||
"type": "object",
|
||||
"required": ["type", "version", "title", "description", "board", "creator_did", "status"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"type": { "const": "logicsrc.task" },
|
||||
"version": { "type": "string", "pattern": "^\\d+\\.\\d+(\\.\\d+)?$" },
|
||||
"title": { "type": "string", "minLength": 1, "maxLength": 160 },
|
||||
"description": { "type": "string", "minLength": 1 },
|
||||
"board": { "type": "string", "pattern": "^/[a-z0-9][a-z0-9/_-]*$" },
|
||||
"creator_did": { "$ref": "#/$defs/did" },
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"draft",
|
||||
"open",
|
||||
"funded",
|
||||
"claimed",
|
||||
"in_progress",
|
||||
"submitted",
|
||||
"approved",
|
||||
"paid",
|
||||
"rejected",
|
||||
"disputed",
|
||||
"cancelled",
|
||||
"expired",
|
||||
"refunded"
|
||||
]
|
||||
},
|
||||
"budget": { "$ref": "#/$defs/money" },
|
||||
"currency": { "type": "string", "minLength": 2, "maxLength": 12 },
|
||||
"deadline": { "type": "string", "format": "date-time" },
|
||||
"skills": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 },
|
||||
"uniqueItems": true
|
||||
},
|
||||
"acceptance_criteria": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "minLength": 1 }
|
||||
},
|
||||
"attachments": {
|
||||
"type": "array",
|
||||
"items": { "$ref": "#/$defs/attachment" }
|
||||
},
|
||||
"external_links": {
|
||||
"type": "array",
|
||||
"items": { "type": "string", "format": "uri" }
|
||||
},
|
||||
"github_repo": { "type": "string" },
|
||||
"github_issue": { "type": "string" },
|
||||
"target_url": { "type": "string", "format": "uri" },
|
||||
"permissions": {
|
||||
"type": "object",
|
||||
"additionalProperties": { "type": "boolean" }
|
||||
},
|
||||
"assignee_did": { "$ref": "#/$defs/did" },
|
||||
"agent_allowed": { "type": "boolean", "default": true },
|
||||
"human_allowed": { "type": "boolean", "default": true },
|
||||
"escrow_required": { "type": "boolean", "default": false },
|
||||
"payment": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"provider": { "type": "string" },
|
||||
"escrow_id": { "type": "string" },
|
||||
"status": {
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"unfunded",
|
||||
"funding_pending",
|
||||
"funded",
|
||||
"release_pending",
|
||||
"released",
|
||||
"refunded",
|
||||
"disputed",
|
||||
"cancelled",
|
||||
"failed"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"logicsrc_version": { "type": "string" }
|
||||
},
|
||||
"$defs": {
|
||||
"did": {
|
||||
"type": "string",
|
||||
"pattern": "^[a-z0-9][a-z0-9._-]*\\.[a-z0-9][a-z0-9._-]*$"
|
||||
},
|
||||
"money": {
|
||||
"type": "object",
|
||||
"required": ["amount", "currency"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"amount": { "type": "number", "exclusiveMinimum": 0 },
|
||||
"currency": { "type": "string", "minLength": 2, "maxLength": 12 }
|
||||
}
|
||||
},
|
||||
"attachment": {
|
||||
"type": "object",
|
||||
"required": ["type", "url"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"type": { "type": "string" },
|
||||
"name": { "type": "string" },
|
||||
"url": { "type": "string", "format": "uri" },
|
||||
"sha256": { "type": "string" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
packages/tui/package.json
Normal file
17
packages/tui/package.json
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"name": "@logicsrc/tui",
|
||||
"version": "0.1.0",
|
||||
"description": "CommandBoard.run terminal UI.",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@logicsrc/plugin-core": "file:../plugin-core",
|
||||
"@logicsrc/plugin-coinpay": "file:../../plugins/coinpay",
|
||||
"@logicsrc/plugin-sh1pt": "file:../../plugins/sh1pt",
|
||||
"@logicsrc/plugin-ugig": "file:../../plugins/ugig"
|
||||
}
|
||||
}
|
||||
52
packages/tui/src/index.ts
Normal file
52
packages/tui/src/index.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import { createPluginRegistry } from "@logicsrc/plugin-core";
|
||||
import { coinPayPlugin } from "@logicsrc/plugin-coinpay";
|
||||
import { sh1ptPlugin } from "@logicsrc/plugin-sh1pt";
|
||||
import { uGigPlugin } from "@logicsrc/plugin-ugig";
|
||||
|
||||
export interface TuiState {
|
||||
did: string;
|
||||
board: string;
|
||||
reputation: number;
|
||||
balance: string;
|
||||
}
|
||||
|
||||
const defaultState: TuiState = {
|
||||
did: "anthony.coinpay",
|
||||
board: "/gigs",
|
||||
reputation: 98,
|
||||
balance: "$42"
|
||||
};
|
||||
|
||||
export function renderTui(state: Partial<TuiState> = {}) {
|
||||
const view = { ...defaultState, ...state };
|
||||
const registry = createPluginRegistry([coinPayPlugin, uGigPlugin, sh1ptPlugin]);
|
||||
const plugins = registry.snapshot().plugins;
|
||||
|
||||
return [
|
||||
"┌─ CommandBoard.run ──────────────────────────────────────────┐",
|
||||
`│ DID: ${pad(view.did, 17)} Board: ${pad(view.board, 7)} Rep: ${String(view.reputation).padEnd(3)} Balance: ${pad(view.balance, 6)} │`,
|
||||
"├───────────────┬─────────────────────────────────────────────┤",
|
||||
"│ Boards │ Feed │",
|
||||
"│ > /gigs │ [TASK] QA checkout flow - 25 USDC │",
|
||||
"│ /agents │ [POST] New agent plugin idea │",
|
||||
"│ /qa │ [RUN] qa-agent completed task_123 │",
|
||||
"│ /jobs │ [uGig] Senior AI Engineer remote │",
|
||||
"│ /projects │ [sh1pt] Release action published │",
|
||||
"├───────────────┴─────────────────────────────────────────────┤",
|
||||
"│ Plugins: " + plugins.map((plugin) => `${plugin.name} ${plugin.enabled ? "enabled" : "disabled"}`).join(" | ").padEnd(50) + " │",
|
||||
"│ Enter: open p: post t: task a: agents w: wallet q: quit │",
|
||||
"└─────────────────────────────────────────────────────────────┘"
|
||||
].join("\n");
|
||||
}
|
||||
|
||||
export function renderPluginStatus() {
|
||||
const registry = createPluginRegistry([coinPayPlugin, uGigPlugin, sh1ptPlugin]);
|
||||
return registry
|
||||
.snapshot()
|
||||
.plugins.map((plugin) => `${plugin.id.padEnd(8)} ${plugin.enabled ? "enabled" : "disabled"} ${plugin.type.join(", ")}`)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
function pad(value: string, width: number) {
|
||||
return value.length >= width ? value.slice(0, width) : value.padEnd(width);
|
||||
}
|
||||
8
packages/tui/tsconfig.json
Normal file
8
packages/tui/tsconfig.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
24
packages/validators/package.json
Normal file
24
packages/validators/package.json
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "@logicsrc/validators",
|
||||
"version": "0.1.0",
|
||||
"description": "LogicSRC schema validation helpers.",
|
||||
"type": "module",
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
"bin": {
|
||||
"logicsrc-validate": "./dist/cli.js"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "tsc -p tsconfig.json",
|
||||
"test": "vitest run src",
|
||||
"validate:fixtures": "node dist/cli.js task ../schemas/fixtures/task.yaml && node dist/cli.js agent ../schemas/fixtures/agent.yaml"
|
||||
},
|
||||
"dependencies": {
|
||||
"ajv": "^8.17.1",
|
||||
"ajv-formats": "^3.0.1",
|
||||
"yaml": "^2.8.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"vitest": "^4.0.8"
|
||||
}
|
||||
}
|
||||
33
packages/validators/src/cli.ts
Normal file
33
packages/validators/src/cli.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#!/usr/bin/env node
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { assertSchemaKind, parseDocument, validate } from "./index.js";
|
||||
|
||||
function main(argv: string[]) {
|
||||
const [, , kindArg, fileArg] = argv;
|
||||
|
||||
if (!kindArg || !fileArg) {
|
||||
console.error("Usage: logicsrc-validate <task|agent|run|event|plugin> <file.yaml|file.json>");
|
||||
process.exitCode = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
const kind = assertSchemaKind(kindArg);
|
||||
const filePath = resolve(process.cwd(), fileArg);
|
||||
const input = readFileSync(filePath, "utf8");
|
||||
const data = parseDocument(input, filePath);
|
||||
const result = validate(kind, data);
|
||||
|
||||
if (!result.ok) {
|
||||
console.error(`Invalid LogicSRC ${kind} document: ${filePath}`);
|
||||
for (const error of result.errors) {
|
||||
console.error(`- ${error.instancePath || "/"} ${error.message ?? "failed validation"}`);
|
||||
}
|
||||
process.exitCode = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
console.log(`Valid LogicSRC ${kind} document: ${filePath}`);
|
||||
}
|
||||
|
||||
main(process.argv);
|
||||
28
packages/validators/src/index.test.ts
Normal file
28
packages/validators/src/index.test.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
import { readFileSync } from "node:fs";
|
||||
import { dirname, resolve } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseDocument, validate } from "./index.js";
|
||||
|
||||
describe("LogicSRC validators", () => {
|
||||
it("validates the task fixture", () => {
|
||||
const testDir = dirname(fileURLToPath(import.meta.url));
|
||||
const file = resolve(testDir, "../../schemas/fixtures/task.yaml");
|
||||
const data = parseDocument(readFileSync(file, "utf8"), file);
|
||||
|
||||
expect(validate("task", data).ok).toBe(true);
|
||||
});
|
||||
|
||||
it("rejects a task without a DID", () => {
|
||||
const result = validate("task", {
|
||||
type: "logicsrc.task",
|
||||
version: "0.1",
|
||||
title: "Missing DID",
|
||||
description: "This should fail.",
|
||||
board: "/qa",
|
||||
status: "open"
|
||||
});
|
||||
|
||||
expect(result.ok).toBe(false);
|
||||
});
|
||||
});
|
||||
52
packages/validators/src/index.ts
Normal file
52
packages/validators/src/index.ts
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import * as Ajv2020Module from "ajv/dist/2020.js";
|
||||
import * as addFormatsModule from "ajv-formats";
|
||||
import type { ErrorObject } from "ajv";
|
||||
import { parse } from "yaml";
|
||||
import { isSchemaKind, schemas, type SchemaKind } from "./schemas.js";
|
||||
|
||||
const Ajv2020 = (Ajv2020Module as unknown as { default: new (options: Record<string, unknown>) => { compile: (schema: unknown) => { (data: unknown): boolean; errors?: ErrorObject[] | null } } }).default;
|
||||
const addFormats = (addFormatsModule as unknown as { default: (ajv: InstanceType<typeof Ajv2020>) => void }).default;
|
||||
|
||||
export type ValidationResult =
|
||||
| { ok: true; kind: SchemaKind; data: unknown }
|
||||
| { ok: false; kind: SchemaKind; errors: ErrorObject[] };
|
||||
|
||||
export function createValidator() {
|
||||
const ajv = new Ajv2020({ allErrors: true, strict: true });
|
||||
addFormats(ajv);
|
||||
return ajv;
|
||||
}
|
||||
|
||||
export function parseDocument(input: string, fileName = "document") {
|
||||
if (fileName.endsWith(".json")) {
|
||||
return JSON.parse(input) as unknown;
|
||||
}
|
||||
|
||||
return parse(input) as unknown;
|
||||
}
|
||||
|
||||
export function validate(kind: SchemaKind, data: unknown): ValidationResult {
|
||||
const ajv = createValidator();
|
||||
const validateDocument = ajv.compile(schemas[kind]);
|
||||
const ok = validateDocument(data);
|
||||
|
||||
if (ok) {
|
||||
return { ok: true, kind, data };
|
||||
}
|
||||
|
||||
return {
|
||||
ok: false,
|
||||
kind,
|
||||
errors: validateDocument.errors ?? []
|
||||
};
|
||||
}
|
||||
|
||||
export function assertSchemaKind(value: string): SchemaKind {
|
||||
if (!isSchemaKind(value)) {
|
||||
throw new Error(`Unknown schema kind "${value}". Expected one of: ${Object.keys(schemas).join(", ")}`);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export { schemas, type SchemaKind };
|
||||
19
packages/validators/src/schemas.ts
Normal file
19
packages/validators/src/schemas.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import agentSchema from "../../schemas/schemas/logicsrc-agent.schema.json" with { type: "json" };
|
||||
import eventSchema from "../../schemas/schemas/logicsrc-event.schema.json" with { type: "json" };
|
||||
import pluginSchema from "../../schemas/schemas/logicsrc-plugin.schema.json" with { type: "json" };
|
||||
import runSchema from "../../schemas/schemas/logicsrc-run.schema.json" with { type: "json" };
|
||||
import taskSchema from "../../schemas/schemas/logicsrc-task.schema.json" with { type: "json" };
|
||||
|
||||
export const schemas = {
|
||||
agent: agentSchema,
|
||||
event: eventSchema,
|
||||
plugin: pluginSchema,
|
||||
run: runSchema,
|
||||
task: taskSchema
|
||||
} as const;
|
||||
|
||||
export type SchemaKind = keyof typeof schemas;
|
||||
|
||||
export function isSchemaKind(value: string): value is SchemaKind {
|
||||
return value in schemas;
|
||||
}
|
||||
8
packages/validators/tsconfig.json
Normal file
8
packages/validators/tsconfig.json
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "src",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src/**/*.ts"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue