@goondan/openharness-base 0.1.7 → 0.1.9

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 (98) hide show
  1. package/package.json +14 -9
  2. package/dist/extensions/compaction.d.ts +0 -12
  3. package/dist/extensions/compaction.d.ts.map +0 -1
  4. package/dist/extensions/compaction.js +0 -159
  5. package/dist/extensions/compaction.js.map +0 -1
  6. package/dist/extensions/context-message.d.ts +0 -9
  7. package/dist/extensions/context-message.d.ts.map +0 -1
  8. package/dist/extensions/context-message.js +0 -446
  9. package/dist/extensions/context-message.js.map +0 -1
  10. package/dist/extensions/index.d.ts +0 -13
  11. package/dist/extensions/index.d.ts.map +0 -1
  12. package/dist/extensions/index.js +0 -7
  13. package/dist/extensions/index.js.map +0 -1
  14. package/dist/extensions/logging.d.ts +0 -11
  15. package/dist/extensions/logging.d.ts.map +0 -1
  16. package/dist/extensions/logging.js +0 -140
  17. package/dist/extensions/logging.js.map +0 -1
  18. package/dist/extensions/message-window.d.ts +0 -7
  19. package/dist/extensions/message-window.d.ts.map +0 -1
  20. package/dist/extensions/message-window.js +0 -60
  21. package/dist/extensions/message-window.js.map +0 -1
  22. package/dist/extensions/required-tools-guard.d.ts +0 -9
  23. package/dist/extensions/required-tools-guard.d.ts.map +0 -1
  24. package/dist/extensions/required-tools-guard.js +0 -74
  25. package/dist/extensions/required-tools-guard.js.map +0 -1
  26. package/dist/extensions/tool-search.d.ts +0 -10
  27. package/dist/extensions/tool-search.d.ts.map +0 -1
  28. package/dist/extensions/tool-search.js +0 -198
  29. package/dist/extensions/tool-search.js.map +0 -1
  30. package/dist/harness.yaml +0 -503
  31. package/dist/index.d.ts.map +0 -1
  32. package/dist/index.js.map +0 -1
  33. package/dist/manifests/base.d.ts +0 -8
  34. package/dist/manifests/base.d.ts.map +0 -1
  35. package/dist/manifests/base.js +0 -352
  36. package/dist/manifests/base.js.map +0 -1
  37. package/dist/manifests/index.d.ts +0 -3
  38. package/dist/manifests/index.d.ts.map +0 -1
  39. package/dist/manifests/index.js +0 -2
  40. package/dist/manifests/index.js.map +0 -1
  41. package/dist/tools/bash.d.ts +0 -8
  42. package/dist/tools/bash.d.ts.map +0 -1
  43. package/dist/tools/bash.js +0 -119
  44. package/dist/tools/bash.js.map +0 -1
  45. package/dist/tools/file-system.d.ts +0 -12
  46. package/dist/tools/file-system.d.ts.map +0 -1
  47. package/dist/tools/file-system.js +0 -117
  48. package/dist/tools/file-system.js.map +0 -1
  49. package/dist/tools/http-fetch.d.ts +0 -8
  50. package/dist/tools/http-fetch.d.ts.map +0 -1
  51. package/dist/tools/http-fetch.js +0 -149
  52. package/dist/tools/http-fetch.js.map +0 -1
  53. package/dist/tools/index.d.ts +0 -7
  54. package/dist/tools/index.d.ts.map +0 -1
  55. package/dist/tools/index.js +0 -7
  56. package/dist/tools/index.js.map +0 -1
  57. package/dist/tools/json-query.d.ts +0 -12
  58. package/dist/tools/json-query.d.ts.map +0 -1
  59. package/dist/tools/json-query.js +0 -176
  60. package/dist/tools/json-query.js.map +0 -1
  61. package/dist/tools/text-transform.d.ts +0 -16
  62. package/dist/tools/text-transform.d.ts.map +0 -1
  63. package/dist/tools/text-transform.js +0 -127
  64. package/dist/tools/text-transform.js.map +0 -1
  65. package/dist/tools/wait.d.ts +0 -6
  66. package/dist/tools/wait.d.ts.map +0 -1
  67. package/dist/tools/wait.js +0 -32
  68. package/dist/tools/wait.js.map +0 -1
  69. package/dist/types.d.ts +0 -4
  70. package/dist/types.d.ts.map +0 -1
  71. package/dist/types.js +0 -6
  72. package/dist/types.js.map +0 -1
  73. package/dist/utils.d.ts +0 -17
  74. package/dist/utils.d.ts.map +0 -1
  75. package/dist/utils.js +0 -159
  76. package/dist/utils.js.map +0 -1
  77. package/src/__tests__/basic-system-prompt.test.ts +0 -186
  78. package/src/__tests__/compaction-summarize.test.ts +0 -282
  79. package/src/__tests__/logging.test.ts +0 -200
  80. package/src/__tests__/message-window.test.ts +0 -194
  81. package/src/__tests__/required-tools-guard.test.ts +0 -207
  82. package/src/__tests__/tool-search.test.ts +0 -187
  83. package/src/__tests__/tools.test.ts +0 -332
  84. package/src/extensions/basic-system-prompt.ts +0 -48
  85. package/src/extensions/compaction-summarize.ts +0 -104
  86. package/src/extensions/logging.ts +0 -42
  87. package/src/extensions/message-window.ts +0 -23
  88. package/src/extensions/required-tools-guard.ts +0 -24
  89. package/src/extensions/tool-search.ts +0 -38
  90. package/src/index.ts +0 -16
  91. package/src/tools/bash.ts +0 -38
  92. package/src/tools/file-system.ts +0 -83
  93. package/src/tools/http-fetch.ts +0 -64
  94. package/src/tools/json-query.ts +0 -71
  95. package/src/tools/text-transform.ts +0 -59
  96. package/src/tools/wait.ts +0 -46
  97. package/tsconfig.json +0 -8
  98. package/vitest.config.ts +0 -7
