opencode-subagent-tools 0.1.0 → 0.2.1
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/CHANGELOG.md +36 -0
- package/README.md +23 -18
- package/SECURITY.md +1 -1
- package/SKILL.md +60 -20
- package/docs/development.md +14 -10
- package/docs/installation.md +1 -7
- package/docs/limitations.md +45 -9
- package/docs/reference.md +83 -32
- package/package.json +5 -5
- package/src/access.ts +79 -79
- package/src/background.ts +602 -0
- package/src/config.ts +47 -47
- package/src/cursor.ts +41 -39
- package/src/discovery.ts +77 -69
- package/src/errors.ts +7 -7
- package/src/events.ts +141 -95
- package/src/format.ts +20 -20
- package/src/index.ts +49 -36
- package/src/interrupt.ts +4 -4
- package/src/live-state.ts +64 -41
- package/src/messages.ts +134 -84
- package/src/permissions.ts +18 -18
- package/src/session-row.ts +82 -21
- package/src/session.ts +69 -69
- package/src/skill.ts +24 -24
- package/src/status.ts +64 -64
- package/src/text.ts +16 -16
- package/src/tokens.ts +51 -51
- package/src/tools/cancel-descendants.ts +303 -170
- package/src/tools/cancel.ts +139 -73
- package/src/tools/index.ts +32 -30
- package/src/tools/input.ts +46 -44
- package/src/tools/list.ts +281 -175
- package/src/tools/names.ts +2 -2
- package/src/tools/output.ts +51 -51
- package/src/tools/send.ts +130 -96
- package/src/tools/usage.ts +181 -143
package/src/tools/names.ts
CHANGED
package/src/tools/output.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
|
-
import type { JsonSchema } from "effect"
|
|
2
|
-
import { OUTPUT_FORMAT, normalizeOutputFormats, type OutputFormat } from "../config"
|
|
3
|
-
import { TOOL, type ToolName } from "./names"
|
|
1
|
+
import type { JsonSchema } from "effect";
|
|
2
|
+
import { OUTPUT_FORMAT, normalizeOutputFormats, type OutputFormat } from "../config";
|
|
3
|
+
import { TOOL, type ToolName } from "./names";
|
|
4
4
|
|
|
5
5
|
export interface OutputResult {
|
|
6
|
-
readonly content: string
|
|
7
|
-
readonly output?: unknown
|
|
6
|
+
readonly content: string;
|
|
7
|
+
readonly output?: unknown;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export interface OutputFormatProperty {
|
|
11
11
|
readonly format?: {
|
|
12
|
-
readonly type: "string"
|
|
13
|
-
readonly enum: readonly OutputFormat[]
|
|
14
|
-
readonly description: string
|
|
15
|
-
}
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
readonly enum: readonly OutputFormat[];
|
|
14
|
+
readonly description: string;
|
|
15
|
+
};
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
type ResponseFactory = (content: string, output: unknown) => OutputResult
|
|
18
|
+
type ResponseFactory = (content: string, output: unknown) => OutputResult;
|
|
19
19
|
|
|
20
20
|
interface FormatHandler {
|
|
21
21
|
/** Response when this format is the only allowed one. */
|
|
22
|
-
readonly solo: ResponseFactory
|
|
22
|
+
readonly solo: ResponseFactory;
|
|
23
23
|
/** Response when this format is selected among several allowed formats. */
|
|
24
|
-
readonly combined: ResponseFactory
|
|
24
|
+
readonly combined: ResponseFactory;
|
|
25
25
|
/** Output schema when this format is the only allowed one. */
|
|
26
26
|
readonly soloSchema: (
|
|
27
27
|
schema: JsonSchema.JsonSchema,
|
|
28
|
-
) => JsonSchema.JsonSchema | undefined
|
|
28
|
+
) => JsonSchema.JsonSchema | undefined;
|
|
29
29
|
/** Output schema contribution when several formats are allowed. */
|
|
30
|
-
readonly combinedSchema: (schema: JsonSchema.JsonSchema) => JsonSchema.JsonSchema
|
|
30
|
+
readonly combinedSchema: (schema: JsonSchema.JsonSchema) => JsonSchema.JsonSchema;
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
const TEXT_HANDLER: FormatHandler = {
|
|
@@ -35,41 +35,41 @@ const TEXT_HANDLER: FormatHandler = {
|
|
|
35
35
|
combined: (content) => ({ content, output: content }),
|
|
36
36
|
soloSchema: () => undefined,
|
|
37
37
|
combinedSchema: () => ({ type: "string" }),
|
|
38
|
-
}
|
|
38
|
+
};
|
|
39
39
|
|
|
40
40
|
const JSON_HANDLER: FormatHandler = {
|
|
41
41
|
solo: (content, output) => ({ content, output }),
|
|
42
42
|
combined: (content, output) => ({ content, output }),
|
|
43
43
|
soloSchema: (schema) => schema,
|
|
44
44
|
combinedSchema: (schema) => schema,
|
|
45
|
-
}
|
|
45
|
+
};
|
|
46
46
|
|
|
47
47
|
const FORMAT_HANDLERS: Readonly<Record<OutputFormat, FormatHandler>> = {
|
|
48
48
|
[OUTPUT_FORMAT.text]: TEXT_HANDLER,
|
|
49
49
|
[OUTPUT_FORMAT.json]: JSON_HANDLER,
|
|
50
|
-
}
|
|
50
|
+
};
|
|
51
51
|
|
|
52
52
|
const FORMAT_HANDLER_MAP: ReadonlyMap<OutputFormat, FormatHandler> = new Map(
|
|
53
53
|
Object.entries(FORMAT_HANDLERS) as Array<[OutputFormat, FormatHandler]>,
|
|
54
|
-
)
|
|
54
|
+
);
|
|
55
55
|
|
|
56
56
|
export interface OutputStrategy {
|
|
57
57
|
/** Formats this strategy accepts, in canonical order. */
|
|
58
|
-
readonly formats: readonly OutputFormat[]
|
|
58
|
+
readonly formats: readonly OutputFormat[];
|
|
59
59
|
/** The effective default when format is omitted or invalid. */
|
|
60
|
-
readonly defaultFormat: OutputFormat
|
|
60
|
+
readonly defaultFormat: OutputFormat;
|
|
61
61
|
/** The per-call format input property, or an empty object when there is no choice. */
|
|
62
|
-
readonly formatProperty: (description: string) => OutputFormatProperty
|
|
62
|
+
readonly formatProperty: (description: string) => OutputFormatProperty;
|
|
63
63
|
/** The tool output schema, or undefined when output is text-only. */
|
|
64
|
-
readonly schema: (schema: JsonSchema.JsonSchema) => JsonSchema.JsonSchema | undefined
|
|
64
|
+
readonly schema: (schema: JsonSchema.JsonSchema) => JsonSchema.JsonSchema | undefined;
|
|
65
65
|
/** Resolve the effective format for this call. */
|
|
66
|
-
readonly selectFormat: (requested: unknown) => OutputFormat
|
|
66
|
+
readonly selectFormat: (requested: unknown) => OutputFormat;
|
|
67
67
|
/** Build the tool result for the selected format. */
|
|
68
68
|
readonly respond: (
|
|
69
69
|
content: string,
|
|
70
70
|
output: unknown,
|
|
71
71
|
format: OutputFormat,
|
|
72
|
-
) => OutputResult
|
|
72
|
+
) => OutputResult;
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
export const TOOL_FORMAT_DEFAULTS: Readonly<Record<ToolName, OutputFormat>> = {
|
|
@@ -80,19 +80,19 @@ export const TOOL_FORMAT_DEFAULTS: Readonly<Record<ToolName, OutputFormat>> = {
|
|
|
80
80
|
[TOOL.steer]: OUTPUT_FORMAT.text,
|
|
81
81
|
[TOOL.queue]: OUTPUT_FORMAT.text,
|
|
82
82
|
[TOOL.context]: OUTPUT_FORMAT.text,
|
|
83
|
-
}
|
|
83
|
+
};
|
|
84
84
|
|
|
85
85
|
const TOOL_FORMAT_DEFAULT_MAP: ReadonlyMap<ToolName, OutputFormat> = new Map(
|
|
86
86
|
Object.entries(TOOL_FORMAT_DEFAULTS) as Array<[ToolName, OutputFormat]>,
|
|
87
|
-
)
|
|
87
|
+
);
|
|
88
88
|
|
|
89
|
-
const NO_FORMAT_PROPERTY = (): OutputFormatProperty => ({})
|
|
89
|
+
const NO_FORMAT_PROPERTY = (): OutputFormatProperty => ({});
|
|
90
90
|
|
|
91
91
|
const handlerFor = (format: OutputFormat): FormatHandler => {
|
|
92
|
-
const handler = FORMAT_HANDLER_MAP.get(format)
|
|
93
|
-
if (!handler) throw new Error(`Unsupported output format: ${format}`)
|
|
94
|
-
return handler
|
|
95
|
-
}
|
|
92
|
+
const handler = FORMAT_HANDLER_MAP.get(format);
|
|
93
|
+
if (!handler) throw new Error(`Unsupported output format: ${format}`);
|
|
94
|
+
return handler;
|
|
95
|
+
};
|
|
96
96
|
|
|
97
97
|
export const resolveOutputStrategy = (
|
|
98
98
|
allowedOutputFormats: readonly OutputFormat[],
|
|
@@ -100,13 +100,13 @@ export const resolveOutputStrategy = (
|
|
|
100
100
|
): OutputStrategy => {
|
|
101
101
|
// Invalid and empty inputs fall back to the default set. The config layer
|
|
102
102
|
// uses the same normalizer, so a malformed option cannot widen the surface.
|
|
103
|
-
const formats = normalizeOutputFormats(allowedOutputFormats)
|
|
104
|
-
const handlers = formats.map(handlerFor)
|
|
105
|
-
const defaultFormat = formats.includes(preferredFormat) ? preferredFormat : formats[0]
|
|
103
|
+
const formats = normalizeOutputFormats(allowedOutputFormats);
|
|
104
|
+
const handlers = formats.map(handlerFor);
|
|
105
|
+
const defaultFormat = formats.includes(preferredFormat) ? preferredFormat : formats[0];
|
|
106
106
|
|
|
107
107
|
if (formats.length === 1) {
|
|
108
|
-
const format = formats[0]
|
|
109
|
-
const handler = handlers[0]
|
|
108
|
+
const format = formats[0];
|
|
109
|
+
const handler = handlers[0];
|
|
110
110
|
return {
|
|
111
111
|
formats,
|
|
112
112
|
defaultFormat,
|
|
@@ -114,12 +114,12 @@ export const resolveOutputStrategy = (
|
|
|
114
114
|
schema: handler.soloSchema,
|
|
115
115
|
selectFormat: () => format,
|
|
116
116
|
respond: (content, output) => handler.solo(content, output),
|
|
117
|
-
}
|
|
117
|
+
};
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
const handlerByFormat = new Map(
|
|
121
121
|
formats.map((format, index) => [format, handlers[index]] as const),
|
|
122
|
-
)
|
|
122
|
+
);
|
|
123
123
|
|
|
124
124
|
return {
|
|
125
125
|
formats,
|
|
@@ -139,31 +139,31 @@ export const resolveOutputStrategy = (
|
|
|
139
139
|
? (requested as OutputFormat)
|
|
140
140
|
: defaultFormat,
|
|
141
141
|
respond: (content, output, format) => {
|
|
142
|
-
const handler = handlerByFormat.get(format)
|
|
143
|
-
if (!handler) throw new Error(`Unsupported output format: ${format}`)
|
|
144
|
-
return handler.combined(content, output)
|
|
142
|
+
const handler = handlerByFormat.get(format);
|
|
143
|
+
if (!handler) throw new Error(`Unsupported output format: ${format}`);
|
|
144
|
+
return handler.combined(content, output);
|
|
145
145
|
},
|
|
146
|
-
}
|
|
147
|
-
}
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
148
|
|
|
149
149
|
export const resolveToolOutputStrategy = (
|
|
150
150
|
allowedOutputFormats: readonly OutputFormat[],
|
|
151
151
|
tool: ToolName,
|
|
152
152
|
): OutputStrategy => {
|
|
153
|
-
const preferred = TOOL_FORMAT_DEFAULT_MAP.get(tool)
|
|
154
|
-
if (!preferred) throw new Error(`Unsupported tool: ${String(tool)}`)
|
|
155
|
-
return resolveOutputStrategy(allowedOutputFormats, preferred)
|
|
156
|
-
}
|
|
153
|
+
const preferred = TOOL_FORMAT_DEFAULT_MAP.get(tool);
|
|
154
|
+
if (!preferred) throw new Error(`Unsupported tool: ${String(tool)}`);
|
|
155
|
+
return resolveOutputStrategy(allowedOutputFormats, preferred);
|
|
156
|
+
};
|
|
157
157
|
|
|
158
158
|
export const otherOutputFormat = (strategy: OutputStrategy): OutputFormat | undefined =>
|
|
159
|
-
strategy.formats.find((format) => format !== strategy.defaultFormat)
|
|
159
|
+
strategy.formats.find((format) => format !== strategy.defaultFormat);
|
|
160
160
|
|
|
161
161
|
export const formatPropertyDescription = (
|
|
162
162
|
strategy: OutputStrategy,
|
|
163
163
|
otherHint: string,
|
|
164
164
|
): string => {
|
|
165
|
-
const other = otherOutputFormat(strategy)
|
|
165
|
+
const other = otherOutputFormat(strategy);
|
|
166
166
|
return other
|
|
167
167
|
? `Response format. Defaults to ${strategy.defaultFormat}; use ${other} for ${otherHint}.`
|
|
168
|
-
: `Response format. Defaults to ${strategy.defaultFormat}
|
|
169
|
-
}
|
|
168
|
+
: `Response format. Defaults to ${strategy.defaultFormat}.`;
|
|
169
|
+
};
|
package/src/tools/send.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import type { ToolEditor } from "@opencode/plugin/promise/tool"
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
1
|
+
import type { ToolEditor } from "@opencode/plugin/promise/tool";
|
|
2
|
+
import { BACKGROUND_JOB_SCHEMA } from "../background";
|
|
3
|
+
import type { Config } from "../config";
|
|
4
|
+
import { toolError } from "../errors";
|
|
4
5
|
import {
|
|
5
6
|
CONTEXT_DELIVERY,
|
|
7
|
+
CONTEXT_METADATA_SOURCE,
|
|
6
8
|
DELIVERY,
|
|
7
9
|
SEND_KIND,
|
|
8
10
|
SendAdmissionError,
|
|
@@ -10,62 +12,84 @@ import {
|
|
|
10
12
|
type Delivery,
|
|
11
13
|
type SendMessage,
|
|
12
14
|
type SendResultFields,
|
|
13
|
-
} from "../messages"
|
|
14
|
-
import {
|
|
15
|
-
import { maxLengthError, textLength } from "../text"
|
|
15
|
+
} from "../messages";
|
|
16
|
+
import { RUN_STATUSES } from "../status";
|
|
17
|
+
import { maxLengthError, textLength } from "../text";
|
|
16
18
|
import {
|
|
17
19
|
MAX_DESCRIPTION_LENGTH,
|
|
18
20
|
readTextField,
|
|
19
21
|
readToolInput,
|
|
20
22
|
requireSessionID,
|
|
21
23
|
requireText,
|
|
22
|
-
} from "./input"
|
|
23
|
-
import { TOOL } from "./names"
|
|
24
|
+
} from "./input";
|
|
25
|
+
import { TOOL } from "./names";
|
|
24
26
|
import {
|
|
25
27
|
formatPropertyDescription,
|
|
26
28
|
resolveToolOutputStrategy,
|
|
27
29
|
type OutputStrategy,
|
|
28
|
-
} from "./output"
|
|
30
|
+
} from "./output";
|
|
29
31
|
|
|
30
32
|
export interface SendOutput extends SendResultFields {
|
|
31
|
-
sessionID: string
|
|
32
|
-
delivery: Delivery
|
|
33
|
-
chars: number
|
|
34
|
-
resume: boolean
|
|
33
|
+
sessionID: string;
|
|
34
|
+
delivery: Delivery;
|
|
35
|
+
chars: number;
|
|
36
|
+
resume: boolean;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
export interface ContextOutput extends SendResultFields {
|
|
38
|
-
sessionID: string
|
|
39
|
-
delivery: typeof CONTEXT_DELIVERY
|
|
40
|
-
chars: number
|
|
41
|
-
description?: string
|
|
40
|
+
sessionID: string;
|
|
41
|
+
delivery: typeof CONTEXT_DELIVERY;
|
|
42
|
+
chars: number;
|
|
43
|
+
description?: string;
|
|
42
44
|
}
|
|
43
45
|
|
|
46
|
+
const SEND_OUTPUT_PROPERTIES = {
|
|
47
|
+
sessionID: { type: "string" },
|
|
48
|
+
messageID: { type: "string" },
|
|
49
|
+
delivery: { type: "string", enum: Object.values(DELIVERY) },
|
|
50
|
+
chars: { type: "integer" },
|
|
51
|
+
resume: {
|
|
52
|
+
type: "boolean",
|
|
53
|
+
description: "Whether the message could wake an idle child.",
|
|
54
|
+
},
|
|
55
|
+
status: {
|
|
56
|
+
type: "string",
|
|
57
|
+
enum: [...RUN_STATUSES],
|
|
58
|
+
description:
|
|
59
|
+
"Status observed before the message was accepted; a wake may not be reflected yet.",
|
|
60
|
+
},
|
|
61
|
+
active: {
|
|
62
|
+
type: "boolean",
|
|
63
|
+
description:
|
|
64
|
+
"True when the target was running, unknown, or owned a background job when observed.",
|
|
65
|
+
},
|
|
66
|
+
backgroundJob: BACKGROUND_JOB_SCHEMA,
|
|
67
|
+
pending: {
|
|
68
|
+
type: "boolean",
|
|
69
|
+
description: "True when the message was accepted without waking an idle child.",
|
|
70
|
+
},
|
|
71
|
+
} as const;
|
|
72
|
+
|
|
44
73
|
const SEND_OUTPUT_SCHEMA = {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: SEND_OUTPUT_PROPERTIES,
|
|
76
|
+
required: ["sessionID", "delivery", "chars", "resume", "active"],
|
|
77
|
+
additionalProperties: false,
|
|
78
|
+
} as const;
|
|
79
|
+
|
|
80
|
+
const QUEUE_OUTPUT_SCHEMA = {
|
|
45
81
|
type: "object",
|
|
46
82
|
properties: {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
delivery: { type: "string", enum: Object.values(DELIVERY) },
|
|
50
|
-
chars: { type: "integer" },
|
|
51
|
-
resume: {
|
|
83
|
+
...SEND_OUTPUT_PROPERTIES,
|
|
84
|
+
queued: {
|
|
52
85
|
type: "boolean",
|
|
53
|
-
description: "Whether the message could wake an idle child.",
|
|
54
|
-
},
|
|
55
|
-
status: {
|
|
56
|
-
type: "string",
|
|
57
|
-
enum: [...CHILD_STATUSES],
|
|
58
86
|
description:
|
|
59
|
-
"
|
|
60
|
-
},
|
|
61
|
-
pending: {
|
|
62
|
-
type: "boolean",
|
|
63
|
-
description: "True when the message was accepted without waking an idle child.",
|
|
87
|
+
"True when the message was accepted but has not started yet. Inferred from observed status and resume; other queued prompts may be ahead.",
|
|
64
88
|
},
|
|
65
89
|
},
|
|
66
|
-
required: ["sessionID", "delivery", "chars", "resume"],
|
|
90
|
+
required: ["sessionID", "delivery", "chars", "resume", "active"],
|
|
67
91
|
additionalProperties: false,
|
|
68
|
-
} as const
|
|
92
|
+
} as const;
|
|
69
93
|
|
|
70
94
|
const CONTEXT_OUTPUT_SCHEMA = {
|
|
71
95
|
type: "object",
|
|
@@ -77,30 +101,36 @@ const CONTEXT_OUTPUT_SCHEMA = {
|
|
|
77
101
|
description: { type: "string" },
|
|
78
102
|
status: {
|
|
79
103
|
type: "string",
|
|
80
|
-
enum: [...
|
|
104
|
+
enum: [...RUN_STATUSES],
|
|
81
105
|
description:
|
|
82
106
|
"Status observed before the message was accepted; context does not wake the child.",
|
|
83
107
|
},
|
|
108
|
+
active: {
|
|
109
|
+
type: "boolean",
|
|
110
|
+
description:
|
|
111
|
+
"True when the target was running, unknown, or owned a background job when observed.",
|
|
112
|
+
},
|
|
113
|
+
backgroundJob: BACKGROUND_JOB_SCHEMA,
|
|
84
114
|
pending: { type: "boolean" },
|
|
85
115
|
},
|
|
86
|
-
required: ["sessionID", "delivery", "chars"],
|
|
116
|
+
required: ["sessionID", "delivery", "chars", "active"],
|
|
87
117
|
additionalProperties: false,
|
|
88
|
-
} as const
|
|
118
|
+
} as const;
|
|
89
119
|
|
|
90
120
|
export interface PromptSendConfig {
|
|
91
|
-
delivery: Delivery
|
|
92
|
-
failureLabel: string
|
|
93
|
-
outputStrategy: OutputStrategy
|
|
121
|
+
delivery: Delivery;
|
|
122
|
+
failureLabel: string;
|
|
123
|
+
outputStrategy: OutputStrategy;
|
|
94
124
|
}
|
|
95
125
|
|
|
96
126
|
const ADMITTED_LABEL: Record<Delivery, string> = {
|
|
97
127
|
[DELIVERY.steer]: "Steering message sent to",
|
|
98
128
|
[DELIVERY.queue]: "Message queued for",
|
|
99
|
-
}
|
|
129
|
+
};
|
|
100
130
|
|
|
101
131
|
export interface SendDeps {
|
|
102
|
-
config: Config
|
|
103
|
-
sendMessage: SendMessage
|
|
132
|
+
config: Config;
|
|
133
|
+
sendMessage: SendMessage;
|
|
104
134
|
}
|
|
105
135
|
|
|
106
136
|
/**
|
|
@@ -114,14 +144,14 @@ const runPromptSend = async (
|
|
|
114
144
|
config: PromptSendConfig,
|
|
115
145
|
{ config: pluginConfig, sendMessage }: SendDeps,
|
|
116
146
|
) => {
|
|
117
|
-
const { limits } = pluginConfig
|
|
118
|
-
const { outputStrategy } = config
|
|
119
|
-
const { input, format } = readToolInput(rawInput, outputStrategy)
|
|
120
|
-
const textError = maxLengthError(input.text, limits.maxTextLength, "text")
|
|
121
|
-
if (textError) return toolError(textError)
|
|
122
|
-
const sessionID = requireSessionID(input.sessionID)
|
|
123
|
-
const text = requireText(input.text, limits.maxTextLength)
|
|
124
|
-
const resume = input.resume === undefined ? true : input.resume === true
|
|
147
|
+
const { limits } = pluginConfig;
|
|
148
|
+
const { outputStrategy } = config;
|
|
149
|
+
const { input, format } = readToolInput(rawInput, outputStrategy);
|
|
150
|
+
const textError = maxLengthError(input.text, limits.maxTextLength, "text");
|
|
151
|
+
if (textError) return toolError(textError);
|
|
152
|
+
const sessionID = requireSessionID(input.sessionID);
|
|
153
|
+
const text = requireText(input.text, limits.maxTextLength);
|
|
154
|
+
const resume = input.resume === undefined ? true : input.resume === true;
|
|
125
155
|
try {
|
|
126
156
|
const result = await sendMessage(
|
|
127
157
|
{
|
|
@@ -133,29 +163,30 @@ const runPromptSend = async (
|
|
|
133
163
|
},
|
|
134
164
|
context,
|
|
135
165
|
config.failureLabel,
|
|
136
|
-
)
|
|
137
|
-
const delivery = result.admitted?.delivery ?? config.delivery
|
|
138
|
-
const admittedLabel = ADMITTED_LABEL[delivery]
|
|
139
|
-
const chars = textLength(result.admitted?.text ?? text)
|
|
166
|
+
);
|
|
167
|
+
const delivery = result.admitted?.delivery ?? config.delivery;
|
|
168
|
+
const admittedLabel = ADMITTED_LABEL[delivery];
|
|
169
|
+
const chars = textLength(result.admitted?.text ?? text);
|
|
140
170
|
const output: SendOutput = {
|
|
141
171
|
sessionID,
|
|
142
172
|
delivery,
|
|
143
173
|
chars,
|
|
144
174
|
resume,
|
|
145
|
-
}
|
|
146
|
-
applySendResult(output, result)
|
|
175
|
+
};
|
|
176
|
+
applySendResult(output, result);
|
|
177
|
+
const queuedNote = result.queued !== undefined ? `, queued=${result.queued}` : "";
|
|
147
178
|
return outputStrategy.respond(
|
|
148
179
|
`${admittedLabel} ${sessionID}` +
|
|
149
180
|
(result.admitted?.id ? ` as ${result.admitted.id}` : "") +
|
|
150
|
-
` (delivery=${delivery}, resume=${resume}, ${chars} chars).`,
|
|
181
|
+
` (delivery=${delivery}, resume=${resume}${queuedNote}, ${chars} chars).`,
|
|
151
182
|
output,
|
|
152
183
|
format,
|
|
153
|
-
)
|
|
184
|
+
);
|
|
154
185
|
} catch (error) {
|
|
155
|
-
if (error instanceof SendAdmissionError) return toolError(error.message)
|
|
156
|
-
throw error
|
|
186
|
+
if (error instanceof SendAdmissionError) return toolError(error.message);
|
|
187
|
+
throw error;
|
|
157
188
|
}
|
|
158
|
-
}
|
|
189
|
+
};
|
|
159
190
|
|
|
160
191
|
const sendInputSchema = (
|
|
161
192
|
outputStrategy: OutputStrategy,
|
|
@@ -183,19 +214,20 @@ const sendInputSchema = (
|
|
|
183
214
|
},
|
|
184
215
|
required: ["sessionID", "text"],
|
|
185
216
|
additionalProperties: false,
|
|
186
|
-
})
|
|
217
|
+
});
|
|
187
218
|
|
|
188
219
|
export const registerSteerTool = (editor: ToolEditor, deps: SendDeps) => {
|
|
189
|
-
const { allowedOutputFormats, limits } = deps.config
|
|
190
|
-
const outputStrategy = resolveToolOutputStrategy(allowedOutputFormats, TOOL.steer)
|
|
220
|
+
const { allowedOutputFormats, limits } = deps.config;
|
|
221
|
+
const outputStrategy = resolveToolOutputStrategy(allowedOutputFormats, TOOL.steer);
|
|
191
222
|
editor.add({
|
|
192
223
|
name: TOOL.steer,
|
|
193
224
|
description:
|
|
194
225
|
"Send an instruction into a session at its next model request. " +
|
|
195
226
|
"Use it to correct course, add a constraint, or forbid a step. " +
|
|
196
227
|
"It does not interrupt current work: the message is delivered before the next request. " +
|
|
228
|
+
"The plugin cannot move a blocking shell to the background, so delivery may wait for that shell. " +
|
|
197
229
|
"By default an idle child is woken; set resume:false to accept the message without waking it. " +
|
|
198
|
-
"Use queue instead when the message should wait until the current
|
|
230
|
+
"Use queue instead when the message should wait until the current execution settles.",
|
|
199
231
|
input: sendInputSchema(
|
|
200
232
|
outputStrategy,
|
|
201
233
|
limits.maxTextLength,
|
|
@@ -215,26 +247,27 @@ export const registerSteerTool = (editor: ToolEditor, deps: SendDeps) => {
|
|
|
215
247
|
},
|
|
216
248
|
deps,
|
|
217
249
|
),
|
|
218
|
-
})
|
|
219
|
-
}
|
|
250
|
+
});
|
|
251
|
+
};
|
|
220
252
|
|
|
221
253
|
export const registerQueueTool = (editor: ToolEditor, deps: SendDeps) => {
|
|
222
|
-
const { allowedOutputFormats, limits } = deps.config
|
|
223
|
-
const outputStrategy = resolveToolOutputStrategy(allowedOutputFormats, TOOL.queue)
|
|
254
|
+
const { allowedOutputFormats, limits } = deps.config;
|
|
255
|
+
const outputStrategy = resolveToolOutputStrategy(allowedOutputFormats, TOOL.queue);
|
|
224
256
|
editor.add({
|
|
225
257
|
name: TOOL.queue,
|
|
226
258
|
description:
|
|
227
259
|
"Queue a message for a session as its next independent turn. " +
|
|
228
|
-
"Unlike steer, it does not join the current run: it waits
|
|
260
|
+
"Unlike steer, it does not join the current run: it waits for the current execution to settle, then starts a separate turn. " +
|
|
261
|
+
"Background jobs are not waited for and continue in parallel. " +
|
|
229
262
|
"Use it for 'do this next' work. By default an idle child is woken; set resume:false to accept the message without waking it. " +
|
|
230
263
|
"Use steer instead to correct the current run.",
|
|
231
264
|
input: sendInputSchema(
|
|
232
265
|
outputStrategy,
|
|
233
266
|
limits.maxTextLength,
|
|
234
267
|
"Follow-up message.",
|
|
235
|
-
"Default true: wake an idle child and start the queued turn. Set false to accept without waking; an idle child keeps the message pending until its next run.",
|
|
268
|
+
"Default true: wake an idle child and start the queued turn. The queue waits for the current execution, not background jobs. Set false to accept without waking; an idle child keeps the message pending until its next run.",
|
|
236
269
|
),
|
|
237
|
-
output: outputStrategy.schema(
|
|
270
|
+
output: outputStrategy.schema(QUEUE_OUTPUT_SCHEMA),
|
|
238
271
|
options: { namespace: deps.config.namespace },
|
|
239
272
|
execute: async (rawInput, context) =>
|
|
240
273
|
runPromptSend(
|
|
@@ -247,13 +280,13 @@ export const registerQueueTool = (editor: ToolEditor, deps: SendDeps) => {
|
|
|
247
280
|
},
|
|
248
281
|
deps,
|
|
249
282
|
),
|
|
250
|
-
})
|
|
251
|
-
}
|
|
283
|
+
});
|
|
284
|
+
};
|
|
252
285
|
|
|
253
286
|
export const registerContextTool = (editor: ToolEditor, deps: SendDeps) => {
|
|
254
|
-
const { allowedOutputFormats, limits } = deps.config
|
|
255
|
-
const outputStrategy = resolveToolOutputStrategy(allowedOutputFormats, TOOL.context)
|
|
256
|
-
const { sendMessage } = deps
|
|
287
|
+
const { allowedOutputFormats, limits } = deps.config;
|
|
288
|
+
const outputStrategy = resolveToolOutputStrategy(allowedOutputFormats, TOOL.context);
|
|
289
|
+
const { sendMessage } = deps;
|
|
257
290
|
|
|
258
291
|
editor.add({
|
|
259
292
|
name: TOOL.context,
|
|
@@ -287,18 +320,18 @@ export const registerContextTool = (editor: ToolEditor, deps: SendDeps) => {
|
|
|
287
320
|
output: outputStrategy.schema(CONTEXT_OUTPUT_SCHEMA),
|
|
288
321
|
options: { namespace: deps.config.namespace },
|
|
289
322
|
execute: async (rawInput, context) => {
|
|
290
|
-
const { input, format } = readToolInput(rawInput, outputStrategy)
|
|
291
|
-
const textError = maxLengthError(input?.text, limits.maxTextLength, "text")
|
|
292
|
-
if (textError) return toolError(textError)
|
|
323
|
+
const { input, format } = readToolInput(rawInput, outputStrategy);
|
|
324
|
+
const textError = maxLengthError(input?.text, limits.maxTextLength, "text");
|
|
325
|
+
if (textError) return toolError(textError);
|
|
293
326
|
const descriptionField = readTextField(
|
|
294
327
|
input?.description,
|
|
295
328
|
MAX_DESCRIPTION_LENGTH,
|
|
296
329
|
"description",
|
|
297
|
-
)
|
|
298
|
-
if (descriptionField.error) return toolError(descriptionField.error)
|
|
299
|
-
const sessionID = requireSessionID(input?.sessionID)
|
|
300
|
-
const text = requireText(input?.text, limits.maxTextLength)
|
|
301
|
-
const description = descriptionField.text
|
|
330
|
+
);
|
|
331
|
+
if (descriptionField.error) return toolError(descriptionField.error);
|
|
332
|
+
const sessionID = requireSessionID(input?.sessionID);
|
|
333
|
+
const text = requireText(input?.text, limits.maxTextLength);
|
|
334
|
+
const description = descriptionField.text;
|
|
302
335
|
try {
|
|
303
336
|
const result = await sendMessage(
|
|
304
337
|
{
|
|
@@ -307,29 +340,30 @@ export const registerContextTool = (editor: ToolEditor, deps: SendDeps) => {
|
|
|
307
340
|
kind: SEND_KIND.synthetic,
|
|
308
341
|
resume: false,
|
|
309
342
|
description,
|
|
343
|
+
metadata: { source: CONTEXT_METADATA_SOURCE },
|
|
310
344
|
},
|
|
311
345
|
context,
|
|
312
346
|
"Context injection",
|
|
313
|
-
)
|
|
314
|
-
const chars = textLength(result.admitted?.text ?? text)
|
|
347
|
+
);
|
|
348
|
+
const chars = textLength(result.admitted?.text ?? text);
|
|
315
349
|
const output: ContextOutput = {
|
|
316
350
|
sessionID,
|
|
317
351
|
delivery: CONTEXT_DELIVERY,
|
|
318
352
|
chars,
|
|
319
|
-
}
|
|
320
|
-
if (description) output.description = description
|
|
321
|
-
applySendResult(output, result)
|
|
353
|
+
};
|
|
354
|
+
if (description) output.description = description;
|
|
355
|
+
applySendResult(output, result);
|
|
322
356
|
return outputStrategy.respond(
|
|
323
357
|
`Context injected into ${sessionID}` +
|
|
324
358
|
(result.admitted?.id ? ` as ${result.admitted.id}` : "") +
|
|
325
359
|
` (${chars} chars).`,
|
|
326
360
|
output,
|
|
327
361
|
format,
|
|
328
|
-
)
|
|
362
|
+
);
|
|
329
363
|
} catch (error) {
|
|
330
|
-
if (error instanceof SendAdmissionError) return toolError(error.message)
|
|
331
|
-
throw error
|
|
364
|
+
if (error instanceof SendAdmissionError) return toolError(error.message);
|
|
365
|
+
throw error;
|
|
332
366
|
}
|
|
333
367
|
},
|
|
334
|
-
})
|
|
335
|
-
}
|
|
368
|
+
});
|
|
369
|
+
};
|