fnloom 0.1.0 → 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.
- package/README.md +31 -18
- package/package.json +2 -7
- package/packages/build/package.json +1 -1
- package/packages/cli/package.json +1 -1
- package/packages/cli/src/commands/available.ts +63 -22
- package/packages/cli/src/commands/install.ts +86 -28
- package/packages/cli/src/index.ts +3 -2
- package/packages/cli/src/local.ts +6 -0
- package/packages/cli/src/premade.ts +80 -0
- package/packages/core/package.json +1 -1
- package/packages/hub/package.json +1 -1
- package/packages/hub/src/link/process.ts +6 -1
- package/packages/sdk/package.json +1 -1
- package/packages/web/package.json +1 -1
- package/premade/claude.zip +0 -0
- package/premade/database.zip +0 -0
- package/premade/web.zip +0 -0
- package/scripts/dev-env.ts +4 -4
- package/scripts/stack.ts +42 -27
- package/scripts/start.ts +26 -16
- package/systems/api/package.json +1 -1
- package/systems/code/package.json +1 -1
- package/systems/embedder/package.json +1 -1
- package/systems/fs/package.json +1 -1
- package/systems/google-calendar/package.json +1 -1
- package/systems/input/package.json +1 -1
- package/systems/mcp/package.json +1 -1
- package/systems/ollama/package.json +1 -1
- package/systems/schedule/package.json +1 -1
- package/systems/template/package.json +1 -1
- package/systems/widgets/package.json +1 -1
- package/systems/claude/client/FleetPage.vue +0 -132
- package/systems/claude/client/NewSessionForm.vue +0 -62
- package/systems/claude/client/SessionList.vue +0 -64
- package/systems/claude/client/SessionPage.vue +0 -199
- package/systems/claude/client/TaskList.vue +0 -61
- package/systems/claude/client/fakes.ts +0 -186
- package/systems/claude/client/host.ts +0 -23
- package/systems/claude/client/index.ts +0 -15
- package/systems/claude/client/logic.ts +0 -270
- package/systems/claude/client/state.ts +0 -344
- package/systems/claude/package.json +0 -23
- package/systems/claude/server/agent-sdk.ts +0 -379
- package/systems/claude/server/driver.ts +0 -153
- package/systems/claude/server/env.ts +0 -64
- package/systems/claude/server/fake-driver.ts +0 -112
- package/systems/claude/server/fleet.ts +0 -376
- package/systems/claude/server/impl.ts +0 -568
- package/systems/claude/server/index.ts +0 -8
- package/systems/claude/server/main.ts +0 -38
- package/systems/claude/server/preview.ts +0 -76
- package/systems/claude/server/questions.ts +0 -117
- package/systems/claude/server/transcript.ts +0 -83
- package/systems/claude/shared/index.ts +0 -262
- package/systems/claude/shared/session.ts +0 -284
- package/systems/claude/shared/shapes.ts +0 -106
- package/systems/claude/system.json +0 -18
- package/systems/claude/tsconfig.json +0 -6
- package/systems/database/package.json +0 -25
- package/systems/database/server/author.ts +0 -41
- package/systems/database/server/authoring.ts +0 -322
- package/systems/database/server/catalog.ts +0 -117
- package/systems/database/server/compile.ts +0 -332
- package/systems/database/server/dialects.ts +0 -17
- package/systems/database/server/drivers/database.ts +0 -71
- package/systems/database/server/drivers/index.ts +0 -23
- package/systems/database/server/drivers/postgres.ts +0 -157
- package/systems/database/server/drivers/sqlite.ts +0 -151
- package/systems/database/server/drivers/sqlserver.ts +0 -176
- package/systems/database/server/env.ts +0 -35
- package/systems/database/server/fixture.ts +0 -169
- package/systems/database/server/impl.ts +0 -793
- package/systems/database/server/index.ts +0 -7
- package/systems/database/server/instance.ts +0 -398
- package/systems/database/server/main.ts +0 -47
- package/systems/database/server/pick.ts +0 -97
- package/systems/database/server/queries.ts +0 -390
- package/systems/database/server/results.ts +0 -39
- package/systems/database/server/schema.ts +0 -59
- package/systems/database/server/table-fns.ts +0 -237
- package/systems/database/server/types.ts +0 -253
- package/systems/database/shared/index.ts +0 -544
- package/systems/database/shared/shapes.ts +0 -413
- package/systems/database/system.json +0 -14
- package/systems/database/tsconfig.json +0 -6
- package/systems/web/client/ReadView.vue +0 -110
- package/systems/web/client/SearchView.vue +0 -215
- package/systems/web/client/StatusChip.vue +0 -38
- package/systems/web/client/fakes.ts +0 -48
- package/systems/web/client/index.ts +0 -15
- package/systems/web/client/view.ts +0 -131
- package/systems/web/package.json +0 -22
- package/systems/web/server/chrome.ts +0 -121
- package/systems/web/server/crawl.ts +0 -333
- package/systems/web/server/env.ts +0 -63
- package/systems/web/server/guard.ts +0 -60
- package/systems/web/server/http.ts +0 -89
- package/systems/web/server/impl.ts +0 -203
- package/systems/web/server/index.ts +0 -71
- package/systems/web/server/loader.ts +0 -104
- package/systems/web/server/main.ts +0 -70
- package/systems/web/server/mentions.ts +0 -111
- package/systems/web/server/problem.ts +0 -72
- package/systems/web/server/renderer.ts +0 -243
- package/systems/web/server/robots.ts +0 -75
- package/systems/web/server/searches.ts +0 -29
- package/systems/web/server/tavily.ts +0 -144
- package/systems/web/server/testing.ts +0 -165
- package/systems/web/server/uploads.ts +0 -33
- package/systems/web/shared/index.ts +0 -343
- package/systems/web/shared/urls.ts +0 -60
- package/systems/web/system.json +0 -15
- package/systems/web/tsconfig.json +0 -6
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* What the approval cards show: a tool use Claude waits on (the command for a shell, a diff for an edit, the content
|
|
3
|
-
* for a new file, else the input as JSON), a question (its words; the form is the card's `ask`), a mode that lets Claude
|
|
4
|
-
* do more on its own, and what an import would add.
|
|
5
|
-
*/
|
|
6
|
-
import { z } from 'zod';
|
|
7
|
-
import type { ApprovalPreview, JsonObject, McpServerConfig, PreviewPart } from '@harness/core';
|
|
8
|
-
import { MODE_MEANING, type ClaudePermissionMode, type ClaudeSession } from '../shared/session.ts';
|
|
9
|
-
import type { PermitRequest, QuestionRequest } from './driver.ts';
|
|
10
|
-
|
|
11
|
-
const BashInput = z.object({ command: z.string(), description: z.string().optional() });
|
|
12
|
-
const EditInput = z.object({ file_path: z.string(), old_string: z.string(), new_string: z.string() });
|
|
13
|
-
const MultiEditInput = z.object({ file_path: z.string(), edits: z.array(z.object({ old_string: z.string(), new_string: z.string() })) });
|
|
14
|
-
const WriteInput = z.object({ file_path: z.string(), content: z.string() });
|
|
15
|
-
|
|
16
|
-
/** Text cut to `max` characters, saying how much was left out. */
|
|
17
|
-
export function clip(text: string, max: number): string {
|
|
18
|
-
return text.length <= max ? text : `${text.slice(0, max)}\n… (${String(text.length - max)} more characters)`;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/** A replacement as a diff: the old lines taken out, the new ones put in. */
|
|
22
|
-
export function replacementDiff(file: string, replacements: ReadonlyArray<{ readonly old_string: string; readonly new_string: string }>): string {
|
|
23
|
-
const hunks = replacements.map((r) => ['@@', ...r.old_string.split('\n').map((line) => `-${line}`), ...r.new_string.split('\n').map((line) => `+${line}`)].join('\n'));
|
|
24
|
-
return [`--- ${file}`, `+++ ${file}`, ...hunks].join('\n');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** What the tool would do, as the card's parts. */
|
|
28
|
-
function toolParts(tool: string, input: JsonObject, max: number): PreviewPart[] {
|
|
29
|
-
const bash = tool === 'Bash' ? BashInput.safeParse(input) : undefined;
|
|
30
|
-
if (bash?.success === true) {
|
|
31
|
-
return [...(bash.data.description === undefined ? [] : [{ type: 'text' as const, text: bash.data.description }]), { type: 'code', language: 'bash', code: clip(bash.data.command, max) }];
|
|
32
|
-
}
|
|
33
|
-
const edit = tool === 'Edit' ? EditInput.safeParse(input) : undefined;
|
|
34
|
-
if (edit?.success === true) { return [{ type: 'code', language: 'diff', title: edit.data.file_path, code: clip(replacementDiff(edit.data.file_path, [edit.data]), max) }]; }
|
|
35
|
-
const multi = tool === 'MultiEdit' ? MultiEditInput.safeParse(input) : undefined;
|
|
36
|
-
if (multi?.success === true) { return [{ type: 'code', language: 'diff', title: multi.data.file_path, code: clip(replacementDiff(multi.data.file_path, multi.data.edits), max) }]; }
|
|
37
|
-
const write = tool === 'Write' ? WriteInput.safeParse(input) : undefined;
|
|
38
|
-
if (write?.success === true) { return [{ type: 'code', language: languageOf(write.data.file_path), title: write.data.file_path, code: clip(write.data.content, max) }]; }
|
|
39
|
-
return [{ type: 'code', language: 'json', code: clip(JSON.stringify(input, null, 2), max) }];
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/** A code block language from a file's extension. */
|
|
43
|
-
function languageOf(file: string): string {
|
|
44
|
-
const dot = file.lastIndexOf('.');
|
|
45
|
-
return dot < 0 ? 'text' : file.slice(dot + 1).toLowerCase();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/** The card of a tool use Claude waits on. */
|
|
49
|
-
export function permitPreview(request: PermitRequest, max: number): ApprovalPreview {
|
|
50
|
-
const why = request.reason === undefined ? [] : [{ type: 'text' as const, text: request.reason }];
|
|
51
|
-
const always = request.canAlways ? [{ type: 'text' as const, text: 'Tick **always** to allow it for the rest of this session.' }] : [];
|
|
52
|
-
return { title: `Claude wants to use ${request.tool}`, parts: [...why, ...toolParts(request.tool, request.input, max), ...always], irreversible: false };
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** The card of a question Claude waits on. */
|
|
56
|
-
export function questionPreview(request: QuestionRequest): ApprovalPreview {
|
|
57
|
-
return { title: request.title, parts: [{ type: 'text', text: request.text }], irreversible: false };
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** The card of a mode that lets Claude do more on its own (`claude/allow_mode`): the mode, what it means, and where. */
|
|
61
|
-
export function modePreview(mode: ClaudePermissionMode, session: Pick<ClaudeSession, 'title' | 'folder'> | undefined): ApprovalPreview {
|
|
62
|
-
const where = session === undefined ? [] : [{ type: 'text' as const, text: `Session: ${session.title} (${session.folder})` }];
|
|
63
|
-
return { title: `Let Claude work in ${mode} mode?`, parts: [{ type: 'text', text: MODE_MEANING[mode] }, ...where], irreversible: false };
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** What a stdio MCP server would start: its command, args and folder, and its env names (never their values). */
|
|
67
|
-
export function mcpServerLines(server: McpServerConfig): string {
|
|
68
|
-
const transport = server.transport;
|
|
69
|
-
if (transport.type !== 'stdio') { return `${transport.type} ${transport.url}`; }
|
|
70
|
-
return [
|
|
71
|
-
`command: ${transport.command}`,
|
|
72
|
-
`args: ${transport.args.length === 0 ? '(none)' : JSON.stringify(transport.args)}`,
|
|
73
|
-
`folder: ${transport.cwd ?? '(the instance’s own)'}`,
|
|
74
|
-
`env: ${Object.keys(transport.env ?? {}).join(', ') || '(none)'}`,
|
|
75
|
-
].join('\n');
|
|
76
|
-
}
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Questions Claude asks, as forms the approval card draws (gin types) and back: the `AskUserQuestion` tool (one choice
|
|
3
|
-
* field per question; a multi-select question takes a list) and an MCP server's form elicitation (its flat schema of
|
|
4
|
-
* text, numbers, choices and yes/no fields, the only shapes the MCP spec lets a form ask for).
|
|
5
|
-
*/
|
|
6
|
-
import type { GinTypeDef, Json } from '@harness/core';
|
|
7
|
-
import { g, wireType, type GinType } from '@harness/sdk';
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
|
|
10
|
-
/** The `AskUserQuestion` tool's input, as far as the form needs it. */
|
|
11
|
-
export const AskUserQuestionInput = z.object({
|
|
12
|
-
questions: z.array(z.object({
|
|
13
|
-
question: z.string(),
|
|
14
|
-
header: z.string().optional(),
|
|
15
|
-
options: z.array(z.object({ label: z.string(), description: z.string().optional() })).min(1),
|
|
16
|
-
multiSelect: z.boolean().default(false),
|
|
17
|
-
})).min(1),
|
|
18
|
-
});
|
|
19
|
-
export type AskUserQuestionInput = z.infer<typeof AskUserQuestionInput>;
|
|
20
|
-
|
|
21
|
-
/** A question as a form, with how its value becomes the answer Claude reads. */
|
|
22
|
-
export interface QuestionForm<A> {
|
|
23
|
-
readonly title: string;
|
|
24
|
-
readonly text: string;
|
|
25
|
-
readonly form: GinTypeDef;
|
|
26
|
-
/** The form's value as Claude takes it; `undefined` when the value doesn't fit. */
|
|
27
|
-
answer(value: Json): A | undefined;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** The field a question's answer is in (`q1`, `q2`, …). */
|
|
31
|
-
const fieldOf = (index: number): string => `q${String(index + 1)}`;
|
|
32
|
-
|
|
33
|
-
/** The `AskUserQuestion` tool's questions as one form; its value becomes the tool's `answers` (question → answer). */
|
|
34
|
-
export function askUserQuestionForm(input: AskUserQuestionInput): QuestionForm<Record<string, string>> {
|
|
35
|
-
const fields: Record<string, ReturnType<typeof g.field>> = {};
|
|
36
|
-
input.questions.forEach((q, index) => {
|
|
37
|
-
const choice = g.enum(q.options.map((option) => option.label));
|
|
38
|
-
fields[fieldOf(index)] = g.field(q.multiSelect ? g.list(choice) : choice, { docs: q.question });
|
|
39
|
-
});
|
|
40
|
-
const lines = input.questions.map((q) => [
|
|
41
|
-
`**${q.header ?? q.question}**${q.header === undefined ? '' : ` ${q.question}`}`,
|
|
42
|
-
...q.options.map((option) => `- ${option.label}${option.description === undefined ? '' : `: ${option.description}`}`),
|
|
43
|
-
].join('\n'));
|
|
44
|
-
const first = input.questions[0];
|
|
45
|
-
return {
|
|
46
|
-
title: input.questions.length === 1 && first !== undefined ? `Claude asks: ${first.question}` : `Claude asks ${String(input.questions.length)} questions`,
|
|
47
|
-
text: lines.join('\n\n'),
|
|
48
|
-
form: wireType(g.obj(fields)),
|
|
49
|
-
answer(value) {
|
|
50
|
-
const given = z.record(z.string(), z.union([z.string(), z.array(z.string())])).safeParse(value);
|
|
51
|
-
if (!given.success) { return undefined; }
|
|
52
|
-
const answers: Record<string, string> = {};
|
|
53
|
-
input.questions.forEach((q, index) => {
|
|
54
|
-
const picked = given.data[fieldOf(index)];
|
|
55
|
-
if (picked !== undefined) { answers[q.question] = Array.isArray(picked) ? picked.join(', ') : picked; }
|
|
56
|
-
});
|
|
57
|
-
return answers;
|
|
58
|
-
},
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/** One property of an MCP elicitation form (the spec's primitive schema). */
|
|
63
|
-
const ElicitProperty = z.object({
|
|
64
|
-
type: z.enum(['string', 'number', 'integer', 'boolean']).optional(),
|
|
65
|
-
title: z.string().optional(),
|
|
66
|
-
description: z.string().optional(),
|
|
67
|
-
enum: z.array(z.string()).min(1).optional(),
|
|
68
|
-
minimum: z.number().optional(),
|
|
69
|
-
maximum: z.number().optional(),
|
|
70
|
-
minLength: z.number().int().optional(),
|
|
71
|
-
maxLength: z.number().int().optional(),
|
|
72
|
-
});
|
|
73
|
-
type ElicitProperty = z.infer<typeof ElicitProperty>;
|
|
74
|
-
|
|
75
|
-
/** An MCP elicitation's requested schema. */
|
|
76
|
-
export const ElicitSchema = z.object({ properties: z.record(z.string(), z.unknown()).default({}), required: z.array(z.string()).default([]) });
|
|
77
|
-
|
|
78
|
-
/** One elicitation property as a gin type; one the spec doesn't allow is taken as any value. */
|
|
79
|
-
function elicitType(property: ElicitProperty): GinType {
|
|
80
|
-
if (property.enum !== undefined) { return g.enum(property.enum); }
|
|
81
|
-
switch (property.type) {
|
|
82
|
-
case 'string': return g.text({ ...(property.minLength === undefined ? {} : { minLength: property.minLength }), ...(property.maxLength === undefined ? {} : { maxLength: property.maxLength }) });
|
|
83
|
-
case 'number':
|
|
84
|
-
case 'integer':
|
|
85
|
-
return g.num({ ...(property.type === 'integer' ? { whole: true } : {}), ...(property.minimum === undefined ? {} : { min: property.minimum }), ...(property.maximum === undefined ? {} : { max: property.maximum }) });
|
|
86
|
-
case 'boolean': return g.bool();
|
|
87
|
-
case undefined: return g.any();
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/** An elicitation's answer: the values the MCP spec lets a form give. */
|
|
92
|
-
export const ElicitContent = z.record(z.string(), z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]));
|
|
93
|
-
export type ElicitContent = z.infer<typeof ElicitContent>;
|
|
94
|
-
|
|
95
|
-
/** An MCP server's form elicitation as a form; its value is the elicitation's `content`. */
|
|
96
|
-
export function elicitationForm(server: string, message: string, schema: unknown): QuestionForm<ElicitContent> {
|
|
97
|
-
const parsed = ElicitSchema.safeParse(schema);
|
|
98
|
-
const shape = parsed.success ? parsed.data : { properties: {}, required: [] };
|
|
99
|
-
const required = new Set(shape.required);
|
|
100
|
-
const fields: Record<string, ReturnType<typeof g.field>> = {};
|
|
101
|
-
for (const [name, raw] of Object.entries(shape.properties)) {
|
|
102
|
-
const property = ElicitProperty.safeParse(raw);
|
|
103
|
-
const known: ElicitProperty = property.success ? property.data : {};
|
|
104
|
-
const type = elicitType(known);
|
|
105
|
-
const docs = [known.title, known.description].filter((part) => part !== undefined).join(': ');
|
|
106
|
-
fields[name] = g.field(required.has(name) ? type : g.optional(type), docs === '' ? {} : { docs });
|
|
107
|
-
}
|
|
108
|
-
return {
|
|
109
|
-
title: `${server} asks: ${message.split('\n')[0] ?? message}`,
|
|
110
|
-
text: message,
|
|
111
|
-
form: wireType(g.obj(fields)),
|
|
112
|
-
answer(value) {
|
|
113
|
-
const given = ElicitContent.safeParse(value);
|
|
114
|
-
return given.success ? given.data : undefined;
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
}
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Claude's stored messages as transcript items. A stored message's body is the Messages API's (`content` a string or
|
|
3
|
-
* blocks), read with zod; blocks the harness doesn't show (images, documents, redacted thinking) are left out. One
|
|
4
|
-
* message can hold several blocks: the first item keeps the message's uuid, the next ones add `#2`, `#3`, ….
|
|
5
|
-
*/
|
|
6
|
-
import { jsonOf, type Json } from '@harness/core';
|
|
7
|
-
import type { ClaudeTranscriptItem } from '../shared/session.ts';
|
|
8
|
-
import { z } from 'zod';
|
|
9
|
-
import { clip } from './preview.ts';
|
|
10
|
-
|
|
11
|
-
/** A stored message as the SDK reads it (`SessionMessage`, its body untyped). */
|
|
12
|
-
export interface StoredMessage {
|
|
13
|
-
readonly type: 'user' | 'assistant' | 'system';
|
|
14
|
-
readonly uuid: string;
|
|
15
|
-
readonly message: unknown;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const TextBlock = z.object({ type: z.literal('text'), text: z.string() });
|
|
19
|
-
const Block = z.discriminatedUnion('type', [
|
|
20
|
-
TextBlock,
|
|
21
|
-
z.object({ type: z.literal('thinking'), thinking: z.string() }),
|
|
22
|
-
z.object({ type: z.literal('tool_use'), id: z.string(), name: z.string(), input: z.unknown() }),
|
|
23
|
-
z.object({
|
|
24
|
-
type: z.literal('tool_result'), tool_use_id: z.string(), is_error: z.boolean().optional(),
|
|
25
|
-
content: z.union([z.string(), z.array(z.unknown())]).optional(),
|
|
26
|
-
}),
|
|
27
|
-
]);
|
|
28
|
-
const Body = z.object({ content: z.union([z.string(), z.array(z.unknown())]) });
|
|
29
|
-
|
|
30
|
-
/** A tool result's text: its string, or its text blocks joined. */
|
|
31
|
-
function resultText(content: string | readonly unknown[] | undefined): string {
|
|
32
|
-
if (content === undefined) { return ''; }
|
|
33
|
-
if (typeof content === 'string') { return content; }
|
|
34
|
-
return content.flatMap((block) => {
|
|
35
|
-
const text = TextBlock.safeParse(block);
|
|
36
|
-
return text.success ? [text.data.text] : [];
|
|
37
|
-
}).join('\n');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** A tool's input for the page: as it is, or cut to `max` characters of its JSON when it is longer. */
|
|
41
|
-
function inputOf(input: unknown, max: number): Json {
|
|
42
|
-
const json = jsonOf(input);
|
|
43
|
-
const text = JSON.stringify(json);
|
|
44
|
-
return text.length <= max ? json : { clipped: clip(text, max) };
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** One stored message's items. */
|
|
48
|
-
export function itemsOf(message: StoredMessage, max: number): ClaudeTranscriptItem[] {
|
|
49
|
-
const body = Body.safeParse(message.message);
|
|
50
|
-
if (!body.success) { return []; }
|
|
51
|
-
const role = message.type;
|
|
52
|
-
if (typeof body.data.content === 'string') { return [{ type: role, uuid: message.uuid, text: clip(body.data.content, max) }]; }
|
|
53
|
-
const items: ClaudeTranscriptItem[] = [];
|
|
54
|
-
for (const raw of body.data.content) {
|
|
55
|
-
const block = Block.safeParse(raw);
|
|
56
|
-
if (!block.success) { continue; }
|
|
57
|
-
const uuid = items.length === 0 ? message.uuid : `${message.uuid}#${String(items.length + 1)}`;
|
|
58
|
-
switch (block.data.type) {
|
|
59
|
-
case 'text':
|
|
60
|
-
items.push({ type: role, uuid, text: clip(block.data.text, max) });
|
|
61
|
-
break;
|
|
62
|
-
case 'thinking':
|
|
63
|
-
items.push({ type: 'thinking', uuid, text: clip(block.data.thinking, max) });
|
|
64
|
-
break;
|
|
65
|
-
case 'tool_use':
|
|
66
|
-
items.push({ type: 'tool-use', uuid, id: block.data.id, tool: block.data.name, input: inputOf(block.data.input, max) });
|
|
67
|
-
break;
|
|
68
|
-
case 'tool_result':
|
|
69
|
-
items.push({ type: 'tool-result', uuid, id: block.data.tool_use_id, ok: block.data.is_error !== true, text: clip(resultText(block.data.content), max) });
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
return items;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/** One line saying what a tool use does, for a run's progress (`Bash: npm test`, `Edit: src/cart.ts`). */
|
|
77
|
-
export function toolLine(tool: string, input: unknown, max = 120): string {
|
|
78
|
-
const fields = z.record(z.string(), z.unknown()).safeParse(input);
|
|
79
|
-
const keys = ['command', 'file_path', 'path', 'pattern', 'url', 'query', 'description', 'prompt'];
|
|
80
|
-
const value = fields.success ? keys.map((key) => fields.data[key]).find((v) => typeof v === 'string') : undefined;
|
|
81
|
-
const line = typeof value === 'string' ? `${tool}: ${value.replace(/\s+/g, ' ')}` : tool;
|
|
82
|
-
return line.length <= max ? line : `${line.slice(0, max - 1)}…`;
|
|
83
|
-
}
|
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The claude system's contract (`shared/`): a fleet of Claude Code sessions on one machine per instance, driven with
|
|
3
|
-
* the Claude Agent SDK (build-9-design.md §6 is binding; the shapes a page or another system reads are in `session.ts`).
|
|
4
|
-
*
|
|
5
|
-
* - **Sessions:** `start_session` starts one in a configured folder, `send` messages it (resuming a closed one),
|
|
6
|
-
* `control` interrupts or stops it and switches its permission mode, `transcript` reads it a page at a time from
|
|
7
|
-
* Claude's own store. Each live session is a `claude/Session` record of its person, so the fleet is listed and
|
|
8
|
-
* searched with `hub/records_*`; `disk_sessions` lists every session in Claude's store.
|
|
9
|
-
* - **Needs attention:** a tool Claude wants to use is a proposed run of `permit`, a question Claude (or an MCP server
|
|
10
|
-
* through it) asks is a proposed run of `answer` with a form; both wait for the session's person in the inbox and in
|
|
11
|
-
* the chat the session started from. Neither is ever called by the model. A mode that lets Claude do more on its own
|
|
12
|
-
* (`acceptEdits`, `auto`, `dontAsk`), asked for by `start_session` or `control`, is a proposed run of `allow_mode`
|
|
13
|
-
* for the session's person, every time (never remembered).
|
|
14
|
-
* - **Tasks and workflows** are kept on the record (`ClaudeSession.tasks`) and reported as a waiting run's progress.
|
|
15
|
-
* - **Imports:** `importables` lists Claude's agents, skills and MCP servers in a folder; `import` (an admin's
|
|
16
|
-
* approval) makes skills context with their `/command`, agents `claude/agent` fns, and MCP servers `mcp` instances.
|
|
17
|
-
*/
|
|
18
|
-
import { context, fn, ginAs, hub, kind, linear, system, type } from '@harness/sdk';
|
|
19
|
-
import {
|
|
20
|
-
CLAUDE_CONFIG_SECRETS, CLAUDE_SYSTEM, ClaudeAllowMode, ClaudeAnswer, ClaudeControl, ClaudeImport, ClaudeInstanceConfig, ClaudePermit, ClaudeSession, ClaudeSend, ClaudeStart,
|
|
21
|
-
ClaudeTranscriptPage, ClaudeTranscriptQuery, ClaudeTurn,
|
|
22
|
-
} from './session.ts';
|
|
23
|
-
import {
|
|
24
|
-
AgentPayload, AnswerOutcome, ControlOutcome, DiskSessionsPage, DiskSessionsQuery, FoldersList, FoldersQuery, ImportOutcome, ImportablesList, ImportablesQuery, ImportedSkill, PermitOutcome,
|
|
25
|
-
} from './shapes.ts';
|
|
26
|
-
|
|
27
|
-
export * from './session.ts';
|
|
28
|
-
export * from './shapes.ts';
|
|
29
|
-
|
|
30
|
-
/** The kind of an imported Claude agent's fn, qualified. */
|
|
31
|
-
export const AGENT_KIND = `${CLAUDE_SYSTEM}/agent`;
|
|
32
|
-
|
|
33
|
-
/** The claude system's pages (`/s/claude/<segment>`): the fleet, and one session (`/s/claude/session/<instance>/<session>`). */
|
|
34
|
-
export const CLAUDE_PAGES = { fleet: 'sessions', session: 'session' } as const;
|
|
35
|
-
|
|
36
|
-
/** An example session id, as the examples write it. */
|
|
37
|
-
const SESSION = '0b7c3c56-2f7e-4d2a-9d55-5c1f0f4e8a21';
|
|
38
|
-
|
|
39
|
-
const status = (active: string, done: string, failed: string) => ({
|
|
40
|
-
active: { one: active, many: active },
|
|
41
|
-
retry: { one: `${active} (again)`, many: `${active} (again)` },
|
|
42
|
-
done: { one: done, many: done },
|
|
43
|
-
failed: { one: failed, many: failed },
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
/** A live (or once live) session, mirrored as its person's record: the fleet is listed and searched in the hub. */
|
|
47
|
-
export const Session = type({
|
|
48
|
-
description: 'A Claude Code session the harness runs: its folder, status, owner, open approvals and questions, tasks and workflows, and the last thing Claude said.',
|
|
49
|
-
shape: ginAs(ClaudeSession),
|
|
50
|
-
display: { label: 'Claude session', plural: 'Claude sessions', icon: 'terminal', title: 'title', subtitle: 'folder' },
|
|
51
|
-
records: { shape: 'table', owner: 'person', search: { text: ['title', 'folder', 'lastText'], embed: false } },
|
|
52
|
-
});
|
|
53
|
-
/** An imported skill, kept so it is declared as context again after a restart. */
|
|
54
|
-
export const Skill = type({
|
|
55
|
-
description: 'A Claude skill imported as harness context, kept so it is offered again after a restart.',
|
|
56
|
-
shape: ginAs(ImportedSkill),
|
|
57
|
-
display: { label: 'Claude skill', plural: 'Claude skills', icon: 'book', title: 'name', subtitle: 'description' },
|
|
58
|
-
records: { shape: 'table', owner: 'shared', search: { text: ['name', 'description'], embed: false } },
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
/** The claude system's contract. */
|
|
62
|
-
export const claude = system(CLAUDE_SYSTEM, {
|
|
63
|
-
description: 'A fleet of Claude Code sessions: start them in folders, message them, answer what they ask, follow their tasks and workflows, and import Claude\'s agents, skills and MCP servers.',
|
|
64
|
-
about: [
|
|
65
|
-
'Claude Code: a separate coding agent that works on its own in a folder of a machine, for coding tasks that take many steps (fix a failing test, add a feature, review code). Each machine it runs on is an instance.',
|
|
66
|
-
'Its fns start a session in an allowed folder (claude/folders lists them, claude/start_session starts one), message it (claude/send), interrupt or stop it (claude/control) and read what it did (claude/transcript). A session keeps working after your turn ends; the tools it wants and the questions it asks go to the person as cards, never to you.',
|
|
67
|
-
'Its fn kind is claude/agent: a Claude agent imported with claude/import becomes a fn; running it starts a session as that agent with the task as its first message. claude/import also makes Claude skills into context with a /command, and is approved by an admin.',
|
|
68
|
-
'Reach for it to hand a whole coding task to Claude Code, not for reading or editing a file yourself (that is fs). Load its guide (claude/guide) first.',
|
|
69
|
-
].join(' '),
|
|
70
|
-
groups: [
|
|
71
|
-
{ name: 'sessions', title: 'Sessions', description: 'Start, message, interrupt and stop Claude Code sessions, and read their transcripts.' },
|
|
72
|
-
{ name: 'attention', title: 'Needs attention', description: 'The approvals and questions Claude waits on, answered by the session\'s person; never called by the model.' },
|
|
73
|
-
{ name: 'imports', title: 'Imports', description: 'Claude\'s agents, skills and MCP servers, made harness fns, context and MCP servers.' },
|
|
74
|
-
],
|
|
75
|
-
configSecrets: [...CLAUDE_CONFIG_SECRETS],
|
|
76
|
-
// sessions are person-owned records; approvals and questions are proposed runs; agents are saved as fns
|
|
77
|
-
grants: { hub: ['data', 'approvals', 'fns'], calls: ['hub/fns_save', 'hub/add_instance', 'hub/system_get'] },
|
|
78
|
-
// the fleet in the sidebar while the system is live, and one session's page reached from it (client/ draws both)
|
|
79
|
-
pages: [
|
|
80
|
-
{ segment: CLAUDE_PAGES.fleet, title: 'Claude', description: 'Your Claude Code sessions on every machine: what each is doing, and what waits on you.', icon: 'code', nav: 'main', component: 'FleetPage' },
|
|
81
|
-
{ segment: CLAUDE_PAGES.session, title: 'Claude session', description: 'One Claude Code session: its transcript, tasks and what waits on you, with a message box.', icon: 'code', nav: 'hidden', component: 'SessionPage' },
|
|
82
|
-
],
|
|
83
|
-
})
|
|
84
|
-
.with({
|
|
85
|
-
config: ginAs(ClaudeInstanceConfig),
|
|
86
|
-
types: {
|
|
87
|
-
Session,
|
|
88
|
-
Skill,
|
|
89
|
-
},
|
|
90
|
-
kinds: {
|
|
91
|
-
agent: kind({
|
|
92
|
-
description: 'An imported Claude agent (a Claude Code subagent such as a code reviewer), kept as a fn: running it starts a Claude Code session as that agent, with the task as its first message.',
|
|
93
|
-
applicability: 'A Claude subagent definition (a code reviewer, a test writer) the harness should be able to hand work to, imported by claude/import.',
|
|
94
|
-
payload: ginAs(AgentPayload),
|
|
95
|
-
// starting a session is a write on the machine: every run asks unless a policy allows it
|
|
96
|
-
approveChanges: false,
|
|
97
|
-
status: status('Starting {fn}…', 'Ran {fn}', '{fn} failed'),
|
|
98
|
-
}),
|
|
99
|
-
},
|
|
100
|
-
fns: {
|
|
101
|
-
folders: fn({
|
|
102
|
-
group: 'sessions',
|
|
103
|
-
description: 'The folders on this machine that Claude sessions may start in and imports are read from, with their labels.',
|
|
104
|
-
instructions: 'Call it before claude/start_session or claude/importables when the person has not named a folder you know is allowed: every folder given to those must be one of these or under one.',
|
|
105
|
-
args: ginAs(FoldersQuery),
|
|
106
|
-
returns: ginAs(FoldersList),
|
|
107
|
-
examples: [{ args: {}, result: { instance: 'main', folders: [{ path: 'C:/code', label: 'Code' }] }, note: 'Sessions start in C:/code or a folder under it, such as C:/code/shop.' }],
|
|
108
|
-
effects: { mode: 'read', free: true },
|
|
109
|
-
tags: ['claude', 'read'],
|
|
110
|
-
}),
|
|
111
|
-
start_session: fn({
|
|
112
|
-
group: 'sessions',
|
|
113
|
-
description: 'Start a Claude Code session in a folder with a first message; it keeps working on its own and asks the person when it needs approval or an answer. Gives the session\'s instance, id and status (and Claude\'s reply with `wait`).',
|
|
114
|
-
instructions: 'Use it to hand a coding task to Claude Code; write `prompt` as the whole task, with what done looks like, since Claude does not see this chat. `folder` must be under one of the instance\'s folders (claude/folders lists them). Leave `wait` off for long work: the session shows in the fleet and reports its tasks; set it to have this run wait for the first turn\'s answer. A `permissionMode` of acceptEdits, auto or dontAsk is asked of the person first (`modeAsked`): the session starts in default until they approve.',
|
|
115
|
-
args: ginAs(ClaudeStart),
|
|
116
|
-
returns: ginAs(ClaudeTurn),
|
|
117
|
-
progress: linear,
|
|
118
|
-
examples: [
|
|
119
|
-
{ args: { folder: 'C:/code/shop', prompt: 'Fix the failing checkout test and explain the cause.', wait: false }, result: { instance: 'main', session: SESSION, status: 'working' } },
|
|
120
|
-
{ args: { folder: 'C:/code/shop', prompt: 'List the scripts in package.json.', permissionMode: 'plan', wait: true }, note: 'A short question answered in this run.' },
|
|
121
|
-
],
|
|
122
|
-
status: status('Starting a Claude session…', 'Started a Claude session', 'Starting a Claude session failed'),
|
|
123
|
-
effects: { mode: 'write' },
|
|
124
|
-
tags: ['claude', 'write'],
|
|
125
|
-
}),
|
|
126
|
-
send: fn({
|
|
127
|
-
group: 'sessions',
|
|
128
|
-
description: 'Send a message to a Claude Code session (a closed one is resumed first).',
|
|
129
|
-
instructions: 'Use it to answer, redirect or continue a session the person names (its instance and id from claude/start_session or hub/records_find over claude/Session). With `wait` this run follows the turn (its tool uses and tasks as progress) and answers with Claude\'s reply.',
|
|
130
|
-
args: ginAs(ClaudeSend),
|
|
131
|
-
returns: ginAs(ClaudeTurn),
|
|
132
|
-
progress: linear,
|
|
133
|
-
examples: [{ args: { instance: 'main', session: SESSION, text: 'Also add a test for the empty cart.', wait: false }, result: { instance: 'main', session: SESSION, status: 'working' } }],
|
|
134
|
-
status: status('Messaging Claude…', 'Messaged Claude', 'Messaging Claude failed'),
|
|
135
|
-
effects: { mode: 'write' },
|
|
136
|
-
tags: ['claude', 'write'],
|
|
137
|
-
}),
|
|
138
|
-
control: fn({
|
|
139
|
-
group: 'sessions',
|
|
140
|
-
description: 'Interrupt a Claude Code session\'s current turn, stop the session (it stays resumable), or only switch its permission mode (`action: "mode"` with `mode`).',
|
|
141
|
-
instructions: 'Use `interrupt` when the person wants Claude to stop what it is doing now and wait; `stop` when they are done with the session; `mode` to change what Claude may do without asking (for example `plan` or `acceptEdits`) while it keeps working. acceptEdits, auto and dontAsk are asked of the person first (`modeAsked`): tell them and end your turn.',
|
|
142
|
-
args: ginAs(ClaudeControl),
|
|
143
|
-
returns: ginAs(ControlOutcome),
|
|
144
|
-
examples: [
|
|
145
|
-
{ args: { instance: 'main', session: SESSION, action: 'interrupt' }, result: { instance: 'main', session: SESSION, status: 'idle' } },
|
|
146
|
-
{ args: { instance: 'main', session: SESSION, action: 'mode', mode: 'acceptEdits' }, result: { instance: 'main', session: SESSION, status: 'working' }, note: 'Switch the mode only; the turn keeps running.' },
|
|
147
|
-
],
|
|
148
|
-
status: status('Controlling a Claude session…', 'Done', 'Controlling the session failed'),
|
|
149
|
-
effects: { mode: 'write', free: true },
|
|
150
|
-
tags: ['claude', 'write'],
|
|
151
|
-
}),
|
|
152
|
-
transcript: fn({
|
|
153
|
-
group: 'sessions',
|
|
154
|
-
description: 'Read a page of a Claude Code session\'s transcript (or one subagent\'s): what was said, thought, the tool uses and their results.',
|
|
155
|
-
instructions: 'Page with `offset` set to `next`. Name a task id as `agent` for a subagent\'s own transcript.',
|
|
156
|
-
args: ginAs(ClaudeTranscriptQuery),
|
|
157
|
-
returns: ginAs(ClaudeTranscriptPage),
|
|
158
|
-
examples: [{ args: { instance: 'main', session: SESSION, offset: 0, limit: 20 } }],
|
|
159
|
-
effects: { mode: 'read', free: true },
|
|
160
|
-
tags: ['claude', 'read'],
|
|
161
|
-
}),
|
|
162
|
-
disk_sessions: fn({
|
|
163
|
-
group: 'sessions',
|
|
164
|
-
description: 'Every Claude Code session in Claude\'s own store on this machine (also ones the harness did not start), newest first, a page at a time.',
|
|
165
|
-
instructions: 'Admins only: the store holds every session on the machine. Resume one with claude/send.',
|
|
166
|
-
args: ginAs(DiskSessionsQuery),
|
|
167
|
-
returns: ginAs(DiskSessionsPage),
|
|
168
|
-
examples: [{ args: { folder: 'C:/code/shop', offset: 0, limit: 10 } }],
|
|
169
|
-
effects: { mode: 'read', free: true },
|
|
170
|
-
tags: ['claude', 'read'],
|
|
171
|
-
}),
|
|
172
|
-
permit: fn({
|
|
173
|
-
group: 'attention',
|
|
174
|
-
description: 'Let Claude use a tool it waits on (the person\'s approval of the proposed run); a decline denies it with the reason.',
|
|
175
|
-
instructions: 'Proposed by the system for the session\'s person; the model never calls it.',
|
|
176
|
-
args: ginAs(ClaudePermit),
|
|
177
|
-
returns: ginAs(PermitOutcome),
|
|
178
|
-
examples: [{ args: { instance: 'main', session: SESSION, request: 'req_1', tool: 'Bash', input: { command: 'npm test' }, always: false } }],
|
|
179
|
-
visibility: 'none',
|
|
180
|
-
display: 'hidden',
|
|
181
|
-
status: status('Allowing {args.tool}…', 'Allowed {args.tool}', 'Allowing {args.tool} failed'),
|
|
182
|
-
effects: { mode: 'write', free: true },
|
|
183
|
-
tags: ['claude'],
|
|
184
|
-
}),
|
|
185
|
-
allow_mode: fn({
|
|
186
|
-
group: 'attention',
|
|
187
|
-
description: 'Let a Claude Code session work in a mode where it does more without asking (the person\'s approval of the proposed run).',
|
|
188
|
-
instructions: 'Proposed by the system for the session\'s person; the model never calls it.',
|
|
189
|
-
args: ginAs(ClaudeAllowMode),
|
|
190
|
-
returns: ginAs(ControlOutcome),
|
|
191
|
-
examples: [{ args: { instance: 'main', session: SESSION, mode: 'acceptEdits' } }],
|
|
192
|
-
visibility: 'none',
|
|
193
|
-
display: 'hidden',
|
|
194
|
-
// asked every time, with the mode on its card, and never remembered as a policy
|
|
195
|
-
approval: { preview: true, remember: false },
|
|
196
|
-
status: status('Switching the mode…', 'Switched the mode', 'Switching the mode failed'),
|
|
197
|
-
effects: { mode: 'write', free: true },
|
|
198
|
-
tags: ['claude'],
|
|
199
|
-
}),
|
|
200
|
-
answer: fn({
|
|
201
|
-
group: 'attention',
|
|
202
|
-
description: 'Give Claude the person\'s answer to a question it waits on (the form on the proposed run); a decline tells Claude the person did not answer.',
|
|
203
|
-
instructions: 'Proposed by the system for the session\'s person; the model never calls it.',
|
|
204
|
-
args: ginAs(ClaudeAnswer),
|
|
205
|
-
returns: ginAs(AnswerOutcome),
|
|
206
|
-
examples: [{ args: { instance: 'main', session: SESSION, request: 'req_2', from: 'question', answer: { q1: 'Postgres' } } }],
|
|
207
|
-
visibility: 'none',
|
|
208
|
-
display: 'hidden',
|
|
209
|
-
status: status('Answering Claude…', 'Answered Claude', 'Answering Claude failed'),
|
|
210
|
-
effects: { mode: 'write', free: true },
|
|
211
|
-
tags: ['claude'],
|
|
212
|
-
}),
|
|
213
|
-
importables: fn({
|
|
214
|
-
group: 'imports',
|
|
215
|
-
description: 'The agents, skills and MCP servers Claude sees in a folder (user, project and plugin scope), and whether each is imported.',
|
|
216
|
-
instructions: 'Use it before claude/import to see what there is. `folder` must be under one of the instance\'s folders (claude/folders lists them).',
|
|
217
|
-
args: ginAs(ImportablesQuery),
|
|
218
|
-
returns: ginAs(ImportablesList),
|
|
219
|
-
// the mcp system's instances say which MCP servers are imported already
|
|
220
|
-
deps: { system: hub.fns.system_get },
|
|
221
|
-
examples: [{ args: { folder: 'C:/code/shop' } }],
|
|
222
|
-
effects: { mode: 'read', free: true },
|
|
223
|
-
tags: ['claude', 'read'],
|
|
224
|
-
}),
|
|
225
|
-
import: fn({
|
|
226
|
-
group: 'imports',
|
|
227
|
-
description: 'Import some of Claude\'s agents, skills and MCP servers: skills become context with a /command, agents claude/agent fns, MCP servers mcp instances. An admin approves it.',
|
|
228
|
-
instructions: 'Name each item as claude/importables lists it (its kind, name and folder).',
|
|
229
|
-
args: ginAs(ClaudeImport),
|
|
230
|
-
returns: ginAs(ImportOutcome),
|
|
231
|
-
deps: { saveFn: hub.fns.fns_save, addInstance: hub.fns.add_instance },
|
|
232
|
-
examples: [{ args: { items: [{ kind: 'skill', name: 'release-notes', folder: 'C:/code/shop' }, { kind: 'agent', name: 'code-reviewer' }] } }],
|
|
233
|
-
// the card shows what each item is: an MCP server's command, args, folder and env names (never their values)
|
|
234
|
-
approval: { preview: true, remember: false, approver: 'admins' },
|
|
235
|
-
status: status('Importing from Claude…', 'Imported from Claude', 'Importing from Claude failed'),
|
|
236
|
-
effects: { mode: 'write', free: true, registry: [{ thing: 'fns', action: 'create', kind: AGENT_KIND }, { thing: 'context', action: 'create' }, { thing: 'fns', action: 'create' }] },
|
|
237
|
-
tags: ['claude', 'write'],
|
|
238
|
-
}),
|
|
239
|
-
},
|
|
240
|
-
})
|
|
241
|
-
.with(({ fns }) => ({
|
|
242
|
-
context: {
|
|
243
|
-
guide: context({
|
|
244
|
-
description: 'How to hand coding work to the Claude Code sessions the harness runs, follow them and read what they did.',
|
|
245
|
-
content: [
|
|
246
|
-
'Claude Code is a separate coding agent. Its sessions run on a machine (an instance of the claude system, such as `main`) in folders an admin allowed; each session is a claude/Session record of its person, listed with hub/records_find.',
|
|
247
|
-
'',
|
|
248
|
-
'To hand over a task:',
|
|
249
|
-
'1. claude/folders gives the allowed folders. The session\'s folder must be one of them or under one.',
|
|
250
|
-
'2. claude/start_session with the folder and the whole task as `prompt` (Claude does not see this chat), for example {"folder":"C:/code/shop","prompt":"Fix the failing checkout test and explain the cause.","wait":false}.',
|
|
251
|
-
'3. Tell the person it started and that it keeps working on its own. The tools Claude wants and the questions it asks come to the person as cards in the chat and their inbox: never answer them yourself.',
|
|
252
|
-
'',
|
|
253
|
-
'Later: claude/transcript reads what a session did (page with `offset`), claude/send gives it another message (a closed session is resumed), claude/control interrupts or stops it, or changes its permission mode (a mode that lets it do more on its own asks the person first).',
|
|
254
|
-
].join('\n'),
|
|
255
|
-
fns: [fns.start_session, fns.send, fns.control, fns.transcript],
|
|
256
|
-
tags: ['claude'],
|
|
257
|
-
}),
|
|
258
|
-
},
|
|
259
|
-
}));
|
|
260
|
-
|
|
261
|
-
/** The claude contract's type. */
|
|
262
|
-
export type ClaudeContract = typeof claude;
|