@oyasmi/pipiclaw 0.8.1 → 0.8.2

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,6 +1,6 @@
1
1
  import { chmodSync, existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
2
2
  import { join } from "path";
3
- import { parseBuiltInCommand } from "../agent/commands.js";
3
+ import { formatUnknownCommandMessage, isRunnerBuiltInCommand, parseBuiltInCommand, slashCommandName, } from "../agent/commands.js";
4
4
  import { getOrCreateRunner } from "../agent/index.js";
5
5
  import { resetRunner } from "../agent/runner-factory.js";
6
6
  import { renderStatus } from "../agent/status-render.js";
@@ -339,11 +339,20 @@ export function parseArgs(argv, paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
339
339
  const args = argv.slice(2);
340
340
  for (let index = 0; index < args.length; index += 1) {
341
341
  const arg = args[index];
342
+ if (index === 0 && arg === "run") {
343
+ // Explicit name for the default daemon mode (`pipiclaw run` == `pipiclaw`).
344
+ continue;
345
+ }
342
346
  if (arg === "--help" || arg === "-h") {
343
- io.log(`Usage: ${paths.appName} [options]`);
347
+ io.log(`Usage: ${paths.appName} [command] [options]`);
348
+ io.log("");
349
+ io.log("Commands:");
350
+ io.log(" run Run the long-lived DingTalk daemon (default)");
351
+ io.log(" tui [prompt] Chat with the agent in the terminal");
344
352
  io.log("");
345
353
  io.log("Options:");
346
354
  io.log(" --version Print the current version and exit");
355
+ io.log(" --help, -h Show this help and exit");
347
356
  io.log("");
348
357
  io.log(`Config: ${paths.channelConfigPath}`);
349
358
  io.log(`Workspace: ${paths.workspaceDir}`);
@@ -353,6 +362,11 @@ export function parseArgs(argv, paths = DEFAULT_BOOTSTRAP_PATHS, io = console) {
353
362
  io.log(readCliVersion());
354
363
  throw new BootstrapExitError(0);
355
364
  }
365
+ else {
366
+ io.error(`Unknown option: ${arg}`);
367
+ io.error(`Run \`${paths.appName} --help\` for usage.`);
368
+ throw new BootstrapExitError(1);
369
+ }
356
370
  }
357
371
  }
358
372
  function waitForTasks(tasks, timeoutMs) {
@@ -581,7 +595,17 @@ export function createRuntimeContext(options) {
581
595
  await handler.handleUsageCommand(event, bot, builtInCommand.args);
582
596
  return;
583
597
  }
584
- await state.runner.handleBuiltinCommand(ctx, builtInCommand);
598
+ if (isRunnerBuiltInCommand(builtInCommand)) {
599
+ await state.runner.handleBuiltinCommand(ctx, builtInCommand);
600
+ }
601
+ return;
602
+ }
603
+ // Reject an unknown slash command instead of spending a full LLM turn
604
+ // letting the model guess what `/modle` meant. Session commands,
605
+ // skills, and prompt templates are recognized by isKnownSlashCommand.
606
+ if (event.text.trim().startsWith("/") && !state.runner.isKnownSlashCommand(event.text)) {
607
+ const name = slashCommandName(event.text) ?? "";
608
+ await bot.sendPlain(event.channelId, formatUnknownCommandMessage(name));
585
609
  return;
586
610
  }
587
611
  log.logInfo(`[${event.channelId}] Starting run: ${event.text.substring(0, 50)}`);
@@ -11,7 +11,7 @@ import axios from "axios";
11
11
  import { DWClient, TOPIC_ROBOT } from "dingtalk-stream";
12
12
  import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
13
13
  import { dirname, join } from "path";
14
- import { parseBuiltInCommand, renderBuiltInHelp } from "../agent/commands.js";
14
+ import { formatBusyCommandList, parseBuiltInCommand, renderBuiltInHelp } from "../agent/commands.js";
15
15
  import * as log from "../log.js";
16
16
  import { errorMessage } from "../shared/text-utils.js";
17
17
  import { isRecord } from "../shared/type-guards.js";
@@ -976,51 +976,43 @@ export class DingTalkBot {
976
976
  const isSlashCommand = content.trim().startsWith("/");
977
977
  // Check if busy
978
978
  if (this.handler.isRunning(channelId)) {
979
- if (builtInCommand?.name === "help") {
980
- await this.sendPlain(channelId, renderBuiltInHelp());
981
- return;
982
- }
983
- if (builtInCommand?.name === "stop") {
984
- await this.handler.handleStop(channelId, this);
985
- await this.sendPlain(channelId, "Stopping the current task.");
986
- return;
987
- }
988
- if (builtInCommand?.name === "steer") {
989
- const result = await this.handler.handleBusyMessage(event, this, "steer", builtInCommand.args);
990
- if (result.kind === "requeue") {
991
- this.enqueueStreamMessage(event, result.text);
992
- }
993
- return;
994
- }
995
- if (builtInCommand?.name === "followup") {
996
- const result = await this.handler.handleBusyMessage(event, this, "followUp", builtInCommand.args);
997
- if (result.kind === "requeue") {
998
- this.enqueueStreamMessage(event, result.text);
999
- }
1000
- return;
1001
- }
1002
- if (builtInCommand?.name === "events") {
1003
- await this.handler.handleEventsCommand(event, this, builtInCommand.args);
1004
- return;
1005
- }
1006
- if (builtInCommand?.name === "tasks") {
1007
- await this.handler.handleTasksCommand(event, this, builtInCommand.args);
1008
- return;
1009
- }
1010
- if (builtInCommand?.name === "status") {
1011
- await this.handler.handleStatusCommand(event, this);
1012
- return;
1013
- }
1014
- if (builtInCommand?.name === "usage") {
1015
- await this.handler.handleUsageCommand(event, this, builtInCommand.args);
1016
- return;
1017
- }
979
+ // All built-in transport commands are usable while a task streams.
1018
980
  if (builtInCommand) {
1019
- await this.sendPlain(channelId, `A task is already running. Use \`/stop\`, \`/steer <message>\`, \`/followup <message>\`, \`/events <action>\`, \`/tasks\`, \`/status\`, or \`/usage\`. Plain messages default to ${this.busyMessageDefault}.`);
1020
- return;
981
+ switch (builtInCommand.name) {
982
+ case "help":
983
+ await this.sendPlain(channelId, renderBuiltInHelp());
984
+ return;
985
+ case "stop":
986
+ await this.handler.handleStop(channelId, this);
987
+ await this.sendPlain(channelId, "Stopping the current task.");
988
+ return;
989
+ case "steer":
990
+ case "followup": {
991
+ const mode = builtInCommand.name === "steer" ? "steer" : "followUp";
992
+ const result = await this.handler.handleBusyMessage(event, this, mode, builtInCommand.args);
993
+ if (result.kind === "requeue") {
994
+ this.enqueueStreamMessage(event, result.text);
995
+ }
996
+ return;
997
+ }
998
+ case "events":
999
+ await this.handler.handleEventsCommand(event, this, builtInCommand.args);
1000
+ return;
1001
+ case "tasks":
1002
+ await this.handler.handleTasksCommand(event, this, builtInCommand.args);
1003
+ return;
1004
+ case "status":
1005
+ await this.handler.handleStatusCommand(event, this);
1006
+ return;
1007
+ case "usage":
1008
+ await this.handler.handleUsageCommand(event, this, builtInCommand.args);
1009
+ return;
1010
+ }
1021
1011
  }
1012
+ // Session commands (/model, /new, …) and unknown slash commands cannot
1013
+ // run mid-turn: they would need the idle session layer.
1022
1014
  if (isSlashCommand) {
1023
- await this.sendPlain(channelId, "A task is already running. Only `/stop`, `/steer <message>`, `/followup <message>`, `/events <action>`, and `/tasks` are available while streaming.");
1015
+ await this.sendPlain(channelId, `A task is already running. While streaming you can use: ${formatBusyCommandList()}. Session commands (\`/model\`, \`/new\`, \`/compact\`, \`/session\`) are available when idle.`);
1024
1016
  return;
1025
1017
  }
1026
1018
  const result = await this.handler.handleBusyMessage(event, this, this.busyMessageDefault, content);
@@ -77,8 +77,8 @@ export function createTaskDriverEvent(channelId, entry, nowMs) {
77
77
  const verification = entry.frontmatter.control?.verification;
78
78
  const verificationInstruction = entry.frontmatter.status === "verifying"
79
79
  ? verification?.status === "passed"
80
- ? " Independent verification already passed; preserve its body/artifact hashes and follow the closeout playbook."
81
- : " This is a checker-only turn: read the closeout playbook and do not continue implementation."
80
+ ? ` Independent verification already passed; preserve its body/artifact hashes and follow ${join(PLAYBOOKS_DIR, "task-closeout.md")}.`
81
+ : ` This is a checker-only turn: read ${join(PLAYBOOKS_DIR, "task-closeout.md")} and do not continue implementation.`
82
82
  : "";
83
83
  const repair = entry.frontmatter.readable
84
84
  ? ""
package/dist/tui/cli.d.ts CHANGED
@@ -14,6 +14,9 @@ export type ParsedTui = {
14
14
  kind: "help";
15
15
  } | {
16
16
  kind: "version";
17
+ } | {
18
+ kind: "error";
19
+ message: string;
17
20
  };
18
21
  /** Parse `pipiclaw tui` arguments (everything after the `tui` subcommand). */
19
22
  export declare function parseTuiArgs(args: string[]): ParsedTui;
package/dist/tui/cli.js CHANGED
@@ -2,7 +2,7 @@
2
2
  * `pipiclaw tui` CLI: argument parsing and entry. Parsing is a pure function
3
3
  * (`parseTuiArgs`) so it can be unit-tested; `runTui` wires it to `runTuiApp`.
4
4
  */
5
- import { readCliVersion } from "../runtime/bootstrap.js";
5
+ import { BootstrapExitError, readCliVersion } from "../runtime/bootstrap.js";
6
6
  import { runTuiApp } from "./app.js";
7
7
  /** Parse `pipiclaw tui` arguments (everything after the `tui` subcommand). */
8
8
  export function parseTuiArgs(args) {
@@ -35,6 +35,11 @@ export function parseTuiArgs(args) {
35
35
  else if (arg === "--version") {
36
36
  return { kind: "version" };
37
37
  }
38
+ else if (arg.startsWith("--")) {
39
+ // An unknown long option is a typo, not part of the prompt — reject it
40
+ // instead of silently sending `--pritn` to the model as prompt text.
41
+ return { kind: "error", message: `Unknown option: ${arg}` };
42
+ }
38
43
  else {
39
44
  positional.push(arg);
40
45
  }
@@ -79,6 +84,11 @@ export async function runTui(argv, io = console) {
79
84
  io.log(readCliVersion());
80
85
  return;
81
86
  }
87
+ if (parsed.kind === "error") {
88
+ io.error(parsed.message);
89
+ io.error(`Run \`pipiclaw tui --help\` for usage.`);
90
+ throw new BootstrapExitError(1);
91
+ }
82
92
  let initialPrompt = parsed.positional.join(" ").trim() || undefined;
83
93
  if (parsed.print && !initialPrompt && process.stdin.isTTY !== true) {
84
94
  initialPrompt = (await readStdin()).trim() || undefined;
@@ -40,7 +40,10 @@ export interface DispatchDeps {
40
40
  runTasks(args: string): Promise<string>;
41
41
  }
42
42
  export declare function dispatch(input: string, deps: DispatchDeps): Promise<DispatchOutcome>;
43
- /** Slash commands offered in editor autocomplete: transport + session + TUI-only. */
43
+ /**
44
+ * Slash commands offered in editor autocomplete: transport + session (both
45
+ * derived from the shared command tables) plus the TUI-only `/exit`.
46
+ */
44
47
  export declare const TUI_SLASH_COMMANDS: Array<{
45
48
  name: string;
46
49
  description: string;
@@ -13,7 +13,7 @@
13
13
  * depend on whether a turn is running, which only the app knows — so those come
14
14
  * back as intents rather than being applied here.
15
15
  */
16
- import { parseBuiltInCommand } from "../agent/commands.js";
16
+ import { BUILT_IN_COMMANDS, parseBuiltInCommand, SESSION_COMMANDS } from "../agent/commands.js";
17
17
  export async function dispatch(input, deps) {
18
18
  const trimmed = input.trim();
19
19
  if (!trimmed)
@@ -49,19 +49,15 @@ export async function dispatch(input, deps) {
49
49
  : { kind: "noop", text: "/followup requires a message." };
50
50
  }
51
51
  }
52
- /** Slash commands offered in editor autocomplete: transport + session + TUI-only. */
52
+ function toAutocompleteEntry(spec) {
53
+ return { name: spec.name, description: spec.description, argumentHint: spec.argumentHint };
54
+ }
55
+ /**
56
+ * Slash commands offered in editor autocomplete: transport + session (both
57
+ * derived from the shared command tables) plus the TUI-only `/exit`.
58
+ */
53
59
  export const TUI_SLASH_COMMANDS = [
54
- { name: "help", description: "Show command help" },
55
- { name: "stop", description: "Stop the current task" },
56
- { name: "steer", description: "Adjust the running task", argumentHint: "<message>" },
57
- { name: "followup", description: "Queue a request after the current task", argumentHint: "<message>" },
58
- { name: "status", description: "Show model, context and run state" },
59
- { name: "usage", description: "Show LLM cost for this channel", argumentHint: "[7d|month]" },
60
- { name: "events", description: "Manage scheduled events", argumentHint: "<list|show|delete|history>" },
61
- { name: "tasks", description: "View the task ledger (read-only)", argumentHint: "[show <id>|archive|doctor]" },
62
- { name: "model", description: "Show or switch the model", argumentHint: "[provider/model]" },
63
- { name: "new", description: "Start a new session" },
64
- { name: "compact", description: "Compact the session context", argumentHint: "[instructions]" },
65
- { name: "session", description: "Show session state" },
60
+ ...BUILT_IN_COMMANDS.map(toAutocompleteEntry),
61
+ ...SESSION_COMMANDS.map(toAutocompleteEntry),
66
62
  { name: "exit", description: "Leave the TUI" },
67
63
  ];
@@ -6,6 +6,7 @@
6
6
  * Collaborators (runner, frontend, store) are injected so the machine can be
7
7
  * unit-tested with fakes and a fake clock. `app.ts` builds the real ones.
8
8
  */
9
+ import { formatUnknownCommandMessage, slashCommandName } from "../agent/commands.js";
9
10
  import { renderStatus } from "../agent/status-render.js";
10
11
  import * as log from "../log.js";
11
12
  import { errorMessage } from "../shared/text-utils.js";
@@ -110,7 +111,15 @@ export class TurnController {
110
111
  this.applyFollowup(outcome.text);
111
112
  return;
112
113
  case "steer":
114
+ await this.applyText(outcome.text);
115
+ return;
113
116
  case "run":
117
+ // Reject an unknown slash command rather than steering/running its raw
118
+ // text. Session commands, skills, and prompt templates pass through.
119
+ if (outcome.text.trim().startsWith("/") && !this.deps.runner.isKnownSlashCommand(outcome.text)) {
120
+ this.deps.frontend.showFinal(formatUnknownCommandMessage(slashCommandName(outcome.text) ?? ""));
121
+ return;
122
+ }
114
123
  await this.applyText(outcome.text);
115
124
  return;
116
125
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oyasmi/pipiclaw",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "An AI assistant runtime for coding and team workflows, with DingTalk AI Cards, sub-agents, memory, and scheduled events.",
5
5
  "type": "module",
6
6
  "bin": {
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "scripts": {
24
24
  "clean": "node -e \"require('node:fs').rmSync('dist', { recursive: true, force: true }); require('node:fs').rmSync('coverage', { recursive: true, force: true });\"",
25
- "build": "tsc -p tsconfig.build.json && node -e \"const fs = require('node:fs'); const src='src/playbooks'; const dst='dist/playbooks'; fs.mkdirSync(dst,{recursive:true}); for (const f of fs.readdirSync(dst)) { if (f.endsWith('.md') || f === 'scripts') fs.rmSync(dst+'/'+f,{recursive:true,force:true}); } for (const f of fs.readdirSync(src)) { if (f.endsWith('.md')) fs.copyFileSync(src+'/'+f,dst+'/'+f); } fs.chmodSync('dist/main.js', 0o755)\"",
25
+ "build": "tsc -p tsconfig.build.json && node -e \"const fs = require('node:fs'); const src = 'src/playbooks', dst = 'dist/playbooks'; fs.rmSync(dst, { recursive: true, force: true }); fs.mkdirSync(dst, { recursive: true }); for (const f of fs.readdirSync(src)) if (f.endsWith('.md')) fs.copyFileSync(src + '/' + f, dst + '/' + f); fs.chmodSync('dist/main.js', 0o755)\"",
26
26
  "dev": "tsc -p tsconfig.build.json --watch --preserveWatchOutput",
27
27
  "lint": "biome check .",
28
28
  "typecheck": "tsc --noEmit -p tsconfig.json",
@@ -1,9 +0,0 @@
1
- export interface RuntimePlaybookMetadata {
2
- name: string;
3
- description: string;
4
- filename: string;
5
- path: string;
6
- }
7
- /** Load the small always-on catalog; playbook bodies remain on disk until the agent reads one. */
8
- export declare function loadRuntimePlaybookCatalog(directory?: string): RuntimePlaybookMetadata[];
9
- export declare function renderRuntimePlaybookIndex(directory?: string): string;
@@ -1,44 +0,0 @@
1
- import { readdirSync, readFileSync } from "node:fs";
2
- import { basename, join } from "node:path";
3
- import { PLAYBOOKS_DIR } from "../paths.js";
4
- function parseFrontmatter(content, filename) {
5
- const match = /^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)/.exec(content);
6
- if (!match)
7
- throw new Error(`Runtime playbook ${filename} has no YAML frontmatter.`);
8
- const fields = new Map();
9
- for (const line of match[1]?.split(/\r?\n/) ?? []) {
10
- const separator = line.indexOf(":");
11
- if (separator < 0)
12
- continue;
13
- const key = line.slice(0, separator).trim();
14
- let value = line.slice(separator + 1).trim();
15
- if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
16
- value = value.slice(1, -1);
17
- }
18
- fields.set(key, value);
19
- }
20
- const name = fields.get("name")?.trim();
21
- const description = fields.get("description")?.trim();
22
- if (!name || !description) {
23
- throw new Error(`Runtime playbook ${filename} requires non-empty name and description metadata.`);
24
- }
25
- if (`${name}.md` !== filename) {
26
- throw new Error(`Runtime playbook ${filename} metadata name must be "${basename(filename, ".md")}".`);
27
- }
28
- return { name, description };
29
- }
30
- /** Load the small always-on catalog; playbook bodies remain on disk until the agent reads one. */
31
- export function loadRuntimePlaybookCatalog(directory = PLAYBOOKS_DIR) {
32
- return readdirSync(directory)
33
- .filter((filename) => filename.endsWith(".md"))
34
- .sort()
35
- .map((filename) => {
36
- const path = join(directory, filename);
37
- return { ...parseFrontmatter(readFileSync(path, "utf-8"), filename), filename, path };
38
- });
39
- }
40
- export function renderRuntimePlaybookIndex(directory = PLAYBOOKS_DIR) {
41
- return loadRuntimePlaybookCatalog(directory)
42
- .map((playbook) => `- ${playbook.filename} — ${playbook.description}`)
43
- .join("\n");
44
- }