@taco-ai/extension-api 0.0.0-stage → 0.4.5

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 NiumAgents
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,10 @@
1
- # Temporary Holding Version
1
+ # @taco-ai/extension-api
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ TypeScript declarations for Taco extensions. The host passes an `ExtensionApi`
4
+ object to the module's default export. Import API types with `import type`;
5
+ the package does not start the sidecar or provide runtime registration helpers.
6
+
7
+ See the [Taco extension authoring guide](https://github.com/niuma996/taco/blob/main/docs/05-extension-authoring.md)
8
+ and [minimal example](https://github.com/niuma996/taco/tree/main/examples/extension-minimal).
9
+ The package version follows Taco releases. The separate `taco.apiVersion`
10
+ manifest field selects the loader contract and is currently `"1"`.
@@ -0,0 +1,45 @@
1
+ /** Tag identifier. Valid names must be accepted by the host tag registry. */
2
+ export type TagName = string;
3
+ /** Which phase of processing a tag applies to. */
4
+ export type TagScope = "system" | "user-context" | "user-request" | "assistant-output" | "summary";
5
+ /** How a tag's body is handled during context compression. */
6
+ export type CompressionPolicy = {
7
+ readonly kind: "pin";
8
+ /** Optional attribute name for per-instance deduplication during
9
+ * compaction (e.g. `"name"` on `skill_body` so multiple distinct
10
+ * skills each survive compaction). Omitted = singleton per tag name. */
11
+ readonly dedupAttr?: string;
12
+ } | {
13
+ readonly kind: "pinOnce";
14
+ } | {
15
+ readonly kind: "summarize";
16
+ } | {
17
+ readonly kind: "drop";
18
+ };
19
+ /** How the tag's content boundaries are determined. Sole kind — add a new variant when a real use case appears. */
20
+ export type ParserKind = {
21
+ readonly kind: "xml-balanced";
22
+ };
23
+ /** Immutable tag specification. */
24
+ export interface TagSpec {
25
+ readonly name: TagName;
26
+ readonly scope: TagScope;
27
+ readonly compression: CompressionPolicy;
28
+ /** Client presentation only. `quote` renders the body as cited text, not author text. */
29
+ readonly tuiVisibility: "visible" | "hidden" | "ephemeral" | "quote";
30
+ readonly parser: ParserKind;
31
+ /** Human-readable description for tooling / debug output. */
32
+ readonly description: string;
33
+ }
34
+ /** Capabilities required for a prompt section to apply to the current toolset. */
35
+ export type SystemPromptContributorTag = "skills" | "agents" | "plan" | "tasks" | "memory";
36
+ /** A section a caller wants to graft onto the assembled prompt. */
37
+ export interface SystemPromptContributor {
38
+ prepend?: string;
39
+ append?: string;
40
+ /** Optional capabilities the contributor requires. The subagent rebuilder
41
+ * drops a contributor whose required tags are not satisfied by the
42
+ * child's toolset, so a read-only agent does not see a `<skill>`
43
+ * listing it cannot act on. */
44
+ requires?: ReadonlyArray<SystemPromptContributorTag>;
45
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,212 @@
1
+ import type { ImageContent, TextContent, Usage } from "@earendil-works/pi-ai";
2
+ import type { AgentMessage } from "@taco-ai/pi-harness";
3
+ import type { ExtensionPermission, ExtensionSource } from "@taco-ai/protocol";
4
+ import type { SystemPromptContributor, TagSpec } from "./contributions.js";
5
+ import type { FileAccess, TacoTool } from "./tools.js";
6
+ /** Supported contract versions. Loader rejects manifests declaring any other value. */
7
+ export type ExtensionApiVersion = "1";
8
+ export interface ExtensionManifest {
9
+ readonly name: string;
10
+ readonly version: string;
11
+ readonly apiVersion: ExtensionApiVersion;
12
+ readonly permissions: ReadonlyArray<ExtensionPermission>;
13
+ /** Short description ("what it does"), from package.json taco.description, may be absent. */
14
+ readonly description?: string;
15
+ /** Usage guidance ("when to use it"), from package.json taco.whenToUse, may be absent. */
16
+ readonly whenToUse?: string;
17
+ /** Validates supplied configuration; schema defaults are not applied. */
18
+ readonly configSchema?: Record<string, unknown>;
19
+ /** Skip workspace activators on IM workspaces; startup registrations are unaffected. */
20
+ readonly skipOnIm?: boolean;
21
+ }
22
+ /**
23
+ * Context hook event — the messages about to be sent to the LLM. The hook
24
+ * may return a `ContextResult` to replace the messages, or `undefined`
25
+ * to pass them through unchanged. Single-purpose: no event-type discriminator.
26
+ */
27
+ export interface ContextEvent {
28
+ messages: AgentMessage[];
29
+ }
30
+ /**
31
+ * Context hook return — when present, the `messages` field replaces the
32
+ * outbound message list. When omitted, the messages pass through
33
+ * unchanged. The `undefined` return value is equivalent to `{}`.
34
+ */
35
+ export interface ContextResult {
36
+ messages?: AgentMessage[];
37
+ }
38
+ /**
39
+ * Tool-call interceptor event. Registered with
40
+ * `api.registerToolCallInterceptor`. Return `{ block: true, reason }`
41
+ * to prevent the call from executing; return `undefined` to let it
42
+ * proceed normally.
43
+ */
44
+ export interface ToolCallEvent {
45
+ type: "tool_call";
46
+ toolCallId: string;
47
+ toolName: string;
48
+ input: Record<string, unknown>;
49
+ /** The run's abort signal, when the harness provides one. */
50
+ signal?: AbortSignal;
51
+ }
52
+ /**
53
+ * Result of a tool-call interceptor.
54
+ */
55
+ export interface ToolCallResult {
56
+ block?: boolean;
57
+ reason?: string;
58
+ }
59
+ /**
60
+ * Tool-result interceptor event. Registered with
61
+ * `api.registerToolResultInterceptor`. Return a `ToolResultPatch` to
62
+ * override the original fields; return `undefined` to leave the
63
+ * result untouched.
64
+ *
65
+ * `terminate: true` aborts the turn after this result lands.
66
+ */
67
+ export interface ToolResultEvent {
68
+ type: "tool_result";
69
+ toolCallId: string;
70
+ toolName: string;
71
+ input: Record<string, unknown>;
72
+ content: Array<TextContent | ImageContent>;
73
+ details: unknown;
74
+ isError: boolean;
75
+ usage?: Usage;
76
+ }
77
+ export interface ToolResultPatch {
78
+ content?: Array<TextContent | ImageContent>;
79
+ details?: unknown;
80
+ isError?: boolean;
81
+ usage?: Usage;
82
+ terminate?: boolean;
83
+ }
84
+ /**
85
+ * Context hook handler.
86
+ * - Return `undefined` (or void) → messages pass through unchanged
87
+ * - Return `{ messages }` → replace the messages array sent to the LLM
88
+ */
89
+ export type ContextHook = (event: ContextEvent) => ContextResult | undefined | Promise<ContextResult | undefined>;
90
+ /**
91
+ * Tool-call interceptor. Registered with
92
+ * `api.registerToolCallInterceptor`. Return `undefined` → tool call
93
+ * proceeds normally. Return `{ block: true, reason }` → the call is
94
+ * blocked; the harness skips execution and records the tool result
95
+ * as-is.
96
+ */
97
+ export type ToolCallHook = (event: ToolCallEvent) => ToolCallResult | undefined | Promise<ToolCallResult | undefined>;
98
+ /**
99
+ * Tool-result interceptor. Registered with
100
+ * `api.registerToolResultInterceptor`. Return `undefined` → result
101
+ * passes through unchanged. Return a `ToolResultPatch` → fields merge
102
+ * onto the result; `terminate: true` aborts the turn.
103
+ */
104
+ export type ToolResultHook = (event: ToolResultEvent) => ToolResultPatch | undefined | Promise<ToolResultPatch | undefined>;
105
+ export interface ExtensionLogger {
106
+ info(msg: string): void;
107
+ warn(msg: string): void;
108
+ error(msg: string): void;
109
+ debug(msg: string): void;
110
+ }
111
+ export interface ExtensionToolRegistrationOptions {
112
+ readonly fileAccess?: FileAccess;
113
+ }
114
+ export interface ExtensionToolCandidate {
115
+ readonly name: string;
116
+ readonly summary: string;
117
+ readonly loading: "deferred" | "always";
118
+ readonly fileAccess?: FileAccess;
119
+ load(): Promise<TacoTool>;
120
+ }
121
+ export interface ExtensionToolCandidateWithSource {
122
+ readonly name: string;
123
+ readonly candidate: ExtensionToolCandidate;
124
+ }
125
+ /** Async cleanup is awaited for up to five seconds per scope, then continues in the background. */
126
+ export type ExtensionDisposer = () => void | Promise<void>;
127
+ export interface SessionActivatorContext {
128
+ readonly cwd: string;
129
+ readonly sessionId: string;
130
+ readonly sessionKind: "main" | "subagent";
131
+ readonly isIm: boolean;
132
+ readonly config: Readonly<Record<string, unknown>>;
133
+ }
134
+ export interface SessionRunEndEvent extends SessionActivatorContext {
135
+ readonly status: "completed" | "failed" | "aborted";
136
+ }
137
+ /** Async listeners are drained during disposal within the scope cleanup budget. */
138
+ export type SessionRunEndHook = (event: SessionRunEndEvent) => void | Promise<void>;
139
+ export interface SessionContribution {
140
+ runEndHooks?: SessionRunEndHook[];
141
+ disposers?: ExtensionDisposer[];
142
+ }
143
+ export type SessionActivator = (ctx: SessionActivatorContext) => SessionContribution | undefined | Promise<SessionContribution | undefined>;
144
+ export interface ExtensionApi {
145
+ readonly manifest: ExtensionManifest;
146
+ readonly logger: ExtensionLogger;
147
+ readonly config: Readonly<Record<string, unknown>>;
148
+ registerContextHook(hook: ContextHook): void;
149
+ /** Intercept / block a tool invocation before it executes. */
150
+ registerToolCallInterceptor(hook: ToolCallHook): void;
151
+ /** Transform a tool result after execution; can also terminate the turn. */
152
+ registerToolResultInterceptor(hook: ToolResultHook): void;
153
+ registerTool(tool: TacoTool, options?: ExtensionToolRegistrationOptions): void;
154
+ registerToolCandidate(candidate: ExtensionToolCandidate): void;
155
+ registerWorkspaceActivator(activator: WorkspaceActivator): void;
156
+ registerSessionActivator(activator: SessionActivator): void;
157
+ registerSystemPrompt(contributor: SystemPromptContributor): void;
158
+ /** Register a custom tag — flows through the tag system's pin/drop/visibility
159
+ * pipeline. Requires the `tags` permission in the manifest. Throws on collisions
160
+ * or invalid specs. */
161
+ registerTag(spec: TagSpec): void;
162
+ }
163
+ export type ExtensionModule = (api: ExtensionApi) => void | Promise<void>;
164
+ /**
165
+ * A per-workspace contribution produced by an activator.
166
+ * Any field may be omitted; missing means "no contribution this workspace".
167
+ *
168
+ * Hook ordering is derived from the registering extension's source; extension
169
+ * authors do not need to provide a source on each contribution.
170
+ */
171
+ export interface WorkspaceContribution {
172
+ contextHooks?: ContextHook[];
173
+ toolCallHooks?: ToolCallHook[];
174
+ toolResultHooks?: ToolResultHook[];
175
+ tools?: Array<{
176
+ name: string;
177
+ tool: TacoTool;
178
+ fileAccess?: FileAccess;
179
+ }>;
180
+ toolCandidates?: ExtensionToolCandidateWithSource[];
181
+ sessionActivators?: SessionActivator[];
182
+ disposers?: ExtensionDisposer[];
183
+ systemPrompt?: SystemPromptContributor;
184
+ /**
185
+ * Shell allow-rules this extension adds for the workspace, merged after the
186
+ * user's `commandPermissions.allow`. In-memory only — never written to
187
+ * taco.json, so disabling the extension removes them with it. Rules use the
188
+ * same string syntax as taco.json (`officecli *`, `git status`).
189
+ */
190
+ commandPermissionRules?: string[];
191
+ /** Optional read-only probe for conditional capabilities; must not allocate resources. */
192
+ activationStatus?: () => {
193
+ active: boolean;
194
+ reason?: string;
195
+ } | Promise<{
196
+ active: boolean;
197
+ reason?: string;
198
+ }>;
199
+ /** @deprecated The host assigns the registration source. */
200
+ source?: ExtensionSource;
201
+ }
202
+ /**
203
+ * Callback registered through `registerWorkspaceActivator`, invoked once per workspace when
204
+ * `activateExtensions` runs. May perform async I/O and decide conditionally
205
+ * based on `ctx.cwd` and `ctx.isIm`.
206
+ */
207
+ export type WorkspaceActivator = (ctx: WorkspaceActivatorContext) => WorkspaceContribution | undefined | Promise<WorkspaceContribution | undefined>;
208
+ export interface WorkspaceActivatorContext {
209
+ readonly cwd: string;
210
+ readonly isIm: boolean;
211
+ readonly config: Readonly<Record<string, unknown>>;
212
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ /** Public contract for Taco extension authors. All exports are types. */
2
+ export type { ImageContent, TextContent, Usage } from "@earendil-works/pi-ai";
3
+ export type { AgentMessage, AgentToolResult, Context as ToolExecutionContext, } from "@taco-ai/pi-harness";
4
+ export type { ExtensionPermission, ExtensionSource } from "@taco-ai/protocol";
5
+ export type * from "./contributions.js";
6
+ export type * from "./extensions.js";
7
+ export type * from "./tools.js";
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import type { AgentHarnessTool, ExecutionToolContext } from "@taco-ai/pi-harness";
2
+ import type { SessionId, WorkspaceId } from "@taco-ai/protocol";
3
+ import type { TSchema } from "typebox";
4
+ /** Per-call context provided by the host to extension tools. */
5
+ export interface TacoToolContext {
6
+ readonly env: ExecutionToolContext["env"];
7
+ readonly workspace: WorkspaceId;
8
+ readonly sessionId: SessionId;
9
+ readonly sessionKind: "main" | "subagent";
10
+ readonly isIm: boolean;
11
+ /** True when IM policy denies filesystem tools. */
12
+ readonly fsToolsDenied?: boolean;
13
+ }
14
+ /** Tool callable by Taco, optionally carrying prompt and mutation metadata. */
15
+ export type TacoTool<TContext extends TacoToolContext = TacoToolContext, TParameters extends TSchema = TSchema, TDetails = unknown> = AgentHarnessTool<TContext, TParameters, TDetails> & {
16
+ readonly taco?: TacoToolMetadata;
17
+ };
18
+ export interface TacoToolMetadata {
19
+ /** One-paragraph prose (≤ 350 chars). Should explain *when* to use this
20
+ * tool vs. a sibling, not re-state the schema description verbatim. */
21
+ readonly promptSummary?: string;
22
+ /** Whether this tool mutates workspace state. Drives the
23
+ * `[read-only]` / `[mutates]` tag in the system prompt. Defaults to
24
+ * `true` when omitted — failure mode is conservative (model treats
25
+ * unknown tools as mutating). */
26
+ readonly mutates?: boolean;
27
+ /** Whether this tool is destructive / hard to reverse (e.g. overwrite,
28
+ * delete, raw shell). Shown as an additional `[destructive]` tag in the
29
+ * routing guide and may feed the permission layer. Defaults to false. */
30
+ readonly destructive?: boolean;
31
+ /** Whether this tool ends the turn to wait for a user answer or approval
32
+ * (e.g. `askUser`, `planExit`). Read-only tools marked `awaitsUser` are
33
+ * called out as exceptions to read-only batching in the routing guide.
34
+ * Defaults to false. */
35
+ readonly awaitsUser?: boolean;
36
+ }
37
+ export interface PathArg {
38
+ /** Top-level input key holding the path. */
39
+ readonly key: string;
40
+ /** The value is an array of paths rather than a single one. */
41
+ readonly many?: boolean;
42
+ }
43
+ export interface FileAccess {
44
+ /** Path arguments the tool reads. An empty list marks a filesystem reader with no path argument. */
45
+ readonly reads?: readonly PathArg[];
46
+ /** Required string argument naming the write target (a file, or for pdfSplit a directory). */
47
+ readonly write?: string;
48
+ }
package/dist/tools.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,38 @@
1
1
  {
2
2
  "name": "@taco-ai/extension-api",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.4.5",
4
+ "description": "TypeScript contracts for Taco extensions",
5
+ "type": "module",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
19
+ "license": "MIT",
20
+ "repository": "github:niuma996/taco",
21
+ "publishConfig": {
22
+ "access": "public"
23
+ },
24
+ "dependencies": {
25
+ "@earendil-works/pi-ai": "1.5.2",
26
+ "@taco-ai/pi-harness": "0.2.1",
27
+ "typebox": "^1.4.7",
28
+ "@taco-ai/protocol": "0.4.5"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^22.7.0",
32
+ "typescript": "^7.0.2"
33
+ },
34
+ "scripts": {
35
+ "build": "tsc -p tsconfig.json",
36
+ "typecheck": "tsc -p tsconfig.json --noEmit"
37
+ }
6
38
  }