@cjhyy/code-shell-core 0.7.0-beta.1 → 0.7.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/dist/cc-orchestrator/agent-adapter.d.ts +2 -0
- package/dist/cc-orchestrator/agent-adapter.js +4 -0
- package/dist/cc-orchestrator/codex-session-history.d.ts +14 -1
- package/dist/cc-orchestrator/codex-session-history.js +64 -4
- package/dist/cc-orchestrator/external-agent-changes.js +22 -5
- package/dist/cc-orchestrator/external-agent-driver.d.ts +1 -1
- package/dist/cc-orchestrator/external-agent-driver.js +202 -38
- package/dist/cc-orchestrator/session-history.d.ts +35 -0
- package/dist/cc-orchestrator/session-history.js +96 -13
- package/dist/credentials/access.d.ts +1 -0
- package/dist/credentials/access.js +2 -0
- package/dist/credentials/index.d.ts +2 -1
- package/dist/credentials/index.js +1 -0
- package/dist/credentials/oauth.d.ts +20 -0
- package/dist/credentials/oauth.js +114 -0
- package/dist/credentials/store.d.ts +1 -0
- package/dist/credentials/store.js +3 -1
- package/dist/credentials/types.d.ts +47 -1
- package/dist/engine/engine.d.ts +6 -2
- package/dist/engine/engine.js +159 -192
- package/dist/engine/goal.d.ts +17 -0
- package/dist/engine/goal.js +16 -6
- package/dist/engine/input-attachments.js +156 -13
- package/dist/engine/run-image-input.d.ts +22 -0
- package/dist/engine/run-image-input.js +195 -0
- package/dist/engine/steer-queue.d.ts +3 -1
- package/dist/engine/steer-queue.js +10 -2
- package/dist/engine/turn-loop.d.ts +30 -1
- package/dist/engine/turn-loop.js +112 -17
- package/dist/hooks/goal-stop-hook.d.ts +33 -1
- package/dist/hooks/goal-stop-hook.js +202 -34
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/preset/index.js +14 -4
- package/dist/protocol/server.js +1 -1
- package/dist/protocol/types.d.ts +2 -0
- package/dist/session/session-manager.js +34 -1
- package/dist/tool-system/builtin/agent-notifications.d.ts +11 -4
- package/dist/tool-system/builtin/agent-notifications.js +19 -7
- package/dist/tool-system/builtin/background-jobs.d.ts +25 -5
- package/dist/tool-system/builtin/background-jobs.js +105 -7
- package/dist/tool-system/builtin/cron-list.definition.d.ts +3 -0
- package/dist/tool-system/builtin/cron-list.definition.js +6 -0
- package/dist/tool-system/builtin/cron.d.ts +1 -2
- package/dist/tool-system/builtin/cron.js +9 -7
- package/dist/tool-system/builtin/drive-claude-code.d.ts +7 -0
- package/dist/tool-system/builtin/drive-claude-code.js +307 -20
- package/dist/tool-system/builtin/index.js +15 -3
- package/dist/tool-system/builtin/sleep.d.ts +1 -2
- package/dist/tool-system/builtin/sleep.definition.d.ts +8 -0
- package/dist/tool-system/builtin/sleep.definition.js +28 -0
- package/dist/tool-system/builtin/sleep.js +1 -22
- package/dist/tool-system/context.d.ts +18 -0
- package/dist/tool-system/mcp-manager.d.ts +14 -2
- package/dist/tool-system/mcp-manager.js +56 -7
- package/dist/types.d.ts +23 -7
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js"
|
|
|
8
8
|
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
9
9
|
import { logger } from "../logging/logger.js";
|
|
10
10
|
import { getCredentialAccess } from "../credentials/access.js";
|
|
11
|
+
import { buildOAuthRefreshRequest, oauthCredentialStatus, parseOAuthCredentialSecret, } from "../credentials/oauth.js";
|
|
11
12
|
import { ENV_ALLOWLIST } from "../runtime/spawn-common.js";
|
|
12
13
|
import { mkdir, readdir, unlink, writeFile } from "node:fs/promises";
|
|
13
14
|
import { join } from "node:path";
|
|
@@ -73,14 +74,14 @@ export function buildStdioEnv(serverName, config) {
|
|
|
73
74
|
* base; env-sourced secrets (`bearerTokenEnvVar`, `envHeaders`) layer on top
|
|
74
75
|
* and win on conflict. Pure + exported for unit testing.
|
|
75
76
|
*/
|
|
76
|
-
export function buildHttpHeaders(serverName, config, resolveCredential) {
|
|
77
|
+
export function buildHttpHeaders(serverName, config, resolveCredential, options = {}) {
|
|
77
78
|
const headers = { ...(config.headers ?? {}) };
|
|
78
79
|
if (config.credentialRef) {
|
|
79
|
-
const
|
|
80
|
-
if (
|
|
80
|
+
const credential = normalizeResolvedMcpCredential(resolveCredential?.(config.credentialRef));
|
|
81
|
+
if (!credential || credential.secret === "") {
|
|
81
82
|
throw new Error(`MCP server "${serverName}": credential "${config.credentialRef}" not found or empty`);
|
|
82
83
|
}
|
|
83
|
-
headers["Authorization"] = `Bearer ${
|
|
84
|
+
headers["Authorization"] = `Bearer ${bearerTokenFromMcpCredential(serverName, config.credentialRef, credential, options)}`;
|
|
84
85
|
}
|
|
85
86
|
else if (config.bearerTokenEnvVar) {
|
|
86
87
|
headers["Authorization"] = `Bearer ${readRequiredEnv(serverName, "bearerTokenEnvVar", config.bearerTokenEnvVar)}`;
|
|
@@ -90,19 +91,67 @@ export function buildHttpHeaders(serverName, config, resolveCredential) {
|
|
|
90
91
|
}
|
|
91
92
|
return headers;
|
|
92
93
|
}
|
|
93
|
-
|
|
94
|
+
function normalizeResolvedMcpCredential(value) {
|
|
95
|
+
if (typeof value === "string")
|
|
96
|
+
return { secret: value };
|
|
97
|
+
if (!value)
|
|
98
|
+
return undefined;
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
export function bearerTokenFromMcpCredential(serverName, credentialId, credential, options = {}) {
|
|
102
|
+
if (credential.type === undefined)
|
|
103
|
+
return credential.secret;
|
|
104
|
+
if (credential.type !== "oauth") {
|
|
105
|
+
if (credential.type !== "token" && credential.type !== "link") {
|
|
106
|
+
throw new Error(`MCP server "${serverName}": credential "${credentialId}" type "${credential.type}" cannot be used as a bearer token`);
|
|
107
|
+
}
|
|
108
|
+
try {
|
|
109
|
+
const parsed = JSON.parse(credential.secret);
|
|
110
|
+
if (parsed !== null && typeof parsed === "object") {
|
|
111
|
+
throw new Error(`MCP server "${serverName}": credential "${credentialId}" resolved to a structured secret that does not match token metadata; refusing bearer injection`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
if (err instanceof SyntaxError)
|
|
116
|
+
return credential.secret;
|
|
117
|
+
throw err;
|
|
118
|
+
}
|
|
119
|
+
return credential.secret;
|
|
120
|
+
}
|
|
121
|
+
const secret = parseOAuthCredentialSecret(credential.secret);
|
|
122
|
+
const status = oauthCredentialStatus(secret, {
|
|
123
|
+
now: options.now,
|
|
124
|
+
skewMs: options.oauthRefreshSkewMs,
|
|
125
|
+
});
|
|
126
|
+
if (status.state === "expired") {
|
|
127
|
+
const refresh = buildOAuthRefreshRequest(credentialId, secret);
|
|
128
|
+
const refreshHint = refresh
|
|
129
|
+
? "refresh data is present, but automatic OAuth refresh is reserved and not wired yet"
|
|
130
|
+
: "missing refreshToken or tokenEndpoint for automatic refresh";
|
|
131
|
+
throw new Error(`MCP server "${serverName}": oauth credential "${credentialId}" access token expired; ${refreshHint}`);
|
|
132
|
+
}
|
|
133
|
+
return secret.accessToken;
|
|
134
|
+
}
|
|
135
|
+
export async function buildHttpHeadersWithCredentialAccess(serverName, config, access = getCredentialAccess(), options = {}) {
|
|
94
136
|
if (!config.credentialRef)
|
|
95
|
-
return buildHttpHeaders(serverName, config);
|
|
137
|
+
return buildHttpHeaders(serverName, config, undefined, options);
|
|
96
138
|
if (!access.resolveValue) {
|
|
97
139
|
throw new Error(`MCP server "${serverName}": credential "${config.credentialRef}" not found or empty`);
|
|
98
140
|
}
|
|
141
|
+
const meta = access.resolveMeta?.(undefined, config.credentialRef, "full");
|
|
142
|
+
if (!meta) {
|
|
143
|
+
throw new Error(`MCP server "${serverName}": credential "${config.credentialRef}" metadata is unavailable; refusing bearer injection`);
|
|
144
|
+
}
|
|
145
|
+
if (meta.type !== "token" && meta.type !== "link" && meta.type !== "oauth") {
|
|
146
|
+
throw new Error(`MCP server "${serverName}": credential "${config.credentialRef}" type "${meta.type}" cannot be used as a bearer token`);
|
|
147
|
+
}
|
|
99
148
|
const secret = await access.resolveValue({
|
|
100
149
|
cwd: undefined,
|
|
101
150
|
id: config.credentialRef,
|
|
102
151
|
scope: "full",
|
|
103
152
|
purpose: "mcp",
|
|
104
153
|
});
|
|
105
|
-
return buildHttpHeaders(serverName, config, (id) => id === config.credentialRef ? secret : undefined);
|
|
154
|
+
return buildHttpHeaders(serverName, config, (id) => id === config.credentialRef ? { secret, type: meta?.type, label: meta?.label } : undefined, options);
|
|
106
155
|
}
|
|
107
156
|
/**
|
|
108
157
|
* Infer the transport when the config doesn't name one: a url-only entry is
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Core type definitions for the code-shell orchestration framework.
|
|
3
3
|
*/
|
|
4
|
-
import type { GoalConfig } from "./engine/goal.js";
|
|
4
|
+
import type { GoalConfig, GoalTerminal } from "./engine/goal.js";
|
|
5
5
|
export interface ContentBlock {
|
|
6
6
|
type: "text" | "tool_use" | "tool_result" | "image" | "reasoning";
|
|
7
7
|
text?: string;
|
|
@@ -133,7 +133,7 @@ export interface RegisteredTool {
|
|
|
133
133
|
*/
|
|
134
134
|
timeoutMs?: number;
|
|
135
135
|
}
|
|
136
|
-
export type TranscriptEventType = "message" | "tool_use" | "tool_result" | "summary" | "content_replace" | "file_history" | "plan_operation" | "session_meta" | "subagent" | "turn_boundary" | "goal_progress" | "turn_stopped" | "error";
|
|
136
|
+
export type TranscriptEventType = "message" | "tool_use" | "tool_result" | "summary" | "content_replace" | "file_history" | "plan_operation" | "session_meta" | "subagent" | "external_file_changes" | "turn_boundary" | "goal_progress" | "turn_stopped" | "error";
|
|
137
137
|
export interface TranscriptEvent {
|
|
138
138
|
id: string;
|
|
139
139
|
type: TranscriptEventType;
|
|
@@ -242,6 +242,12 @@ export interface SessionState {
|
|
|
242
242
|
* baselines reset (matching CC). See engine.run goal-resolution.
|
|
243
243
|
*/
|
|
244
244
|
activeGoal?: GoalConfig;
|
|
245
|
+
/**
|
|
246
|
+
* Last force-terminated goal instance. Kept separately from activeGoal so an
|
|
247
|
+
* old whole-state writer cannot make that same exhausted goal armable again.
|
|
248
|
+
* Optional for backward compatibility with pre-tombstone state.json files.
|
|
249
|
+
*/
|
|
250
|
+
goalTerminal?: GoalTerminal;
|
|
245
251
|
}
|
|
246
252
|
export interface TokenUsage {
|
|
247
253
|
promptTokens: number;
|
|
@@ -506,7 +512,7 @@ export type StreamEvent = {
|
|
|
506
512
|
agentId: string;
|
|
507
513
|
name?: string;
|
|
508
514
|
description: string;
|
|
509
|
-
status: "completed" | "failed";
|
|
515
|
+
status: "completed" | "failed" | "cancelled";
|
|
510
516
|
/**
|
|
511
517
|
* What kind of background work this was. Lets UIs localize the
|
|
512
518
|
* completion toast (e.g. a shell shows "命令完成" not the raw English
|
|
@@ -518,8 +524,16 @@ export type StreamEvent = {
|
|
|
518
524
|
command?: string;
|
|
519
525
|
/** Final assistant text (status === "completed" only). */
|
|
520
526
|
finalText?: string;
|
|
521
|
-
/** Error message (status === "failed" only). */
|
|
527
|
+
/** Error message (status === "failed" or "cancelled" only). */
|
|
522
528
|
error?: string;
|
|
529
|
+
/** External Claude/Codex session id, when workKind === "cc". */
|
|
530
|
+
ccSessionId?: string;
|
|
531
|
+
/** Files attributed to an external DriveAgent transcript. */
|
|
532
|
+
changedFiles?: string[];
|
|
533
|
+
/** Working directory used to canonicalize relative/absolute path aliases. */
|
|
534
|
+
cwd?: string;
|
|
535
|
+
/** Client id of the real user turn that launched this background work. */
|
|
536
|
+
originClientMessageId?: string;
|
|
523
537
|
/** When the bg agent finished (Date.now() value). */
|
|
524
538
|
enqueuedAt: number;
|
|
525
539
|
};
|
|
@@ -652,9 +666,10 @@ export interface MCPServerConfig {
|
|
|
652
666
|
*/
|
|
653
667
|
envHeaders?: Record<string, string>;
|
|
654
668
|
/**
|
|
655
|
-
* (HTTP) id of a stored credential (
|
|
656
|
-
*
|
|
657
|
-
* the secret is never stored in
|
|
669
|
+
* (HTTP) id of a stored credential (token/link/oauth) to use as Bearer auth.
|
|
670
|
+
* OAuth credentials inject their current access token. Resolved at connect
|
|
671
|
+
* time via CredentialStore; the secret is never stored in MCP config. Wins
|
|
672
|
+
* over bearerTokenEnvVar.
|
|
658
673
|
*/
|
|
659
674
|
credentialRef?: string;
|
|
660
675
|
/**
|
|
@@ -677,6 +692,7 @@ export interface MCPServerConfig {
|
|
|
677
692
|
export interface MCPServerOverride {
|
|
678
693
|
env?: Record<string, string>;
|
|
679
694
|
envVars?: string[];
|
|
695
|
+
/** (HTTP) id of a stored token/link/oauth credential used as Bearer auth. */
|
|
680
696
|
credentialRef?: string;
|
|
681
697
|
bearerTokenEnvVar?: string;
|
|
682
698
|
envHeaders?: Record<string, string>;
|
package/package.json
CHANGED