@ocis/myagent-cli 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +357 -0
  2. package/dist/agent/context.d.ts +33 -0
  3. package/dist/agent/context.js +169 -0
  4. package/dist/agent/modes.d.ts +21 -0
  5. package/dist/agent/modes.js +84 -0
  6. package/dist/agent/prompt-builder.d.ts +9 -0
  7. package/dist/agent/prompt-builder.js +31 -0
  8. package/dist/agent/sessions.d.ts +38 -0
  9. package/dist/agent/sessions.js +130 -0
  10. package/dist/agent/todo.d.ts +18 -0
  11. package/dist/agent/todo.js +61 -0
  12. package/dist/agent/turn.d.ts +309 -0
  13. package/dist/agent/turn.js +1253 -0
  14. package/dist/approval/policy.d.ts +81 -0
  15. package/dist/approval/policy.js +157 -0
  16. package/dist/config.d.ts +49 -0
  17. package/dist/config.js +156 -0
  18. package/dist/git/status.d.ts +89 -0
  19. package/dist/git/status.js +226 -0
  20. package/dist/headless.d.ts +72 -0
  21. package/dist/headless.js +330 -0
  22. package/dist/index.d.ts +60 -0
  23. package/dist/index.js +511 -0
  24. package/dist/protocol/client.d.ts +123 -0
  25. package/dist/protocol/client.js +250 -0
  26. package/dist/protocol/sse-frames.d.ts +6 -0
  27. package/dist/protocol/sse-frames.js +75 -0
  28. package/dist/protocol/types.d.ts +200 -0
  29. package/dist/protocol/types.js +8 -0
  30. package/dist/runtime.d.ts +38 -0
  31. package/dist/runtime.js +166 -0
  32. package/dist/sanitize.d.ts +1 -0
  33. package/dist/sanitize.js +21 -0
  34. package/dist/skills/discovery.d.ts +24 -0
  35. package/dist/skills/discovery.js +109 -0
  36. package/dist/tools/binary.d.ts +2 -0
  37. package/dist/tools/binary.js +22 -0
  38. package/dist/tools/diff.d.ts +1 -0
  39. package/dist/tools/diff.js +49 -0
  40. package/dist/tools/find.d.ts +2 -0
  41. package/dist/tools/find.js +61 -0
  42. package/dist/tools/fs.d.ts +2 -0
  43. package/dist/tools/fs.js +276 -0
  44. package/dist/tools/glob.d.ts +6 -0
  45. package/dist/tools/glob.js +131 -0
  46. package/dist/tools/grep.d.ts +3 -0
  47. package/dist/tools/grep.js +228 -0
  48. package/dist/tools/paths.d.ts +27 -0
  49. package/dist/tools/paths.js +124 -0
  50. package/dist/tools/registry.d.ts +13 -0
  51. package/dist/tools/registry.js +38 -0
  52. package/dist/tools/shell.d.ts +2 -0
  53. package/dist/tools/shell.js +136 -0
  54. package/dist/tools/skills.d.ts +2 -0
  55. package/dist/tools/skills.js +36 -0
  56. package/dist/tools/todo.d.ts +2 -0
  57. package/dist/tools/todo.js +43 -0
  58. package/dist/tools/transfer.d.ts +2 -0
  59. package/dist/tools/transfer.js +145 -0
  60. package/dist/tools/truncate.d.ts +12 -0
  61. package/dist/tools/truncate.js +46 -0
  62. package/dist/tools/types.d.ts +85 -0
  63. package/dist/tools/types.js +63 -0
  64. package/dist/ui/app.d.ts +39 -0
  65. package/dist/ui/app.js +1061 -0
  66. package/dist/ui/colors.d.ts +100 -0
  67. package/dist/ui/colors.js +169 -0
  68. package/dist/ui/components.d.ts +267 -0
  69. package/dist/ui/components.js +811 -0
  70. package/dist/ui/diff.d.ts +37 -0
  71. package/dist/ui/diff.js +143 -0
  72. package/dist/ui/format.d.ts +28 -0
  73. package/dist/ui/format.js +76 -0
  74. package/dist/ui/help.d.ts +6 -0
  75. package/dist/ui/help.js +45 -0
  76. package/dist/ui/highlight.d.ts +20 -0
  77. package/dist/ui/highlight.js +210 -0
  78. package/dist/ui/logo.d.ts +24 -0
  79. package/dist/ui/logo.js +106 -0
  80. package/dist/ui/model-list.d.ts +10 -0
  81. package/dist/ui/model-list.js +33 -0
  82. package/dist/ui/quit-confirm.d.ts +8 -0
  83. package/dist/ui/quit-confirm.js +40 -0
  84. package/dist/ui/select-popup.d.ts +30 -0
  85. package/dist/ui/select-popup.js +54 -0
  86. package/dist/ui/theme.d.ts +4 -0
  87. package/dist/ui/theme.js +41 -0
  88. package/dist/ui/tool-view.d.ts +20 -0
  89. package/dist/ui/tool-view.js +326 -0
  90. package/package.json +44 -0
  91. package/skills/git-commit/SKILL.md +27 -0
