From 3b7d0564bb026ff0f1c4be64bb2170ac52feb06a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=A9=98?= Date: Fri, 22 May 2026 08:53:27 +0000 Subject: [PATCH] feat: uwf cas put-text for storing plain text in CAS - Register built-in text schema ({type: 'string'}) alongside workflow schemas - Add cmdCasPutText command: uwf cas put-text - Update CLI reference in workflow-util - Update solve-issue.yaml procedure to use put-text Refs #380 --- .workflows/solve-issue.yaml | 2 +- packages/cli-workflow/src/cli.ts | 12 ++++++++++++ packages/cli-workflow/src/commands/cas.ts | 11 ++++++++++- packages/cli-workflow/src/schemas.ts | 8 ++++++-- packages/workflow-util/src/cli-reference.ts | 2 ++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.workflows/solve-issue.yaml b/.workflows/solve-issue.yaml index cb78960..cfc41ea 100644 --- a/.workflows/solve-issue.yaml +++ b/.workflows/solve-issue.yaml @@ -20,7 +20,7 @@ roles: 2. Revise the test spec accordingly After producing the test spec: - 1. Store it via `uwf cas put ""` and capture the returned hash + 1. Store it via `uwf cas put-text ""` and capture the returned hash 2. Put the hash in meta.plan (required when status=ready) output: "Output a brief summary of the test spec. Frontmatter must include: status (ready or insufficient_info) and plan (CAS hash of the test spec, required when status=ready)." frontmatter: diff --git a/packages/cli-workflow/src/cli.ts b/packages/cli-workflow/src/cli.ts index 378c093..06ce750 100755 --- a/packages/cli-workflow/src/cli.ts +++ b/packages/cli-workflow/src/cli.ts @@ -7,6 +7,7 @@ import { cmdCasGet, cmdCasHas, cmdCasPut, + cmdCasPutText, cmdCasRefs, cmdCasReindex, cmdCasSchemaGet, @@ -295,6 +296,17 @@ cas }); }); +cas + .command("put-text") + .description("Store a plain text string, print its hash") + .argument("", "Text content to store") + .action((text: string) => { + const storageRoot = resolveStorageRoot(); + runAction(async () => { + writeOutput(await cmdCasPutText(storageRoot, text)); + }); + }); + cas .command("has") .description("Check if a hash exists") diff --git a/packages/cli-workflow/src/commands/cas.ts b/packages/cli-workflow/src/commands/cas.ts index 2bc7b58..8f9dbeb 100644 --- a/packages/cli-workflow/src/commands/cas.ts +++ b/packages/cli-workflow/src/commands/cas.ts @@ -2,9 +2,11 @@ import { readFileSync } from "node:fs"; import { join } from "node:path"; import type { JSONSchema, Store } from "@uncaged/json-cas"; -import { bootstrap, getSchema, refs, walk } from "@uncaged/json-cas"; +import { bootstrap, getSchema, putSchema, refs, walk } from "@uncaged/json-cas"; import { createFsStore } from "@uncaged/json-cas-fs"; +import { TEXT_SCHEMA } from "../schemas.js"; + // ---- Helpers ---- function openStore(storageRoot: string): Store { @@ -121,3 +123,10 @@ export async function cmdCasSchemaGet(storageRoot: string, hash: string): Promis } return schema; } + +export async function cmdCasPutText(storageRoot: string, text: string): Promise<{ hash: string }> { + const store = openStore(storageRoot); + const typeHash = await putSchema(store, TEXT_SCHEMA); + const hash = await store.put(typeHash, text); + return { hash }; +} diff --git a/packages/cli-workflow/src/schemas.ts b/packages/cli-workflow/src/schemas.ts index 06cc087..530c2c0 100644 --- a/packages/cli-workflow/src/schemas.ts +++ b/packages/cli-workflow/src/schemas.ts @@ -2,10 +2,13 @@ import type { Hash, Store } from "@uncaged/json-cas"; import { putSchema } from "@uncaged/json-cas"; import { START_NODE_SCHEMA, STEP_NODE_SCHEMA, WORKFLOW_SCHEMA } from "@uncaged/workflow-protocol"; +export const TEXT_SCHEMA = { type: "string" as const }; + export type UwfSchemaHashes = { workflow: Hash; startNode: Hash; stepNode: Hash; + text: Hash; }; /** @@ -13,10 +16,11 @@ export type UwfSchemaHashes = { * Idempotent: safe to call on every CLI invocation. */ export async function registerUwfSchemas(store: Store): Promise { - const [workflow, startNode, stepNode] = await Promise.all([ + const [workflow, startNode, stepNode, text] = await Promise.all([ putSchema(store, WORKFLOW_SCHEMA), putSchema(store, START_NODE_SCHEMA), putSchema(store, STEP_NODE_SCHEMA), + putSchema(store, TEXT_SCHEMA), ]); - return { workflow, startNode, stepNode }; + return { workflow, startNode, stepNode, text }; } diff --git a/packages/workflow-util/src/cli-reference.ts b/packages/workflow-util/src/cli-reference.ts index f2d3881..d4a90cf 100644 --- a/packages/workflow-util/src/cli-reference.ts +++ b/packages/workflow-util/src/cli-reference.ts @@ -46,6 +46,8 @@ uwf cas get # read a CAS node (type + payload) [--timestamp] # include timestamp in output uwf cas put # store a node, print its hash # : JSON file path or inline JSON string +uwf cas put-text # store a plain text string, print its hash + # shortcut for put with the built-in text schema uwf cas has # check if a hash exists uwf cas refs # list direct CAS references from a node uwf cas walk # recursive traversal from a node