Flatten Git service layer and switch server paths to base dir (#1255)
This commit is contained in:
1 parent
843d6d8678
commit
d415558915
17 files changed
+1534
-2249
No files matched your search
@@ -1,129 +0,0 @@
|
||||
import { query, type SDKMessage } from "@anthropic-ai/claude-agent-sdk";
|
||||
|
||||
type ProbeMode = "off" | "on";
|
||||
|
||||
async function* emptyPrompt(): AsyncGenerator<never, void, void> {}
|
||||
|
||||
function parseArgs(argv: ReadonlyArray<string>): {
|
||||
readonly mode: ProbeMode | "both";
|
||||
readonly model?: string;
|
||||
readonly cwd?: string;
|
||||
readonly prompt?: string;
|
||||
} {
|
||||
let mode: ProbeMode | "both" = "both";
|
||||
let model: string | undefined;
|
||||
let cwd: string | undefined;
|
||||
let prompt: string | undefined;
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const value = argv[index];
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
if (value === "--mode") {
|
||||
const next = argv[index + 1];
|
||||
if (next === "off" || next === "on" || next === "both") {
|
||||
mode = next;
|
||||
index += 1;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (value === "--model") {
|
||||
model = argv[index + 1];
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (value === "--cwd") {
|
||||
cwd = argv[index + 1];
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (value === "--prompt") {
|
||||
prompt = argv[index + 1] ?? prompt;
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
mode,
|
||||
...(model ? { model } : {}),
|
||||
...(cwd ? { cwd } : {}),
|
||||
...(prompt ? { prompt } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
async function runProbe(input: {
|
||||
readonly mode: ProbeMode;
|
||||
readonly model?: string;
|
||||
readonly cwd?: string;
|
||||
readonly prompt?: string;
|
||||
}): Promise<void> {
|
||||
const messages = query({
|
||||
prompt: input.prompt ?? emptyPrompt(),
|
||||
options: {
|
||||
...(input.model ? { model: input.model } : {}),
|
||||
...(input.cwd ? { cwd: input.cwd } : {}),
|
||||
persistSession: false,
|
||||
tools: [],
|
||||
permissionMode: "plan",
|
||||
includePartialMessages: true,
|
||||
...(input.mode === "on" ? { settings: { fastMode: true } } : {}),
|
||||
},
|
||||
});
|
||||
|
||||
const summary = {
|
||||
mode: input.mode,
|
||||
initFastModeState: null as string | null,
|
||||
resultFastModeState: null as string | null,
|
||||
resultSubtype: null as string | null,
|
||||
resultText: null as string | null,
|
||||
};
|
||||
|
||||
const initialization = await messages.initializationResult();
|
||||
summary.initFastModeState = initialization.fast_mode_state ?? null;
|
||||
|
||||
if (!input.prompt) {
|
||||
messages.close();
|
||||
console.log(JSON.stringify(summary, null, 2));
|
||||
return;
|
||||
}
|
||||
|
||||
for await (const message of messages) {
|
||||
handleProbeMessage(message, summary);
|
||||
}
|
||||
console.log(JSON.stringify(summary, null, 2));
|
||||
}
|
||||
|
||||
function handleProbeMessage(
|
||||
message: SDKMessage,
|
||||
summary: {
|
||||
mode: ProbeMode;
|
||||
initFastModeState: string | null;
|
||||
resultFastModeState: string | null;
|
||||
resultSubtype: string | null;
|
||||
resultText: string | null;
|
||||
},
|
||||
): void {
|
||||
if (message.type !== "result") {
|
||||
return;
|
||||
}
|
||||
summary.resultSubtype = message.subtype;
|
||||
summary.resultFastModeState = message.fast_mode_state ?? null;
|
||||
summary.resultText = message.subtype === "success" ? message.result : message.errors.join("\n");
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
const modes = args.mode === "both" ? (["off", "on"] as const) : [args.mode];
|
||||
|
||||
for (const mode of modes) {
|
||||
await runProbe({
|
||||
mode,
|
||||
...(args.model ? { model: args.model } : {}),
|
||||
...(args.cwd ? { cwd: args.cwd } : {}),
|
||||
...(args.prompt ? { prompt: args.prompt } : {}),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await main();
|
||||
@@ -1,261 +0,0 @@
|
||||
import { query, type SDKMessage, type ThinkingConfig } from "@anthropic-ai/claude-agent-sdk";
|
||||
|
||||
type ProbeCase =
|
||||
| "default"
|
||||
| "effort-low"
|
||||
| "effort-high"
|
||||
| "settings-off"
|
||||
| "settings-on"
|
||||
| "thinking-disabled"
|
||||
| "thinking-enabled";
|
||||
|
||||
function parseArgs(argv: ReadonlyArray<string>): {
|
||||
readonly model: string;
|
||||
readonly cwd?: string;
|
||||
readonly prompt: string;
|
||||
readonly cases: ReadonlyArray<ProbeCase>;
|
||||
} {
|
||||
let model = "claude-haiku-4-5";
|
||||
let cwd: string | undefined;
|
||||
let prompt =
|
||||
"Think step by step about this before answering: what is 27 multiplied by 43? Return the final number only.";
|
||||
let cases: ReadonlyArray<ProbeCase> = [
|
||||
"default",
|
||||
"effort-low",
|
||||
"effort-high",
|
||||
"settings-off",
|
||||
"settings-on",
|
||||
"thinking-disabled",
|
||||
"thinking-enabled",
|
||||
];
|
||||
|
||||
for (let index = 0; index < argv.length; index += 1) {
|
||||
const value = argv[index];
|
||||
if (!value) {
|
||||
continue;
|
||||
}
|
||||
if (value === "--model") {
|
||||
model = argv[index + 1] ?? model;
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (value === "--cwd") {
|
||||
cwd = argv[index + 1] ?? cwd;
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (value === "--prompt") {
|
||||
prompt = argv[index + 1] ?? prompt;
|
||||
index += 1;
|
||||
continue;
|
||||
}
|
||||
if (value === "--cases") {
|
||||
const next = argv[index + 1];
|
||||
if (next) {
|
||||
const requested = next
|
||||
.split(",")
|
||||
.map((entry) => entry.trim())
|
||||
.filter(
|
||||
(entry): entry is ProbeCase =>
|
||||
entry === "default" ||
|
||||
entry === "effort-low" ||
|
||||
entry === "effort-high" ||
|
||||
entry === "settings-off" ||
|
||||
entry === "settings-on" ||
|
||||
entry === "thinking-disabled" ||
|
||||
entry === "thinking-enabled",
|
||||
);
|
||||
if (requested.length > 0) {
|
||||
cases = requested;
|
||||
}
|
||||
}
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
model,
|
||||
prompt,
|
||||
...(cwd ? { cwd } : {}),
|
||||
cases,
|
||||
};
|
||||
}
|
||||
|
||||
function caseOptions(caseName: ProbeCase): {
|
||||
readonly label: ProbeCase;
|
||||
readonly effort?: "low" | "high";
|
||||
readonly settings?: { alwaysThinkingEnabled: boolean };
|
||||
readonly thinking?: ThinkingConfig;
|
||||
} {
|
||||
switch (caseName) {
|
||||
case "effort-low":
|
||||
return {
|
||||
label: caseName,
|
||||
effort: "low",
|
||||
};
|
||||
case "effort-high":
|
||||
return {
|
||||
label: caseName,
|
||||
effort: "high",
|
||||
};
|
||||
case "settings-off":
|
||||
return {
|
||||
label: caseName,
|
||||
settings: {
|
||||
alwaysThinkingEnabled: false,
|
||||
},
|
||||
};
|
||||
case "settings-on":
|
||||
return {
|
||||
label: caseName,
|
||||
settings: {
|
||||
alwaysThinkingEnabled: true,
|
||||
},
|
||||
};
|
||||
case "thinking-disabled":
|
||||
return {
|
||||
label: caseName,
|
||||
thinking: {
|
||||
type: "disabled",
|
||||
},
|
||||
};
|
||||
case "thinking-enabled":
|
||||
return {
|
||||
label: caseName,
|
||||
thinking: {
|
||||
type: "enabled",
|
||||
budgetTokens: 1024,
|
||||
},
|
||||
};
|
||||
default:
|
||||
return {
|
||||
label: caseName,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
type ProbeSummary = {
|
||||
readonly case: ProbeCase;
|
||||
readonly model: string;
|
||||
initModelInfo: {
|
||||
value: string | null;
|
||||
supportsEffort: boolean | null;
|
||||
supportsAdaptiveThinking: boolean | null;
|
||||
supportedEffortLevels: ReadonlyArray<string> | null;
|
||||
} | null;
|
||||
resultSubtype: string | null;
|
||||
resultText: string | null;
|
||||
assistantThinkingBlockCount: number;
|
||||
streamThinkingEventTypes: Record<string, number>;
|
||||
error: string | null;
|
||||
};
|
||||
|
||||
async function runCase(input: {
|
||||
readonly caseName: ProbeCase;
|
||||
readonly model: string;
|
||||
readonly cwd?: string;
|
||||
readonly prompt: string;
|
||||
}): Promise<ProbeSummary> {
|
||||
const caseConfig = caseOptions(input.caseName);
|
||||
const summary: ProbeSummary = {
|
||||
case: input.caseName,
|
||||
model: input.model,
|
||||
initModelInfo: null,
|
||||
resultSubtype: null,
|
||||
resultText: null,
|
||||
assistantThinkingBlockCount: 0,
|
||||
streamThinkingEventTypes: {},
|
||||
error: null,
|
||||
};
|
||||
|
||||
try {
|
||||
const messages = query({
|
||||
prompt: input.prompt,
|
||||
options: {
|
||||
model: input.model,
|
||||
...(input.cwd ? { cwd: input.cwd } : {}),
|
||||
persistSession: false,
|
||||
tools: [],
|
||||
permissionMode: "bypassPermissions",
|
||||
includePartialMessages: true,
|
||||
maxTurns: 1,
|
||||
...(caseConfig.effort ? { effort: caseConfig.effort } : {}),
|
||||
...(caseConfig.settings ? { settings: caseConfig.settings } : {}),
|
||||
...(caseConfig.thinking ? { thinking: caseConfig.thinking } : {}),
|
||||
},
|
||||
});
|
||||
|
||||
const initialization = await messages.initializationResult();
|
||||
const initModel =
|
||||
initialization.models.find((candidate) => candidate.value === input.model) ??
|
||||
initialization.models.find((candidate) => candidate.value.includes("haiku")) ??
|
||||
null;
|
||||
summary.initModelInfo = initModel
|
||||
? {
|
||||
value: initModel.value,
|
||||
supportsEffort: initModel.supportsEffort ?? null,
|
||||
supportsAdaptiveThinking: initModel.supportsAdaptiveThinking ?? null,
|
||||
supportedEffortLevels: initModel.supportedEffortLevels ?? null,
|
||||
}
|
||||
: null;
|
||||
|
||||
for await (const message of messages) {
|
||||
handleMessage(summary, message);
|
||||
}
|
||||
} catch (error) {
|
||||
summary.error = error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
function handleMessage(summary: ProbeSummary, message: SDKMessage): void {
|
||||
if (message.type === "stream_event") {
|
||||
const event = message.event as {
|
||||
type?: string;
|
||||
delta?: {
|
||||
type?: string;
|
||||
};
|
||||
};
|
||||
const eventType = event.delta?.type ?? event.type;
|
||||
if (typeof eventType === "string" && eventType.includes("thinking")) {
|
||||
summary.streamThinkingEventTypes[eventType] =
|
||||
(summary.streamThinkingEventTypes[eventType] ?? 0) + 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "assistant") {
|
||||
for (const block of message.message.content) {
|
||||
if (typeof block?.type === "string" && block.type.includes("thinking")) {
|
||||
summary.assistantThinkingBlockCount += 1;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type === "result") {
|
||||
summary.resultSubtype = message.subtype;
|
||||
summary.resultText = message.subtype === "success" ? message.result : message.errors.join("\n");
|
||||
}
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
const args = parseArgs(process.argv.slice(2));
|
||||
const results: ProbeSummary[] = [];
|
||||
|
||||
for (const caseName of args.cases) {
|
||||
results.push(
|
||||
await runCase({
|
||||
caseName,
|
||||
model: args.model,
|
||||
...(args.cwd ? { cwd: args.cwd } : {}),
|
||||
prompt: args.prompt,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
console.log(JSON.stringify(results, null, 2));
|
||||
}
|
||||
|
||||
await main();
|
||||
Reference in new issue
Block a user