@@ -1,42 +0,0 @@
1
- import type { Extension, ExtensionApi } from "@goondan/openharness-types";
2
-
3
- /**
4
- * Logging extension — subscribes to core events and logs them.
5
- */
6
- export function Logging(config?: { logger?: (msg: string) => void }): Extension {
7
- const log = config?.logger ?? console.log;
8
-
9
- return {
10
- name: "logging",
11
-
12
- register(api: ExtensionApi): void {
13
- api.on("turn.start", (payload) => {
14
- log(`[turn.start] ${JSON.stringify(payload)}`);
15
- });
16
-
17
- api.on("turn.done", (payload) => {
18
- log(`[turn.done] ${JSON.stringify(payload)}`);
19
- });
20
-
21
- api.on("turn.error", (payload) => {
22
- log(`[turn.error] ${JSON.stringify(payload)}`);
23
- });
24
-
25
- api.on("step.start", (payload) => {
26
- log(`[step.start] ${JSON.stringify(payload)}`);
27
- });
28
-
29
- api.on("step.done", (payload) => {
30
- log(`[step.done] ${JSON.stringify(payload)}`);
31
- });
32
-
33
- api.on("tool.start", (payload) => {
34
- log(`[tool.start] ${JSON.stringify(payload)}`);
35
- });
36
-
37
- api.on("tool.done", (payload) => {
38
- log(`[tool.done] ${JSON.stringify(payload)}`);
39
- });
40
- },
41
- };
42
- }
@@ -1,23 +0,0 @@
1
- import type { Extension, ExtensionApi } from "@goondan/openharness-types";
2
-
3
- /**
4
- * MessageWindow extension — truncates conversation history to keep only
5
- * the most recent `maxMessages` messages before each step.
6
- */
7
- export function MessageWindow(config: { maxMessages: number }): Extension {
8
- return {
9
- name: "message-window",
10
-
11
- register(api: ExtensionApi): void {
12
- api.pipeline.register("step", async (ctx, next) => {
13
- if (ctx.conversation.messages.length > config.maxMessages) {
14
- ctx.conversation.emit({
15
- type: "truncate",
16
- keepLast: config.maxMessages,
17
- });
18
- }
19
- return next();
20
- });
21
- },
22
- };
23
- }
@@ -1,24 +0,0 @@
1
- import type { Extension, ExtensionApi } from "@goondan/openharness-types";
2
-
3
- /**
4
- * RequiredToolsGuard extension — blocks a turn if any required tools are
5
- * not registered.
6
- */
7
- export function RequiredToolsGuard(config: { tools: string[] }): Extension {
8
- return {
9
- name: "required-tools-guard",
10
-
11
- register(api: ExtensionApi): void {
12
- api.pipeline.register("turn", async (ctx, next) => {
13
- const registered = api.tools.list().map((t) => t.name);
14
- const missing = config.tools.filter((name) => !registered.includes(name));
15
- if (missing.length > 0) {
16
- throw new Error(
17
- `RequiredToolsGuard: missing required tools: ${missing.join(", ")}`,
18
- );
19
- }
20
- return next();
21
- });
22
- },
23
- };
24
- }
@@ -1,38 +0,0 @@
1
- import type { Extension, ExtensionApi, JsonValue } from "@goondan/openharness-types";
2
-
3
- /**
4
- * ToolSearch extension — registers a meta-tool `search_tools` that searches
5
- * registered tool names and descriptions by keyword.
6
- */
7
- export function ToolSearch(): Extension {
8
- return {
9
- name: "tool-search",
10
-
11
- register(api: ExtensionApi): void {
12
- api.tools.register({
13
- name: "search_tools",
14
- description: "Search registered tools by keyword in name or description.",
15
- parameters: {
16
- type: "object",
17
- properties: {
18
- query: {
19
- type: "string",
20
- description: "Keyword to search for in tool names and descriptions.",
21
- },
22
- },
23
- required: ["query"],
24
- },
25
- handler: async (args) => {
26
- const query = (args["query"] as string).toLowerCase();
27
- const allTools = api.tools.list();
28
- const matching = allTools.filter(
29
- (t) =>
30
- t.name.toLowerCase().includes(query) ||
31
- t.description.toLowerCase().includes(query),
32
- );
33
- return { type: "json", data: matching as unknown as JsonValue };
34
- },
35
- });
36
- },
37
- };
38
- }
package/src/index.ts DELETED
@@ -1,16 +0,0 @@
1
- export { BasicSystemPrompt } from "./extensions/basic-system-prompt.js";
2
- export { MessageWindow } from "./extensions/message-window.js";
3
- export { CompactionSummarize } from "./extensions/compaction-summarize.js";
4
- export { Logging } from "./extensions/logging.js";
5
- export { ToolSearch } from "./extensions/tool-search.js";
6
- export { RequiredToolsGuard } from "./extensions/required-tools-guard.js";
7
-
8
- // Tools
9
- export { BashTool } from "./tools/bash.js";
10
- export type { BashToolConfig } from "./tools/bash.js";
11
- export { FileReadTool, FileWriteTool, FileListTool } from "./tools/file-system.js";
12
- export { HttpFetchTool } from "./tools/http-fetch.js";
13
- export { JsonQueryTool } from "./tools/json-query.js";
14
- export { TextTransformTool } from "./tools/text-transform.js";
15
- export { WaitTool } from "./tools/wait.js";
16
- export type { WaitToolConfig } from "./tools/wait.js";
package/src/tools/bash.ts DELETED
@@ -1,38 +0,0 @@
1
- import { exec } from "node:child_process";
2
- import type { ToolDefinition, JsonObject, ToolContext } from "@goondan/openharness-types";
3
-
4
- export interface BashToolConfig {
5
- timeout?: number;
6
- maxBuffer?: number;
7
- }
8
-
9
- export function BashTool(config: BashToolConfig = {}): ToolDefinition {
10
- const { timeout = 30_000, maxBuffer = 1024 * 1024 } = config;
11
-
12
- return {
13
- name: "bash",
14
- description: "Execute a shell command and return its output.",
15
- parameters: {
16
- type: "object",
17
- properties: {
18
- command: { type: "string", description: "The shell command to execute." },
19
- cwd: { type: "string", description: "Optional working directory for the command." },
20
- },
21
- required: ["command"],
22
- },
23
- async handler(args: JsonObject, _ctx: ToolContext) {
24
- const command = args["command"] as string;
25
- const cwd = args["cwd"] as string | undefined;
26
-
27
- return new Promise((resolve) => {
28
- exec(command, { timeout, maxBuffer, cwd }, (error, stdout, stderr) => {
29
- if (error) {
30
- resolve({ type: "error", error: stderr || error.message });
31
- } else {
32
- resolve({ type: "text", text: stdout });
33
- }
34
- });
35
- });
36
- },
37
- };
38
- }
@@ -1,83 +0,0 @@
1
- import { readFile, writeFile, readdir } from "node:fs/promises";
2
- import type { ToolDefinition, JsonObject, ToolContext } from "@goondan/openharness-types";
3
-
4
- export function FileReadTool(): ToolDefinition {
5
- return {
6
- name: "file_read",
7
- description: "Read the contents of a file.",
8
- parameters: {
9
- type: "object",
10
- properties: {
11
- path: { type: "string", description: "Absolute or relative path to the file to read." },
12
- encoding: {
13
- type: "string",
14
- enum: ["utf8", "base64"],
15
- description: "File encoding. Defaults to utf8.",
16
- },
17
- },
18
- required: ["path"],
19
- },
20
- async handler(args: JsonObject, _ctx: ToolContext) {
21
- const filePath = args["path"] as string;
22
- const encoding = (args["encoding"] as BufferEncoding | undefined) ?? "utf8";
23
- try {
24
- const content = await readFile(filePath, { encoding });
25
- return { type: "text", text: content };
26
- } catch (err) {
27
- return { type: "error", error: (err as Error).message };
28
- }
29
- },
30
- };
31
- }
32
-
33
- export function FileWriteTool(): ToolDefinition {
34
- return {
35
- name: "file_write",
36
- description: "Write content to a file, creating or overwriting it.",
37
- parameters: {
38
- type: "object",
39
- properties: {
40
- path: { type: "string", description: "Absolute or relative path to the file to write." },
41
- content: { type: "string", description: "The content to write to the file." },
42
- },
43
- required: ["path", "content"],
44
- },
45
- async handler(args: JsonObject, _ctx: ToolContext) {
46
- const filePath = args["path"] as string;
47
- const content = args["content"] as string;
48
- try {
49
- await writeFile(filePath, content, "utf8");
50
- return { type: "text", text: `File written: ${filePath}` };
51
- } catch (err) {
52
- return { type: "error", error: (err as Error).message };
53
- }
54
- },
55
- };
56
- }
57
-
58
- export function FileListTool(): ToolDefinition {
59
- return {
60
- name: "file_list",
61
- description: "List files and directories in a given directory.",
62
- parameters: {
63
- type: "object",
64
- properties: {
65
- path: { type: "string", description: "Absolute or relative path to the directory to list." },
66
- },
67
- required: ["path"],
68
- },
69
- async handler(args: JsonObject, _ctx: ToolContext) {
70
- const dirPath = args["path"] as string;
71
- try {
72
- const entries = await readdir(dirPath, { withFileTypes: true });
73
- const result = entries.map((e) => ({
74
- name: e.name,
75
- type: e.isDirectory() ? "directory" : "file",
76
- }));
77
- return { type: "json", data: result };
78
- } catch (err) {
79
- return { type: "error", error: (err as Error).message };
80
- }
81
- },
82
- };
83
- }
@@ -1,64 +0,0 @@
1
- import type { ToolDefinition, JsonObject, ToolContext, JsonValue } from "@goondan/openharness-types";
2
-
3
- export function HttpFetchTool(): ToolDefinition {
4
- return {
5
- name: "http_fetch",
6
- description: "Perform an HTTP request and return the response.",
7
- parameters: {
8
- type: "object",
9
- properties: {
10
- url: { type: "string", description: "The URL to fetch." },
11
- method: {
12
- type: "string",
13
- enum: ["GET", "POST", "PUT", "PATCH", "DELETE", "HEAD"],
14
- description: "HTTP method. Defaults to GET.",
15
- },
16
- headers: {
17
- type: "object",
18
- additionalProperties: { type: "string" },
19
- description: "Optional request headers.",
20
- },
21
- body: { type: "string", description: "Optional request body." },
22
- },
23
- required: ["url"],
24
- },
25
- async handler(args: JsonObject, _ctx: ToolContext) {
26
- const url = args["url"] as string;
27
- const method = (args["method"] as string | undefined) ?? "GET";
28
- const headers = (args["headers"] as Record<string, string> | undefined) ?? {};
29
- const body = args["body"] as string | undefined;
30
-
31
- try {
32
- const response = await fetch(url, {
33
- method,
34
- headers,
35
- body: body !== undefined ? body : undefined,
36
- });
37
-
38
- const responseHeaders: Record<string, string> = {};
39
- response.headers.forEach((value, key) => {
40
- responseHeaders[key] = value;
41
- });
42
-
43
- let responseBody: unknown;
44
- const contentType = response.headers.get("content-type") ?? "";
45
- if (contentType.includes("application/json")) {
46
- responseBody = await response.json();
47
- } else {
48
- responseBody = await response.text();
49
- }
50
-
51
- return {
52
- type: "json",
53
- data: {
54
- status: response.status,
55
- headers: responseHeaders,
56
- body: responseBody as JsonValue,
57
- },
58
- };
59
- } catch (err) {
60
- return { type: "error", error: (err as Error).message };
61
- }
62
- },
63
- };
64
- }
@@ -1,71 +0,0 @@
1
- import type { ToolDefinition, JsonObject, ToolContext, JsonValue } from "@goondan/openharness-types";
2
-
3
- /**
4
- * Simple JSONPath-like query supporting dot and bracket notation.
5
- * Supported path format: $.key.nested[0].field
6
- * The leading `$` is optional.
7
- */
8
- function jsonQuery(data: unknown, path: string): unknown {
9
- // Normalize: strip leading `$` or `$.`
10
- let normalized = path.trim();
11
- if (normalized.startsWith("$.")) {
12
- normalized = normalized.slice(2);
13
- } else if (normalized === "$") {
14
- return data;
15
- } else if (normalized.startsWith("$")) {
16
- normalized = normalized.slice(1);
17
- }
18
-
19
- if (normalized === "" || normalized === ".") {
20
- return data;
21
- }
22
-
23
- // Tokenize path into segments
24
- const segments: Array<string | number> = [];
25
- // Replace bracket notation [0] with .0
26
- const normalized2 = normalized.replace(/\[(\d+)\]/g, ".$1").replace(/\[['"](.+?)['"]\]/g, ".$1");
27
- for (const part of normalized2.split(".")) {
28
- if (part === "") continue;
29
- const num = Number(part);
30
- segments.push(Number.isInteger(num) && String(num) === part ? num : part);
31
- }
32
-
33
- let current: unknown = data;
34
- for (const segment of segments) {
35
- if (current === null || current === undefined) return undefined;
36
- if (typeof current === "object") {
37
- current = (current as Record<string | number, unknown>)[segment];
38
- } else {
39
- return undefined;
40
- }
41
- }
42
- return current;
43
- }
44
-
45
- export function JsonQueryTool(): ToolDefinition {
46
- return {
47
- name: "json_query",
48
- description: "Query JSON data using a simple JSONPath-like path expression.",
49
- parameters: {
50
- type: "object",
51
- properties: {
52
- data: { description: "The JSON data to query." },
53
- path: {
54
- type: "string",
55
- description: "JSONPath-like path, e.g. $.key.nested[0].field",
56
- },
57
- },
58
- required: ["data", "path"],
59
- },
60
- async handler(args: JsonObject, _ctx: ToolContext) {
61
- const data = args["data"];
62
- const path = args["path"] as string;
63
- try {
64
- const result = jsonQuery(data, path);
65
- return { type: "json", data: result as JsonValue };
66
- } catch (err) {
67
- return { type: "error", error: (err as Error).message };
68
- }
69
- },
70
- };
71
- }
@@ -1,59 +0,0 @@
1
- import type { ToolDefinition, JsonObject, ToolContext } from "@goondan/openharness-types";
2
-
3
- type Operation = "uppercase" | "lowercase" | "trim" | "split" | "replace";
4
-
5
- export function TextTransformTool(): ToolDefinition {
6
- return {
7
- name: "text_transform",
8
- description: "Apply a transformation operation to a text string.",
9
- parameters: {
10
- type: "object",
11
- properties: {
12
- text: { type: "string", description: "The input text to transform." },
13
- operation: {
14
- type: "string",
15
- enum: ["uppercase", "lowercase", "trim", "split", "replace"],
16
- description: "The transformation to apply.",
17
- },
18
- options: {
19
- type: "object",
20
- properties: {
21
- delimiter: { type: "string", description: "Delimiter for split operation." },
22
- find: { type: "string", description: "String to find for replace operation." },
23
- replacement: { type: "string", description: "Replacement string for replace operation." },
24
- },
25
- },
26
- },
27
- required: ["text", "operation"],
28
- },
29
- async handler(args: JsonObject, _ctx: ToolContext) {
30
- const text = args["text"] as string;
31
- const operation = args["operation"] as Operation;
32
- const options = (args["options"] as Record<string, string> | undefined) ?? {};
33
-
34
- try {
35
- switch (operation) {
36
- case "uppercase":
37
- return { type: "text", text: text.toUpperCase() };
38
- case "lowercase":
39
- return { type: "text", text: text.toLowerCase() };
40
- case "trim":
41
- return { type: "text", text: text.trim() };
42
- case "split": {
43
- const delimiter = options["delimiter"] ?? " ";
44
- return { type: "json", data: text.split(delimiter) };
45
- }
46
- case "replace": {
47
- const find = options["find"] ?? "";
48
- const replacement = options["replacement"] ?? "";
49
- return { type: "text", text: text.split(find).join(replacement) };
50
- }
51
- default:
52
- return { type: "error", error: `Unknown operation: ${operation}` };
53
- }
54
- } catch (err) {
55
- return { type: "error", error: (err as Error).message };
56
- }
57
- },
58
- };
59
- }
package/src/tools/wait.ts DELETED
@@ -1,46 +0,0 @@
1
- import type { ToolDefinition, JsonObject, ToolContext } from "@goondan/openharness-types";
2
-
3
- export interface WaitToolConfig {
4
- maxMs?: number;
5
- }
6
-
7
- export function WaitTool(config: WaitToolConfig = {}): ToolDefinition {
8
- const { maxMs = 60_000 } = config;
9
-
10
- return {
11
- name: "wait",
12
- description: "Wait for a specified number of milliseconds before continuing.",
13
- parameters: {
14
- type: "object",
15
- properties: {
16
- ms: {
17
- type: "number",
18
- description: "Number of milliseconds to wait.",
19
- minimum: 0,
20
- },
21
- },
22
- required: ["ms"],
23
- },
24
- async handler(args: JsonObject, ctx: ToolContext) {
25
- const requestedMs = args["ms"] as number;
26
- const ms = Math.min(requestedMs, maxMs);
27
-
28
- await new Promise<void>((resolve, reject) => {
29
- const timer = setTimeout(resolve, ms);
30
-
31
- if (ctx.abortSignal.aborted) {
32
- clearTimeout(timer);
33
- reject(new Error("Aborted"));
34
- return;
35
- }
36
-
37
- ctx.abortSignal.addEventListener("abort", () => {
38
- clearTimeout(timer);
39
- reject(new Error("Aborted"));
40
- });
41
- });
42
-
43
- return { type: "text", text: `Waited ${ms}ms` };
44
- },
45
- };
46
- }
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "outDir": "dist",
5
- "rootDir": "src"
6
- },
7
- "include": ["src"]
8
- }
package/vitest.config.ts DELETED
@@ -1,7 +0,0 @@
1
- import { defineConfig } from "vitest/config";
2
-
3
- export default defineConfig({
4
- test: {
5
- include: ["src/**/*.test.ts"],
6
- },
7
- });