Release 0.1.1

This commit is contained in:
Patrick Wozniak
2026-05-26 23:05:21 +02:00
parent 5d4277876b
commit cc05faa526
9 changed files with 140 additions and 25 deletions
+23 -1
View File
@@ -15,6 +15,7 @@ import {
mapFinishReason,
messagesToCC,
parseStreamEventLine,
projectSlugFromPath,
textContent,
toJsonSchema,
toolsToJson,
@@ -27,12 +28,13 @@ describe("getApiKey()", () => {
assert.equal(getApiKey({ env: { COMMANDCODE_API_KEY: "env-key" }, authPaths: [] }), "env-key")
})
it("reads apiKey, commandcode, and pi OAuth credential fields from explicit auth paths", () => {
it("reads apiKey, commandcode, pi OAuth, and official CLI credential fields", () => {
const dir = mkdtempSync(join(tmpdir(), "cc-auth-"))
try {
const first = join(dir, "first.json")
const second = join(dir, "second.json")
const oauth = join(dir, "oauth.json")
const official = join(dir, "official.json")
writeFileSync(first, JSON.stringify({ apiKey: "file-key" }))
writeFileSync(second, JSON.stringify({ commandcode: "fallback-key" }))
writeFileSync(
@@ -46,9 +48,19 @@ describe("getApiKey()", () => {
},
}),
)
writeFileSync(
official,
JSON.stringify({
"command-code": {
type: "api",
key: "official-cli-key",
},
}),
)
assert.equal(getApiKey({ env: {}, authPaths: [first, second] }), "file-key")
assert.equal(getApiKey({ env: {}, authPaths: [second] }), "fallback-key")
assert.equal(getApiKey({ env: {}, authPaths: [oauth] }), "oauth-access-key")
assert.equal(getApiKey({ env: {}, authPaths: [official] }), "official-cli-key")
} finally {
rmSync(dir, { recursive: true, force: true })
}
@@ -78,6 +90,16 @@ describe("getApiKey()", () => {
})
})
describe("projectSlugFromPath()", () => {
it("matches the official CLI-style slug from an absolute working directory", () => {
assert.equal(
projectSlugFromPath("/Users/patwoz/dev/Personal/pi/pi-commandcode-provider"),
"users-patwoz-dev-personal-pi-pi-commandcode-provider",
)
assert.equal(projectSlugFromPath("/repo"), "repo")
})
})
describe("textContent()", () => {
it("extracts and joins text blocks", () => {
assert.equal(
+29 -3
View File
@@ -142,6 +142,7 @@ describe("streamCommandCode — successful streams", () => {
server.mockResponse({
type: "success",
events: [
JSON.stringify({ type: "reasoning-start" }),
JSON.stringify({ type: "reasoning-delta", text: "think" }),
JSON.stringify({ type: "reasoning-end" }),
JSON.stringify({ type: "text-delta", text: "Using tool" }),
@@ -244,7 +245,13 @@ describe("streamCommandCode — request serialization", () => {
assert.equal(objectAt(body, ["params", "model"]), "deepseek/deepseek-v4-flash")
assert.equal(objectAt(body, ["params", "stream"]), true)
assert.equal(objectAt(body, ["params", "max_tokens"]), 500)
assert.equal(objectAt(body, ["params", "temperature"]), 0.3)
assert.equal(objectAt(body, ["params", "system"]), "You are a test assistant.")
assert.equal(objectAt(body, ["memory"]), null)
assert.equal(objectAt(body, ["taste"]), null)
assert.equal(objectAt(body, ["skills"]), null)
assert.equal(objectAt(body, ["permissionMode"]), undefined)
assert.equal(objectAt(body, ["threadId"]), "00000000-0000-4000-8000-000000000000")
assert.equal(
objectAt(body, ["params", "messages", "1", "content", "0", "text"]),
"first response",
@@ -253,8 +260,11 @@ describe("streamCommandCode — request serialization", () => {
const headers = server.lastRequestHeaders()
assert.equal(headers.authorization, "Bearer mock-key")
assert.equal(headers["x-command-code-version"], "0.24.1")
assert.equal(headers["x-session-id"], "00000000-0000-4000-8000-000000000000")
assert.equal(headers["x-command-code-version"], "0.27.2")
assert.equal(headers["x-project-slug"], "repo")
assert.equal(headers["x-taste-learning"], "true")
assert.equal(headers["x-co-flag"], "false")
assert.equal(headers["x-session-id"], undefined)
})
it("caps maxTokens and passes custom headers", async () => {
@@ -272,10 +282,26 @@ describe("streamCommandCode — request serialization", () => {
}),
)
assert.equal(objectAt(server.lastRequestBody(), ["params", "max_tokens"]), 200_000)
assert.equal(objectAt(server.lastRequestBody(), ["params", "max_tokens"]), 64_000)
assert.equal(server.lastRequestHeaders()["x-custom"], "value")
})
it("caps default maxTokens by the selected model", async () => {
server.mockResponse({
type: "success",
events: [JSON.stringify({ type: "finish", finishReason: "stop" })],
})
const { streamCommandCode } = createTestDeps({ apiBase: server.baseUrl() })
await collectEvents(
streamCommandCode(makeModel({ maxTokens: 8_192 }), makeContext(), {
apiKey: "mock-key",
}),
)
assert.equal(objectAt(server.lastRequestBody(), ["params", "max_tokens"]), 8_192)
})
it("runs onPayload and onResponse hooks", async () => {
server.mockResponse({
type: "success",