@javargasm/opencode-kiro-auth 0.4.0 → 0.5.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/README.md CHANGED
@@ -146,6 +146,31 @@ bun test --watch
146
146
  bun run build
147
147
  ```
148
148
 
149
+ ### Debug logging
150
+
151
+ Structured file logging is **opt-in** via the `KIRO_FILE_LOG` environment
152
+ variable. When enabled, every turn of a conversation is written to
153
+ `/tmp/kiro-logs/session-{id}.log` (full request/response bodies) plus a
154
+ `session-{id}.last-request.json` dump of the most recent request. The id is
155
+ derived from OpenCode's session id, so all turns of one conversation — including
156
+ after a restart (`opencode -s <id>`) — share a single file.
157
+
158
+ It is **off by default** because the logs are verbose and may contain sensitive
159
+ prompt content. Enable it for the current shell:
160
+
161
+ ```bash
162
+ export KIRO_FILE_LOG=1
163
+ ```
164
+
165
+ To keep it always on, add it to your shell profile (macOS uses zsh):
166
+
167
+ ```bash
168
+ echo 'export KIRO_FILE_LOG=1' >> ~/.zshrc && source ~/.zshrc
169
+ ```
170
+
171
+ Accepted truthy values: `1`, `true`, `yes`, `on` (case-insensitive). Rebuild the
172
+ plugin (`bun run build`) and restart OpenCode after changing it.
173
+
149
174
  ### Project Structure
150
175
 
151
176
  ```
@@ -1,5 +1,16 @@
1
1
  /** Root directory for ALL Kiro file logs (session logs, debug log, request dumps). */
2
2
  export declare const LOG_DIR = "/tmp/kiro-logs";
3
+ /**
4
+ * File logging (the structured `session-{id}.log` files under /tmp/kiro-logs,
5
+ * plus the `.last-request.json` dumps) is OPT-IN via the `KIRO_FILE_LOG` env
6
+ * var. It captures full request/response bodies — invaluable for debugging the
7
+ * Kiro wire protocol, but verbose and potentially containing sensitive prompt
8
+ * content — so it stays OFF unless explicitly enabled.
9
+ *
10
+ * Truthy values: `1`, `true`, `yes`, `on` (case-insensitive). Evaluated on
11
+ * every call so it can be toggled at runtime (and in tests).
12
+ */
13
+ export declare function isFileLoggingEnabled(): boolean;
3
14
  /** Ensure LOG_DIR exists. Best-effort and memoized; safe to call on every write. */
4
15
  export declare function ensureLogDir(): void;
5
16
  /** File path of the session log active in the current async context, if any. */