@@ -0,0 +1,85 @@
1
+ import type { TodoStore } from "../agent/todo.js";
2
+ import type { IntegrationClient } from "../protocol/client.js";
3
+ export interface JsonSchema {
4
+ type: "object";
5
+ properties?: Record<string, unknown>;
6
+ required?: string[];
7
+ [key: string]: unknown;
8
+ }
9
+ export interface ToolDefinition {
10
+ type: "function";
11
+ function: {
12
+ name: string;
13
+ description: string;
14
+ parameters: JsonSchema;
15
+ };
16
+ }
17
+ export interface ApprovalRequest {
18
+ tool: string;
19
+ summary: string;
20
+ /** True when the call reaches outside the workspace (AUTO asks for these). */
21
+ outsideWorkspace?: boolean;
22
+ /** Id of the tool call this approval is about (lets the UI ignore releases
23
+ * of other calls in the same round). */
24
+ callId?: string;
25
+ /**
26
+ * The caller's per-CALL mutation verdict (`isMutatingCall`) — set for tools
27
+ * whose arguments decide it (transfer get vs put/list). The policy's plan
28
+ * check uses it instead of the name-based read-only list; omitted, it falls
29
+ * back to that list.
30
+ */
31
+ mutating?: boolean;
32
+ }
33
+ export interface ToolContext {
34
+ /** Workspace root — every relative path resolves against it. */
35
+ workspace: string;
36
+ /** Allow paths outside the workspace (--allow-outside). */
37
+ allowOutside: boolean;
38
+ /** Extra skill directories (--skills-dir). */
39
+ skillDirs: string[];
40
+ /** Aborted when the user interrupts the run (Esc / Ctrl+C). */
41
+ signal?: AbortSignal;
42
+ /** Shared todo list (local_update_todo). */
43
+ todos: TodoStore;
44
+ /** Integration API client (workspace transfers). Absent in tool unit tests. */
45
+ client?: IntegrationClient;
46
+ }
47
+ export interface ToolHandler {
48
+ definition: ToolDefinition;
49
+ /** Mutating tools require approval and are refused in plan mode. */
50
+ mutating: boolean;
51
+ /**
52
+ * Per-call override for `mutating` — for tools whose direction decides
53
+ * whether they touch the user's machine (e.g. transfer get vs put/list).
54
+ */
55
+ isMutating?: (args: Record<string, unknown>) => boolean;
56
+ /** One-line summary shown in the transcript / approval prompt. */
57
+ summarize: (args: Record<string, unknown>) => string;
58
+ /** Execute and return the text delivered to the model. */
59
+ run: (args: Record<string, unknown>, ctx: ToolContext) => Promise<string>;
60
+ }
61
+ /** Declarative spec accepted by {@link defineTool}. */
62
+ export interface ToolSpec {
63
+ name: string;
64
+ description: string;
65
+ parameters: JsonSchema;
66
+ /** Defaults to false (read-only). */
67
+ mutating?: boolean;
68
+ /** Per-call mutation override (see {@link ToolHandler.isMutating}). */
69
+ isMutating?: (args: Record<string, unknown>) => boolean;
70
+ summarize: (args: Record<string, unknown>) => string;
71
+ run: (args: Record<string, unknown>, ctx: ToolContext) => Promise<string>;
72
+ }
73
+ export declare function defineTool(spec: ToolSpec): ToolHandler;
74
+ /**
75
+ * Whether a call mutates the user's machine — the single definition behind
76
+ * plan-mode refusal, approval, replay-after-reconnect and read-only batching.
77
+ * Direction-aware tools decide per call (`isMutating`); unknown tools count as
78
+ * mutating so they serialize and are never replayed silently.
79
+ */
80
+ export declare function isMutatingCall(handler: ToolHandler | undefined, args: Record<string, unknown>): boolean;
81
+ /** Narrow an unknown argument value to a string, with a field-labelled error. */
82
+ export declare function requireString(args: Record<string, unknown>, field: string): string;
83
+ export declare function optionalString(args: Record<string, unknown>, field: string): string | undefined;
84
+ export declare function optionalNumber(args: Record<string, unknown>, field: string): number | undefined;
85
+ export declare function optionalBoolean(args: Record<string, unknown>, field: string): boolean | undefined;
@@ -0,0 +1,63 @@
1
+ // ---------------------------------------------------------------------------
2
+ // Client tool contracts.
3
+ //
4
+ // Tools execute on the user's machine (the CLI process), never on the server.
5
+ // The server receives only the JSON-schema definitions; execution results are
6
+ // sent back as tool_outputs. `mutating` drives approval and mode filtering.
7
+ // ---------------------------------------------------------------------------
8
+ export function defineTool(spec) {
9
+ return {
10
+ definition: {
11
+ type: "function",
12
+ function: { name: spec.name, description: spec.description, parameters: spec.parameters },
13
+ },
14
+ mutating: spec.mutating ?? false,
15
+ ...(spec.isMutating ? { isMutating: spec.isMutating } : {}),
16
+ summarize: spec.summarize,
17
+ run: spec.run,
18
+ };
19
+ }
20
+ /**
21
+ * Whether a call mutates the user's machine — the single definition behind
22
+ * plan-mode refusal, approval, replay-after-reconnect and read-only batching.
23
+ * Direction-aware tools decide per call (`isMutating`); unknown tools count as
24
+ * mutating so they serialize and are never replayed silently.
25
+ */
26
+ export function isMutatingCall(handler, args) {
27
+ if (!handler)
28
+ return true;
29
+ return handler.isMutating?.(args) ?? handler.mutating;
30
+ }
31
+ /** Narrow an unknown argument value to a string, with a field-labelled error. */
32
+ export function requireString(args, field) {
33
+ const value = args[field];
34
+ if (typeof value !== "string") {
35
+ throw new Error(`Invalid arguments: "${field}" must be a string.`);
36
+ }
37
+ return value;
38
+ }
39
+ export function optionalString(args, field) {
40
+ const value = args[field];
41
+ if (value === undefined || value === null)
42
+ return undefined;
43
+ if (typeof value !== "string")
44
+ throw new Error(`Invalid arguments: "${field}" must be a string.`);
45
+ return value;
46
+ }
47
+ export function optionalNumber(args, field) {
48
+ const value = args[field];
49
+ if (value === undefined || value === null)
50
+ return undefined;
51
+ if (typeof value !== "number" || !Number.isFinite(value)) {
52
+ throw new Error(`Invalid arguments: "${field}" must be a number.`);
53
+ }
54
+ return value;
55
+ }
56
+ export function optionalBoolean(args, field) {
57
+ const value = args[field];
58
+ if (value === undefined || value === null)
59
+ return undefined;
60
+ if (typeof value !== "boolean")
61
+ throw new Error(`Invalid arguments: "${field}" must be a boolean.`);
62
+ return value;
63
+ }
@@ -0,0 +1,39 @@
1
+ import type { IntegrationClient } from "../protocol/client.js";
2
+ import type { AgentUsage } from "../protocol/types.js";
3
+ import type { ToolRegistry } from "../tools/registry.js";
4
+ import type { StoredConfig } from "../config.js";
5
+ import { type AgentMode } from "../agent/modes.js";
6
+ import { SessionIndex } from "../agent/sessions.js";
7
+ import { type ApprovalMode } from "../approval/policy.js";
8
+ export interface TuiOptions {
9
+ client: IntegrationClient;
10
+ registry: ToolRegistry;
11
+ config: StoredConfig;
12
+ sessionIndex: SessionIndex;
13
+ workspace: string;
14
+ allowOutside: boolean;
15
+ skillDirs: string[];
16
+ extraInstructions?: string;
17
+ noContextFiles?: boolean;
18
+ initialMode: AgentMode;
19
+ initialApproval: ApprovalMode;
20
+ initialThinking?: string;
21
+ /** Client-choice model for new sessions (from --model). */
22
+ initialModel?: string;
23
+ /** Positional CLI prompt, submitted as the first message of the session. */
24
+ initialPrompt?: string;
25
+ resumeThreadId?: string;
26
+ noLogo?: boolean;
27
+ }
28
+ /**
29
+ * Panel width: ~25% of the terminal, floored at a readable minimum. Grows
30
+ * with wide terminals instead of being capped, so the panel keeps its share
31
+ * as the window grows (the transcript already gets the larger part).
32
+ */
33
+ export declare function sidebarWidth(columns: number): number;
34
+ export declare function runTui(opts: TuiOptions): Promise<number>;
35
+ /**
36
+ * Footer usage: `current` minus the pre-run `baseline`, so the status bar
37
+ * reports the current/last run instead of the session total.
38
+ */
39
+ export declare function runUsageDelta(current: AgentUsage | null, baseline: AgentUsage | null): AgentUsage | null;