@gajae-code/coding-agent 0.7.2 → 0.7.4
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 +86 -0
- package/bin/gjc.js +4 -0
- package/dist/types/cli/mcp-cli.d.ts +25 -0
- package/dist/types/cli/plugin-cli.d.ts +2 -0
- package/dist/types/cli.d.ts +6 -0
- package/dist/types/commands/mcp.d.ts +70 -0
- package/dist/types/commands/plugin.d.ts +6 -0
- package/dist/types/commands/session.d.ts +6 -0
- package/dist/types/config/keybindings.d.ts +2 -2
- package/dist/types/config/model-profile-activation.d.ts +8 -1
- package/dist/types/deep-interview/plaintext-gate-guard.d.ts +11 -0
- package/dist/types/extensibility/gjc-plugins/compiler.d.ts +19 -0
- package/dist/types/extensibility/gjc-plugins/constrained-hooks.d.ts +29 -0
- package/dist/types/extensibility/gjc-plugins/index.d.ts +9 -0
- package/dist/types/extensibility/gjc-plugins/injection.d.ts +9 -0
- package/dist/types/extensibility/gjc-plugins/installer.d.ts +13 -0
- package/dist/types/extensibility/gjc-plugins/mcp-policy.d.ts +26 -0
- package/dist/types/extensibility/gjc-plugins/observability.d.ts +27 -0
- package/dist/types/extensibility/gjc-plugins/prompt-appendix.d.ts +16 -0
- package/dist/types/extensibility/gjc-plugins/registry.d.ts +32 -0
- package/dist/types/extensibility/gjc-plugins/runtime-adapters.d.ts +64 -0
- package/dist/types/extensibility/gjc-plugins/session-validation.d.ts +42 -0
- package/dist/types/extensibility/gjc-plugins/types.d.ts +158 -2
- package/dist/types/extensibility/gjc-plugins/validation.d.ts +8 -1
- package/dist/types/gjc-runtime/launch-tmux.d.ts +1 -0
- package/dist/types/gjc-runtime/psmux-detect.d.ts +78 -0
- package/dist/types/gjc-runtime/team-runtime.d.ts +2 -0
- package/dist/types/gjc-runtime/tmux-common.d.ts +20 -1
- package/dist/types/gjc-runtime/tmux-sessions.d.ts +18 -0
- package/dist/types/main.d.ts +2 -0
- package/dist/types/modes/components/custom-editor.d.ts +1 -1
- package/dist/types/modes/components/model-selector.d.ts +8 -0
- package/dist/types/modes/components/status-line/git-utils.d.ts +6 -0
- package/dist/types/modes/theme/defaults/index.d.ts +99 -0
- package/dist/types/notifications/html-format.d.ts +11 -0
- package/dist/types/notifications/index.d.ts +149 -1
- package/dist/types/notifications/lifecycle-commands.d.ts +72 -0
- package/dist/types/notifications/lifecycle-control-runtime.d.ts +98 -0
- package/dist/types/notifications/lifecycle-orchestrator.d.ts +144 -0
- package/dist/types/notifications/operator-runtime.d.ts +52 -0
- package/dist/types/notifications/rate-limit-pool.d.ts +2 -0
- package/dist/types/notifications/recent-activity.d.ts +35 -0
- package/dist/types/notifications/telegram-daemon.d.ts +114 -16
- package/dist/types/notifications/telegram-reference.d.ts +3 -1
- package/dist/types/notifications/topic-registry.d.ts +12 -9
- package/dist/types/runtime-mcp/types.d.ts +7 -0
- package/dist/types/sdk.d.ts +2 -0
- package/dist/types/session/agent-session.d.ts +14 -4
- package/dist/types/session/blob-store.d.ts +25 -0
- package/dist/types/session/session-manager.d.ts +57 -0
- package/dist/types/slash-commands/helpers/fast-status-report.d.ts +6 -0
- package/dist/types/system-prompt.d.ts +2 -0
- package/dist/types/task/executor.d.ts +9 -1
- package/dist/types/tools/composer-bash-policy.d.ts +14 -0
- package/dist/types/tools/index.d.ts +3 -1
- package/dist/types/utils/changelog.d.ts +1 -0
- package/dist/types/web/insane/url-guard.d.ts +6 -3
- package/dist/types/web/scrapers/types.d.ts +5 -0
- package/dist/types/web/scrapers/utils.d.ts +7 -1
- package/package.json +11 -9
- package/scripts/g004-tmux-smoke.ts +100 -0
- package/scripts/g005-daemon-smoke.ts +181 -0
- package/scripts/g011-daemon-path-smoke.ts +153 -0
- package/src/cli/mcp-cli.ts +272 -0
- package/src/cli/plugin-cli.ts +66 -3
- package/src/cli.ts +27 -6
- package/src/commands/mcp.ts +117 -0
- package/src/commands/plugin.ts +4 -0
- package/src/commands/session.ts +18 -0
- package/src/config/keybindings.ts +2 -2
- package/src/config/model-profile-activation.ts +55 -7
- package/src/deep-interview/plaintext-gate-guard.ts +94 -0
- package/src/defaults/gjc/extensions/grok-cli-vendor/biome.json +1 -1
- package/src/defaults/gjc/skills/deep-interview/SKILL.md +7 -6
- package/src/defaults/gjc/skills/team/SKILL.md +5 -3
- package/src/defaults/gjc/skills/ultragoal/SKILL.md +41 -13
- package/src/export/html/index.ts +2 -2
- package/src/extensibility/extensions/runner.ts +1 -0
- package/src/extensibility/gjc-plugins/compiler.ts +351 -0
- package/src/extensibility/gjc-plugins/constrained-hooks.ts +170 -0
- package/src/extensibility/gjc-plugins/index.ts +9 -0
- package/src/extensibility/gjc-plugins/injection.ts +109 -0
- package/src/extensibility/gjc-plugins/installer.ts +434 -0
- package/src/extensibility/gjc-plugins/loader.ts +3 -1
- package/src/extensibility/gjc-plugins/mcp-policy.ts +239 -0
- package/src/extensibility/gjc-plugins/observability.ts +84 -0
- package/src/extensibility/gjc-plugins/paths.ts +1 -1
- package/src/extensibility/gjc-plugins/prompt-appendix.ts +109 -0
- package/src/extensibility/gjc-plugins/registry.ts +180 -0
- package/src/extensibility/gjc-plugins/runtime-adapters.ts +234 -0
- package/src/extensibility/gjc-plugins/schema.ts +250 -20
- package/src/extensibility/gjc-plugins/session-validation.ts +147 -0
- package/src/extensibility/gjc-plugins/types.ts +199 -3
- package/src/extensibility/gjc-plugins/validation.ts +80 -0
- package/src/extensibility/skills.ts +15 -0
- package/src/gjc-runtime/launch-tmux.ts +61 -7
- package/src/gjc-runtime/psmux-detect.ts +239 -0
- package/src/gjc-runtime/team-runtime.ts +56 -23
- package/src/gjc-runtime/tmux-common.ts +30 -3
- package/src/gjc-runtime/tmux-sessions.ts +51 -1
- package/src/gjc-runtime/ultragoal-guard.ts +25 -8
- package/src/gjc-runtime/ultragoal-runtime.ts +75 -15
- package/src/hooks/skill-state.ts +57 -0
- package/src/internal-urls/docs-index.generated.ts +12 -8
- package/src/main.ts +14 -3
- package/src/modes/bridge/bridge-mode.ts +11 -0
- package/src/modes/components/custom-editor.ts +2 -0
- package/src/modes/components/footer.ts +2 -3
- package/src/modes/components/hook-editor.ts +1 -1
- package/src/modes/components/hook-selector.ts +67 -43
- package/src/modes/components/model-selector.ts +56 -11
- package/src/modes/components/status-line/git-utils.ts +25 -0
- package/src/modes/components/status-line.ts +10 -11
- package/src/modes/components/welcome.ts +2 -3
- package/src/modes/controllers/extension-ui-controller.ts +0 -27
- package/src/modes/controllers/selector-controller.ts +53 -11
- package/src/modes/interactive-mode.ts +4 -1
- package/src/modes/shared/agent-wire/scopes.ts +1 -1
- package/src/modes/theme/defaults/gruvbox-dark.json +99 -0
- package/src/modes/theme/defaults/index.ts +2 -0
- package/src/modes/utils/hotkeys-markdown.ts +1 -1
- package/src/notifications/html-format.ts +38 -0
- package/src/notifications/index.ts +242 -12
- package/src/notifications/lifecycle-commands.ts +228 -0
- package/src/notifications/lifecycle-control-runtime.ts +400 -0
- package/src/notifications/lifecycle-orchestrator.ts +358 -0
- package/src/notifications/operator-runtime.ts +171 -0
- package/src/notifications/rate-limit-pool.ts +19 -0
- package/src/notifications/recent-activity.ts +132 -0
- package/src/notifications/telegram-daemon.ts +778 -257
- package/src/notifications/telegram-reference.ts +25 -7
- package/src/notifications/topic-registry.ts +23 -9
- package/src/prompts/agents/executor.md +2 -2
- package/src/runtime-mcp/transports/stdio.ts +38 -4
- package/src/runtime-mcp/types.ts +7 -0
- package/src/sdk.ts +157 -10
- package/src/session/agent-session.ts +166 -74
- package/src/session/blob-store.ts +196 -8
- package/src/session/session-manager.ts +678 -7
- package/src/slash-commands/builtin-registry.ts +23 -3
- package/src/slash-commands/helpers/fast-status-report.ts +13 -3
- package/src/slash-commands/helpers/parse.ts +2 -1
- package/src/system-prompt.ts +9 -0
- package/src/task/executor.ts +31 -7
- package/src/task/index.ts +2 -0
- package/src/tools/ask.ts +5 -1
- package/src/tools/bash.ts +9 -0
- package/src/tools/composer-bash-policy.ts +96 -0
- package/src/tools/fetch.ts +18 -2
- package/src/tools/index.ts +3 -1
- package/src/utils/changelog.ts +8 -0
- package/src/web/insane/url-guard.ts +18 -14
- package/src/web/scrapers/types.ts +143 -45
- package/src/web/scrapers/utils.ts +70 -19
|
@@ -15,7 +15,14 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import * as fs from "node:fs";
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
bold,
|
|
20
|
+
buildCompactChoiceGrid,
|
|
21
|
+
escapeHtml,
|
|
22
|
+
numberedOptionList,
|
|
23
|
+
TELEGRAM_PARSE_MODE,
|
|
24
|
+
truncateTelegramHtml,
|
|
25
|
+
} from "./html-format";
|
|
19
26
|
import { renderThreadedFrame } from "./threaded-render";
|
|
20
27
|
|
|
21
28
|
/** One inline-keyboard button. */
|
|
@@ -129,8 +136,9 @@ export function buildActionMessage(action: {
|
|
|
129
136
|
const text = `❓ ${bold(action.question ?? "Question")}`;
|
|
130
137
|
const options = action.options ?? [];
|
|
131
138
|
if (options.length === 0) return { text: truncateTelegramHtml(`${text}\n\n(reply with text)`) };
|
|
132
|
-
const
|
|
133
|
-
|
|
139
|
+
const body = `${text}\n\n${numberedOptionList(options)}`;
|
|
140
|
+
const inline_keyboard = buildCompactChoiceGrid(options, i => encodeCallbackData(action.id, i));
|
|
141
|
+
return { text: truncateTelegramHtml(body), inline_keyboard };
|
|
134
142
|
}
|
|
135
143
|
|
|
136
144
|
/** A protocol `reply` frame the client should send to the server. */
|
|
@@ -235,13 +243,23 @@ export function routeInboundUpdate(update: unknown, ctx: RouteInboundContext): R
|
|
|
235
243
|
return { kind: "ignore" };
|
|
236
244
|
}
|
|
237
245
|
|
|
238
|
-
/** Read `{url, token}` from an endpoint discovery file. */
|
|
239
|
-
export function readEndpoint(path: string): { url: string; token: string } {
|
|
240
|
-
const raw = JSON.parse(fs.readFileSync(path, "utf8")) as {
|
|
246
|
+
/** Read `{url, token, pid?, stale?}` from an endpoint discovery file. */
|
|
247
|
+
export function readEndpoint(path: string): { url: string; token: string; pid?: number; stale?: boolean } {
|
|
248
|
+
const raw = JSON.parse(fs.readFileSync(path, "utf8")) as {
|
|
249
|
+
url?: unknown;
|
|
250
|
+
token?: unknown;
|
|
251
|
+
pid?: unknown;
|
|
252
|
+
stale?: unknown;
|
|
253
|
+
};
|
|
241
254
|
if (typeof raw.url !== "string" || typeof raw.token !== "string") {
|
|
242
255
|
throw new Error(`invalid endpoint file: ${path}`);
|
|
243
256
|
}
|
|
244
|
-
return {
|
|
257
|
+
return {
|
|
258
|
+
url: raw.url,
|
|
259
|
+
token: raw.token,
|
|
260
|
+
pid: typeof raw.pid === "number" ? raw.pid : undefined,
|
|
261
|
+
stale: raw.stale === true,
|
|
262
|
+
};
|
|
245
263
|
}
|
|
246
264
|
|
|
247
265
|
/** Options for {@link runTelegramReferenceClient}. */
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Per-session forum-topic registry for the threaded session surface.
|
|
3
3
|
*
|
|
4
|
-
* Each GJC session owns
|
|
5
|
-
* DM. The topic is created
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
4
|
+
* Each GJC session owns one active Telegram forum topic in the paired private
|
|
5
|
+
* DM. The topic is created via `createForumTopic`, reused while the session
|
|
6
|
+
* remains active, and removed from the registry when the daemon deletes it on
|
|
7
|
+
* shutdown. The registry also tracks whether the one-time identity header has
|
|
8
|
+
* already been pinned, so it is sent exactly once per active topic, even across
|
|
9
9
|
* reconnects.
|
|
10
10
|
*
|
|
11
11
|
* State is a plain serialisable map persisted beside the daemon state files;
|
|
@@ -65,20 +65,25 @@ export class TopicRegistry {
|
|
|
65
65
|
return this.byTopic.get(topicId);
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
/** All session ids with a persisted topic record. */
|
|
69
|
+
sessionIds(): string[] {
|
|
70
|
+
return [...this.topics.keys()];
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
/** The existing topic record for a session, if any. */
|
|
69
74
|
get(sessionId: string): TopicRecord | undefined {
|
|
70
75
|
return this.topics.get(sessionId);
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
/**
|
|
74
|
-
* Return the existing topic for `sessionId`, or create one via
|
|
75
|
-
* (called only on first use).
|
|
76
|
-
* returned without invoking `create`.
|
|
79
|
+
* Return the existing active topic for `sessionId`, or create one via
|
|
80
|
+
* `create` (called only on first use).
|
|
77
81
|
*/
|
|
78
82
|
async getOrCreateTopic(
|
|
79
83
|
sessionId: string,
|
|
80
84
|
create: () => Promise<string>,
|
|
81
85
|
now: () => number = Date.now,
|
|
86
|
+
name?: string,
|
|
82
87
|
): Promise<TopicRecord> {
|
|
83
88
|
const existing = this.topics.get(sessionId);
|
|
84
89
|
if (existing) return existing;
|
|
@@ -90,7 +95,7 @@ export class TopicRegistry {
|
|
|
90
95
|
if (pending) return pending;
|
|
91
96
|
const promise = (async () => {
|
|
92
97
|
const topicId = await create();
|
|
93
|
-
const record: TopicRecord = { topicId, identitySent: false, createdAt: now() };
|
|
98
|
+
const record: TopicRecord = { topicId, name, identitySent: false, createdAt: now() };
|
|
94
99
|
this.topics.set(sessionId, record);
|
|
95
100
|
this.byTopic.set(topicId, sessionId);
|
|
96
101
|
return record;
|
|
@@ -126,6 +131,15 @@ export class TopicRegistry {
|
|
|
126
131
|
return true;
|
|
127
132
|
}
|
|
128
133
|
|
|
134
|
+
/** Remove a session topic record after Telegram deletes the topic. */
|
|
135
|
+
delete(sessionId: string): boolean {
|
|
136
|
+
const record = this.topics.get(sessionId);
|
|
137
|
+
if (!record) return false;
|
|
138
|
+
this.topics.delete(sessionId);
|
|
139
|
+
this.byTopic.delete(record.topicId);
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
129
143
|
/** Serialise for atomic persistence beside the daemon state. */
|
|
130
144
|
serialize(): TopicRegistryState {
|
|
131
145
|
return { topics: Object.fromEntries(this.topics) };
|
|
@@ -36,8 +36,8 @@ This mode activates only when the assignment explicitly labels Executor as Ultra
|
|
|
36
36
|
|
|
37
37
|
When active:
|
|
38
38
|
- Start from the approved plan/spec/acceptance criteria, then user-facing contracts, then implementation code only as supporting evidence. Treat plan/code mismatches as blockers.
|
|
39
|
-
- Exercise the real user-facing invocation rather than inspecting internals alone. Live artifacts must be runtime-valid: GUI/web needs a real automation transcript plus non-uniform screenshot; CLI needs executed argv-only replay; native/desktop/TUI needs a real screenshot, PTY capture with control codes, or app-automation transcript. `inlineEvidence` is supplemental only and is never sole proof for live surfaces.
|
|
40
|
-
- For CLI evidence, emit argv-only replay JSON with `schemaVersion: 1`, `kind: "cli-replay"`, `replaySafe: true`, and `command` as a string array. Use only allowlisted deterministic executables/arguments
|
|
39
|
+
- Exercise the real user-facing invocation rather than inspecting internals alone. Live artifacts must be runtime-valid: GUI/web needs a real automation transcript plus non-uniform screenshot; CLI needs executed argv-only replay; native/desktop/TUI needs a real screenshot, PTY capture with control codes, or app-automation transcript. API/package surfaces need a real artifact file or typed receipt whose artifact `kind` contains `api`, `package`, `consumer`, `black-box`, or `test-report`; good kinds include `api-package-test-report`, `package-consumer-report`, and `black-box-api-receipt`. Algorithm/math surfaces need a real artifact file or typed receipt whose artifact `kind` contains `property`, `boundary`, `edge`, `adversarial`, `failure`, `math`, `algorithm`, or `test-report`; good kinds include `property-test-report` and `algorithm-boundary-report`. `inlineEvidence` is supplemental only and is never sole proof for live surfaces.
|
|
40
|
+
- For CLI evidence, emit argv-only replay JSON with `schemaVersion: 1`, `kind: "cli-replay"`, `replaySafe: true`, and `command` as a string array. Use only allowlisted deterministic executables/arguments: `bun --version`, `node --version`, deterministic `bun/node -e "console.log(...)"`, `npm|pnpm|yarn --version`, `npm|pnpm|yarn list`, read-only `git status|rev-parse|merge-base|diff|show|log` with safe args, and `gjc read|status`. Mark any other command with audited `replayExempt` metadata plus a valid structural fallback artifact. `replayExempt` must use exact fields `reasonCode`, `reason`, `approvedBy`, and `fallbackArtifactRefs`; allowed `reasonCode` values are exactly `unsafe_side_effect`, `requires_credentials`, `requires_network`, `non_deterministic_external`, `destructive`, `interactive_only`, and `platform_unavailable`.
|
|
41
41
|
- Native/TUI evidence must be structural, not prose-only: screenshot, app transcript, or PTY artifact with terminal control codes.
|
|
42
42
|
- Do not call the `ask` tool while an Ultragoal run is active; record unresolved decisions with `gjc ultragoal record-review-blockers`.
|
|
43
43
|
- Try to break the work with adversarial cases, not just happy-path confirmations.
|
|
@@ -24,6 +24,38 @@ import { toJsonRpcError } from "../../runtime-mcp/types";
|
|
|
24
24
|
*/
|
|
25
25
|
const CLOSE_WAIT_MS = 1_000;
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Build a minimal environment for a no-inherit stdio MCP child. Only OS-level
|
|
29
|
+
* keys needed to locate/run an interpreter (PATH, HOME, temp, locale, and the
|
|
30
|
+
* Windows system essentials) are copied from the host; everything else
|
|
31
|
+
* (API keys, tokens, secrets) is withheld. Explicit `env` overrides win.
|
|
32
|
+
*/
|
|
33
|
+
function buildMinimalStdioEnv(explicit?: Record<string, string>): Record<string, string> {
|
|
34
|
+
const allow = [
|
|
35
|
+
"PATH",
|
|
36
|
+
"HOME",
|
|
37
|
+
"TMPDIR",
|
|
38
|
+
"TEMP",
|
|
39
|
+
"TMP",
|
|
40
|
+
"LANG",
|
|
41
|
+
"LC_ALL",
|
|
42
|
+
"LC_CTYPE",
|
|
43
|
+
"SHELL",
|
|
44
|
+
"USER",
|
|
45
|
+
"SystemRoot",
|
|
46
|
+
"SYSTEMROOT",
|
|
47
|
+
"PATHEXT",
|
|
48
|
+
"COMSPEC",
|
|
49
|
+
"WINDIR",
|
|
50
|
+
];
|
|
51
|
+
const env: Record<string, string> = {};
|
|
52
|
+
for (const key of allow) {
|
|
53
|
+
const value = Bun.env[key];
|
|
54
|
+
if (typeof value === "string") env[key] = value;
|
|
55
|
+
}
|
|
56
|
+
return { ...env, ...explicit };
|
|
57
|
+
}
|
|
58
|
+
|
|
27
59
|
export class StdioTransport implements MCPTransport {
|
|
28
60
|
#process: OwnedProcess | null = null;
|
|
29
61
|
#pendingRequests = new Map<
|
|
@@ -63,10 +95,12 @@ export class StdioTransport implements MCPTransport {
|
|
|
63
95
|
if (this.#connected) return;
|
|
64
96
|
|
|
65
97
|
const args = this.config.args ?? [];
|
|
66
|
-
const env =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
98
|
+
const env = this.config.noInheritEnv
|
|
99
|
+
? buildMinimalStdioEnv(this.config.env)
|
|
100
|
+
: {
|
|
101
|
+
...Bun.env,
|
|
102
|
+
...this.config.env,
|
|
103
|
+
};
|
|
70
104
|
|
|
71
105
|
this.#process = spawnOwnedProcess([this.config.command, ...args], {
|
|
72
106
|
cwd: this.config.cwd ?? getProjectDir(),
|
package/src/runtime-mcp/types.ts
CHANGED
|
@@ -81,6 +81,13 @@ export interface MCPStdioServerConfig extends MCPServerConfigBase {
|
|
|
81
81
|
command: string;
|
|
82
82
|
args?: string[];
|
|
83
83
|
env?: Record<string, string>;
|
|
84
|
+
/**
|
|
85
|
+
* When true, the child process is NOT given the host environment. Only a
|
|
86
|
+
* minimal OS allowlist (PATH/HOME/temp/locale) plus any explicit `env` keys
|
|
87
|
+
* are passed. Used for third-party plugin-bundle MCP servers so they cannot
|
|
88
|
+
* read host secrets from the inherited environment.
|
|
89
|
+
*/
|
|
90
|
+
noInheritEnv?: boolean;
|
|
84
91
|
cwd?: string;
|
|
85
92
|
}
|
|
86
93
|
|
package/src/sdk.ts
CHANGED
|
@@ -71,7 +71,13 @@ import {
|
|
|
71
71
|
wrapRegisteredTools,
|
|
72
72
|
} from "./extensibility/extensions";
|
|
73
73
|
import { ExtensionRuntime } from "./extensibility/extensions/loader";
|
|
74
|
+
import { type ConstrainedPluginHook, loadConstrainedPluginHooks } from "./extensibility/gjc-plugins/constrained-hooks";
|
|
74
75
|
import { resolveCurrentPhaseForParent } from "./extensibility/gjc-plugins/injection";
|
|
76
|
+
import {
|
|
77
|
+
buildPluginMcpConfigs,
|
|
78
|
+
loadAlwaysOnPluginTools,
|
|
79
|
+
renderAlwaysOnSystemAppendices,
|
|
80
|
+
} from "./extensibility/gjc-plugins/runtime-adapters";
|
|
75
81
|
import { loadActiveSubskillTools } from "./extensibility/gjc-plugins/tools";
|
|
76
82
|
import { loadSkills, type Skill, type SkillWarning, setActiveSkills } from "./extensibility/skills";
|
|
77
83
|
import type { FileSlashCommand } from "./extensibility/slash-commands";
|
|
@@ -746,6 +752,27 @@ function createCustomToolsExtension(tools: CustomTool[]): ExtensionFactory {
|
|
|
746
752
|
};
|
|
747
753
|
}
|
|
748
754
|
|
|
755
|
+
export function createPluginHooksExtension(hooks: ConstrainedPluginHook[]): ExtensionFactory {
|
|
756
|
+
return api => {
|
|
757
|
+
for (const hook of hooks) {
|
|
758
|
+
// Constrained plugin hooks register exactly their declared event handler
|
|
759
|
+
// through the standard extension API; the loader already denied every
|
|
760
|
+
// session-mutation/command/exec capability at load time. At execution we
|
|
761
|
+
// additionally enforce the declared `target`: a tool-scoped hook only
|
|
762
|
+
// fires for its declared tool, never for arbitrary tool events.
|
|
763
|
+
const target = hook.target;
|
|
764
|
+
const handler = target
|
|
765
|
+
? (event: { toolName?: string; tool?: { name?: string }; name?: string }, ...rest: unknown[]) => {
|
|
766
|
+
const toolName = event?.toolName ?? event?.tool?.name ?? event?.name;
|
|
767
|
+
if (toolName !== target) return undefined;
|
|
768
|
+
return (hook.handler as (...a: unknown[]) => unknown)(event, ...rest);
|
|
769
|
+
}
|
|
770
|
+
: hook.handler;
|
|
771
|
+
(api.on as (event: string, handler: (...args: unknown[]) => unknown) => void)(hook.event, handler);
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
|
|
749
776
|
// Factory
|
|
750
777
|
|
|
751
778
|
/**
|
|
@@ -1231,6 +1258,13 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1231
1258
|
get model() {
|
|
1232
1259
|
return agent?.state.model ?? model;
|
|
1233
1260
|
},
|
|
1261
|
+
get serviceTier() {
|
|
1262
|
+
// Live parent service-tier intent (e.g. runtime `/fast on|off`), inherited
|
|
1263
|
+
// by `inherit` subagents. Only fall back to the startup tier when there is
|
|
1264
|
+
// no live agent yet — never `??`, or an intentional `/fast off`
|
|
1265
|
+
// (serviceTier === undefined) would be resurrected to the startup value.
|
|
1266
|
+
return agent ? agent.serviceTier : initialServiceTier;
|
|
1267
|
+
},
|
|
1234
1268
|
getAgentId: () => resolvedAgentId,
|
|
1235
1269
|
bashAllowedPrefixes: options.bashAllowedPrefixes,
|
|
1236
1270
|
bashRestrictionProfile: options.bashRestrictionProfile,
|
|
@@ -1325,14 +1359,13 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1325
1359
|
|
|
1326
1360
|
// MCP runtime discovery is quarantined for the GJC surface. Keep an
|
|
1327
1361
|
// explicitly supplied manager only for legacy in-process callers that own
|
|
1328
|
-
// lifecycle themselves; never discover project/user MCP configs here.
|
|
1329
|
-
|
|
1362
|
+
// lifecycle themselves; never discover project/user MCP configs here. The
|
|
1363
|
+
// owned manager for always-on plugin-bundle MCP servers is created further
|
|
1364
|
+
// below, after `customTools` is populated, so its tools can be surfaced as
|
|
1365
|
+
// always-on tools per the plugin product contract.
|
|
1366
|
+
let mcpManager: MCPManager | undefined = options.mcpManager;
|
|
1367
|
+
let ownsMcpManager = false;
|
|
1330
1368
|
const customTools: CustomTool[] = [];
|
|
1331
|
-
// Only top-level sessions own the global MCPManager. Subagents already
|
|
1332
|
-
// receive the parent's manager via `options.mcpManager`, and reassigning
|
|
1333
|
-
// the singleton to the same value is a no-op \u2014 keep the gate explicit
|
|
1334
|
-
// to mirror the AsyncJobManager ownership rule.
|
|
1335
|
-
if (mcpManager && !options.parentTaskPrefix) MCPManager.setInstance(mcpManager);
|
|
1336
1369
|
|
|
1337
1370
|
// Add image tools when the active model or configured image providers can generate images.
|
|
1338
1371
|
const imageGenTools = await logger.time("getImageGenTools", () => getImageGenTools(modelRegistry, model));
|
|
@@ -1386,6 +1419,84 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1386
1419
|
}
|
|
1387
1420
|
}
|
|
1388
1421
|
|
|
1422
|
+
// Always-on GJC plugin bundle tools (validated registry surfaces). This is
|
|
1423
|
+
// additive and a no-op when no plugins are installed for the cwd. Surfaces
|
|
1424
|
+
// are hash-verified and collision-checked; declared names are authoritative.
|
|
1425
|
+
try {
|
|
1426
|
+
const pluginToolResult = await loadAlwaysOnPluginTools({
|
|
1427
|
+
cwd,
|
|
1428
|
+
reservedToolNames: [...getReservedSubskillToolNames(), ...customTools.map(tool => tool.name)],
|
|
1429
|
+
});
|
|
1430
|
+
if (pluginToolResult.tools.length > 0) customTools.push(...pluginToolResult.tools);
|
|
1431
|
+
for (const q of pluginToolResult.quarantine) {
|
|
1432
|
+
logger.warn("Quarantined GJC plugin surface", { plugin: q.plugin, surface: q.surfaceId, code: q.code });
|
|
1433
|
+
}
|
|
1434
|
+
} catch (error) {
|
|
1435
|
+
logger.warn("Failed to load always-on GJC plugin tools", { error });
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// Always-on GJC plugin-bundle MCP servers. Top-level sessions own a manager
|
|
1439
|
+
// and connect the validated servers; subagents inherit the parent's manager
|
|
1440
|
+
// via options.mcpManager and never spawn their own (prevents duplicate
|
|
1441
|
+
// processes and leaks). Per the plugin product contract, connected MCP tools
|
|
1442
|
+
// are surfaced as always-on tools rather than gated behind MCP selection.
|
|
1443
|
+
if (!mcpManager && !options.parentTaskPrefix) {
|
|
1444
|
+
try {
|
|
1445
|
+
const { configs, quarantine } = await buildPluginMcpConfigs({ cwd });
|
|
1446
|
+
for (const q of quarantine) {
|
|
1447
|
+
logger.warn("Quarantined GJC plugin MCP", { plugin: q.plugin, surface: q.surfaceId, code: q.code });
|
|
1448
|
+
}
|
|
1449
|
+
if (Object.keys(configs).length > 0) {
|
|
1450
|
+
const owned = new MCPManager(cwd);
|
|
1451
|
+
try {
|
|
1452
|
+
const sources = Object.fromEntries(
|
|
1453
|
+
Object.keys(configs).map(name => [
|
|
1454
|
+
name,
|
|
1455
|
+
{ provider: "gjc-plugins", providerName: "GJC plugin bundle", level: "project" as const },
|
|
1456
|
+
]),
|
|
1457
|
+
);
|
|
1458
|
+
const result = await owned.connectServers(configs, sources as never);
|
|
1459
|
+
for (const [server, err] of result.errors) {
|
|
1460
|
+
logger.warn("GJC plugin MCP connect failed", { path: `mcp:${server}`, error: err });
|
|
1461
|
+
}
|
|
1462
|
+
if (result.connectedServers.length > 0) {
|
|
1463
|
+
mcpManager = owned;
|
|
1464
|
+
ownsMcpManager = true;
|
|
1465
|
+
customTools.push(...(result.tools as CustomTool[]));
|
|
1466
|
+
} else {
|
|
1467
|
+
await owned.disconnectAll().catch(() => {});
|
|
1468
|
+
}
|
|
1469
|
+
} catch (error) {
|
|
1470
|
+
// Avoid leaking partially-started server processes on failure.
|
|
1471
|
+
await owned.disconnectAll().catch(() => {});
|
|
1472
|
+
throw error;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
} catch (error) {
|
|
1476
|
+
logger.warn("Failed to wire GJC plugin MCP servers", { error });
|
|
1477
|
+
}
|
|
1478
|
+
} else if (options.parentTaskPrefix) {
|
|
1479
|
+
// Subagent: inherit the parent's always-on plugin MCP tools WITHOUT
|
|
1480
|
+
// owning the manager (no connect, no callbacks, no disposal). The
|
|
1481
|
+
// top-level session installed its manager as the process-global
|
|
1482
|
+
// instance; reading getTools() surfaces the same always-on tools so the
|
|
1483
|
+
// product decision holds for subagent sessions too.
|
|
1484
|
+
const inherited = mcpManager ?? MCPManager.instance();
|
|
1485
|
+
if (inherited) {
|
|
1486
|
+
try {
|
|
1487
|
+
const inheritedTools = inherited.getTools();
|
|
1488
|
+
if (inheritedTools.length > 0) customTools.push(...(inheritedTools as CustomTool[]));
|
|
1489
|
+
} catch (error) {
|
|
1490
|
+
logger.warn("Failed to inherit plugin MCP tools in subagent", { error });
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
}
|
|
1494
|
+
// Only top-level sessions own the global MCPManager. Subagents already
|
|
1495
|
+
// receive the parent's manager via options.mcpManager; reassigning the
|
|
1496
|
+
// singleton to the same value is a no-op. Keep the gate explicit to mirror
|
|
1497
|
+
// the AsyncJobManager ownership rule.
|
|
1498
|
+
if (mcpManager && !options.parentTaskPrefix) MCPManager.setInstance(mcpManager);
|
|
1499
|
+
|
|
1389
1500
|
// Custom tool and extension discovery is quarantined from the public GJC utility surface.
|
|
1390
1501
|
// Explicit SDK extension factories are still honored; callers use them to
|
|
1391
1502
|
// register in-process tools/providers without enabling filesystem discovery.
|
|
@@ -1393,6 +1504,20 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1393
1504
|
if (customTools.length > 0) {
|
|
1394
1505
|
inlineExtensions.push(createCustomToolsExtension(customTools));
|
|
1395
1506
|
}
|
|
1507
|
+
|
|
1508
|
+
// Always-on constrained plugin hooks (validated registry surfaces). Additive
|
|
1509
|
+
// and a no-op without installed plugins; the loader denies all dangerous APIs.
|
|
1510
|
+
try {
|
|
1511
|
+
const pluginHookResult = await loadConstrainedPluginHooks({ cwd });
|
|
1512
|
+
if (pluginHookResult.hooks.length > 0) {
|
|
1513
|
+
inlineExtensions.push(createPluginHooksExtension(pluginHookResult.hooks));
|
|
1514
|
+
}
|
|
1515
|
+
for (const q of pluginHookResult.quarantine) {
|
|
1516
|
+
logger.warn("Quarantined GJC plugin hook", { plugin: q.plugin, surface: q.surfaceId, code: q.code });
|
|
1517
|
+
}
|
|
1518
|
+
} catch (error) {
|
|
1519
|
+
logger.warn("Failed to load constrained GJC plugin hooks", { error });
|
|
1520
|
+
}
|
|
1396
1521
|
let notificationCfg: NotificationConfig | undefined;
|
|
1397
1522
|
try {
|
|
1398
1523
|
notificationCfg = getNotificationConfig(Settings.instance);
|
|
@@ -1670,6 +1795,12 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1670
1795
|
}
|
|
1671
1796
|
appendPrompt = parts.join("\n\n");
|
|
1672
1797
|
}
|
|
1798
|
+
let pluginSystemAppendices = "";
|
|
1799
|
+
try {
|
|
1800
|
+
pluginSystemAppendices = await renderAlwaysOnSystemAppendices({ cwd });
|
|
1801
|
+
} catch (error) {
|
|
1802
|
+
logger.warn("Failed to render GJC plugin system appendices", { error });
|
|
1803
|
+
}
|
|
1673
1804
|
const defaultPrompt = await buildSystemPromptInternal({
|
|
1674
1805
|
cwd,
|
|
1675
1806
|
skills,
|
|
@@ -1680,6 +1811,7 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
1680
1811
|
alwaysApplyRules,
|
|
1681
1812
|
skillsSettings: settings.getGroup("skills"),
|
|
1682
1813
|
appendSystemPrompt: appendPrompt,
|
|
1814
|
+
pluginAppendices: pluginSystemAppendices,
|
|
1683
1815
|
repeatToolDescriptions,
|
|
1684
1816
|
intentField,
|
|
1685
1817
|
mcpDiscoveryMode: false,
|
|
@@ -2036,6 +2168,10 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2036
2168
|
// AsyncJobManager on teardown; subagents inherit the parent's and
|
|
2037
2169
|
// **MUST NOT** tear it down.
|
|
2038
2170
|
ownedAsyncJobManager: asyncJobManager,
|
|
2171
|
+
// Only the owned plugin-bundle MCP manager is torn down on dispose;
|
|
2172
|
+
// subagents/callers that merely observe the global must not (see
|
|
2173
|
+
// AgentSession.dispose).
|
|
2174
|
+
ownedMcpManager: ownsMcpManager ? mcpManager : undefined,
|
|
2039
2175
|
scopedModels: options.scopedModels,
|
|
2040
2176
|
promptTemplates,
|
|
2041
2177
|
slashCommands,
|
|
@@ -2200,9 +2336,20 @@ export async function createAgentSession(options: CreateAgentSessionOptions = {}
|
|
|
2200
2336
|
// Wire MCP manager callbacks to session for reactive tool updates.
|
|
2201
2337
|
// Skip when reusing a parent's manager — the parent owns the callbacks.
|
|
2202
2338
|
if (mcpManager && !options.mcpManager) {
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2339
|
+
// The owned plugin-bundle manager surfaces its tools as always-on custom
|
|
2340
|
+
// tools (registered above), so it must NOT drive refreshMCPTools — that
|
|
2341
|
+
// path strips MCP bridge tools and re-gates them behind MCP selection,
|
|
2342
|
+
// which would deactivate the always-on plugin tools. Reactive tool
|
|
2343
|
+
// updates remain wired only for externally supplied managers.
|
|
2344
|
+
// The owned manager is disconnected by AgentSession.dispose via
|
|
2345
|
+
// ownedMcpManager; only externally supplied managers wire reactive
|
|
2346
|
+
// refreshMCPTools (the owned always-on path must not, or it would
|
|
2347
|
+
// deactivate the plugin tools).
|
|
2348
|
+
if (!ownsMcpManager) {
|
|
2349
|
+
mcpManager.setOnToolsChanged(tools => {
|
|
2350
|
+
void session.refreshMCPTools(tools);
|
|
2351
|
+
});
|
|
2352
|
+
}
|
|
2206
2353
|
// Wire prompt refresh → rebuild MCP prompt slash commands
|
|
2207
2354
|
mcpManager.setOnPromptsChanged(serverName => {
|
|
2208
2355
|
const promptCommands = buildMCPPromptCommands(mcpManager);
|