@@ -1 +1 @@
1
- {"version":3,"file":"file-logger.d.ts","sourceRoot":"","sources":["../src/file-logger.ts"],"names":[],"mappings":"AAaA,sFAAsF;AACtF,eAAO,MAAM,OAAO,mBAAmB,CAAC;AASxC,oFAAoF;AACpF,wBAAgB,YAAY,IAAI,IAAI,CAQnC;AA4BD,gFAAgF;AAChF,wBAAgB,qBAAqB,IAAI,MAAM,GAAG,IAAI,CAErD;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAIrE;AAgBD,MAAM,WAAW,aAAa;IAC5B,uDAAuD;IACvD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iDAAiD;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B,kDAAkD;IAClD,UAAU,CACR,IAAI,EAAE;QACJ,QAAQ,EAAE,MAAM,CAAC;QACjB,KAAK,EAAE,MAAM,CAAC;QACd,aAAa,EAAE,MAAM,CAAC;QACtB,gBAAgB,EAAE,MAAM,CAAC;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,MAAM,CAAC;KACxB,EACD,WAAW,EAAE,MAAM,GAClB,IAAI,CAAC;IAER,wDAAwD;IACxD,gBAAgB,CAAC,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAEjF,gEAAgE;IAChE,eAAe,CAAC,IAAI,EAAE;QACpB,UAAU,EAAE,MAAM,CAAC;QACnB,gBAAgB,EAAE,MAAM,CAAC;QACzB,KAAK,EAAE,OAAO,CAAC;QACf,aAAa,EAAE,MAAM,CAAC;QACtB,KAAK,EAAE,MAAM,CAAC;KACf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,IAAI,EAAE;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,EACjE,KAAK,CAAC,EAAE,OAAO,GACd,IAAI,CAAC;CACT;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,aAAa,CAkDrE"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  import type { Plugin } from "@opencode-ai/plugin";
2
+ /**
3
+ * Headers injected into every model request so the gateway can tie the Kiro
4
+ * `conversationId` (and its log-file grouping) to OpenCode's STABLE session id.
5
+ *
6
+ * The gateway derives the conversationId from the `x-session-id` header (see
7
+ * `deriveLogSessionId` in server.ts). OpenCode's session id is stable for the
8
+ * life of a conversation AND survives a restart (`opencode -s <id>` resumes the
9
+ * same id), so the conversationId stays constant across turns and restarts —
10
+ * matching the real Kiro CLI. Without this the gateway fell back to an
11
+ * ephemeral header / first-message fingerprint, so the id changed on every
12
+ * restart and the logs scattered across files.
13
+ *
14
+ * Exported for testing. Returns `{}` when no session id is available.
15
+ */
16
+ export declare function kiroSessionHeaders(sessionID: string | undefined): Record<string, string>;
2
17
  export declare const KiroPlugin: Plugin;
3
18
  declare const _default: {
4
19
  id: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAuB,MAAM,qBAAqB,CAAC;AA0BvE,eAAO,MAAM,UAAU,EAAE,MAqUxB,CAAC;;;;;AAEF,wBAGyB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAuB,MAAM,qBAAqB,CAAC;AA0BvE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIxF;AAED,eAAO,MAAM,UAAU,EAAE,MA+UxB,CAAC;;;;;AAEF,wBAGyB"}
package/dist/index.js CHANGED
@@ -19,8 +19,12 @@ var __require = /* @__PURE__ */ createRequire(import.meta.url);
19
19
  // src/file-logger.ts
20
20
  import { appendFileSync, mkdirSync } from "node:fs";
21
21
  import { AsyncLocalStorage } from "node:async_hooks";
22
- function isEnabled() {
23
- return true;
22
+ function isFileLoggingEnabled() {
23
+ const v = process.env.KIRO_FILE_LOG;
24
+ if (!v)
25
+ return false;
26
+ const s = v.trim().toLowerCase();
27
+ return s === "1" || s === "true" || s === "yes" || s === "on";
24
28
  }
25
29
  function ensureLogDir() {
26
30
  if (dirEnsured)
@@ -43,7 +47,7 @@ function enterSessionLog(sessionId) {
43
47
  return id;
44
48
  }
45
49
  function writeLine(file, data) {
46
- if (!isEnabled())
50
+ if (!isFileLoggingEnabled())
47
51
  return;
48
52
  ensureLogDir();
49
53
  const entry = {
@@ -2987,7 +2991,7 @@ ${currentContent}`;
2987
2991
  requestJsonChars: requestBody.length
2988
2992
  });
2989
2993
  log.debug(`[stream] req=${requestBody.length}c hist=${history.length} content=${currentContent.length}c profileArn=${!!profileArn}`);
2990
- if (log.isDebug()) {
2994
+ if (isFileLoggingEnabled()) {
2991
2995
  try {
2992
2996
  ensureLogDir();
2993
2997
  __require("fs").writeFileSync(`${LOG_DIR}/session-${fileLog.sessionId}.last-request.json`, requestBody);
@@ -4602,6 +4606,9 @@ init_models();
4602
4606
  process.env.KIRO_LOG = process.env.KIRO_LOG || "debug";
4603
4607
  process.env.KIRO_LOG_FILE = process.env.KIRO_LOG_FILE || "/tmp/kiro-logs/session-gateway.log";
4604
4608
  var gatewayServer = null;
4609
+ function kiroSessionHeaders(sessionID) {
4610
+ return typeof sessionID === "string" && sessionID.trim().length > 0 ? { "x-session-id": sessionID.trim() } : {};
4611
+ }
4605
4612
  var KiroPlugin = async (input) => {
4606
4613
  const client = input.client;
4607
4614
  const GATEWAY_PORT = 7438;
@@ -4618,6 +4625,12 @@ var KiroPlugin = async (input) => {
4618
4625
  await initGatewayAuth();
4619
4626
  const localPort = gatewayServer ? gatewayServer.port : GATEWAY_PORT;
4620
4627
  const hooks = {
4628
+ "chat.headers": async (input2, output) => {
4629
+ const headers = kiroSessionHeaders(input2?.sessionID);
4630
+ if (output && output.headers) {
4631
+ Object.assign(output.headers, headers);
4632
+ }
4633
+ },
4621
4634
  dispose: async () => {
4622
4635
  if (gatewayServer) {
4623
4636
  log.info("[opencode-kiro] Shutting down gateway server...");
@@ -4885,6 +4898,7 @@ var src_default = {
4885
4898
  server: KiroPlugin
4886
4899
  };
4887
4900
  export {
4901
+ kiroSessionHeaders,
4888
4902
  src_default as default,
4889
4903
  KiroPlugin
4890
4904
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@javargasm/opencode-kiro-auth",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Kiro provider plugin for OpenCode: AWS Builder ID / Identity Center login and OpenAI compatible local gateway for CodeWhisperer streaming.",
5
5
  "type": "module",
6
6
  "license": "MIT",