repowisestage 0.0.48 → 0.0.49

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.
Files changed (2) hide show
  1. package/dist/bin/repowise.js +112 -80
  2. package/package.json +1 -1
@@ -4129,9 +4129,9 @@ async function isLocallyConsented(flagPath2) {
4129
4129
  try {
4130
4130
  const body = await readFile11(flagPath2, "utf-8");
4131
4131
  const parsed = JSON.parse(body);
4132
- return Boolean(parsed.consentGrantedAt) && parsed.enabled === true;
4132
+ return parsed.enabled !== false;
4133
4133
  } catch {
4134
- return false;
4134
+ return true;
4135
4135
  }
4136
4136
  }
4137
4137
 
@@ -5665,8 +5665,10 @@ async function startMcp(options) {
5665
5665
  const mcpLogger = createMcpLogger({ filePath: logFilePath, keyStore });
5666
5666
  const flagFilePath = join18(mcpHome, "mcp-log.flag");
5667
5667
  const watermarkFilePath = join18(mcpHome, "mcp-log.watermark");
5668
+ const consentSentMarkerPath = join18(mcpHome, "mcp-log.consent-sent");
5668
5669
  let uploader = null;
5669
5670
  let lastConsentState = false;
5671
+ let serverConsentEnsuredThisProcess = false;
5670
5672
  function ensureUploader() {
5671
5673
  if (uploader)
5672
5674
  return uploader;
@@ -5742,6 +5744,15 @@ async function startMcp(options) {
5742
5744
  lastConsentState = false;
5743
5745
  return { uploaded: 0, skipped: "no-consent" };
5744
5746
  }
5747
+ if (!serverConsentEnsuredThisProcess && await logFileExists(logFilePath)) {
5748
+ await ensureServerConsent({
5749
+ apiUrl: options.repos.find((r) => Boolean(r.apiUrl))?.apiUrl ?? options.repos[0]?.apiUrl ?? "",
5750
+ getAuthToken: options.getAuthToken,
5751
+ markerPath: consentSentMarkerPath,
5752
+ fetchImpl: options.fetchImpl ?? fetch
5753
+ });
5754
+ serverConsentEnsuredThisProcess = true;
5755
+ }
5745
5756
  const u = ensureUploader();
5746
5757
  if (!lastConsentState) {
5747
5758
  u.resetConsentLatch();
@@ -5810,6 +5821,52 @@ function defaultGraphsDir() {
5810
5821
  function defaultMcpHome() {
5811
5822
  return getConfigDir();
5812
5823
  }
5824
+ async function logFileExists(path) {
5825
+ try {
5826
+ const { stat: stat7 } = await import("fs/promises");
5827
+ const s = await stat7(path);
5828
+ return s.size > 0;
5829
+ } catch {
5830
+ return false;
5831
+ }
5832
+ }
5833
+ async function ensureServerConsent(opts) {
5834
+ if (!opts.apiUrl)
5835
+ return;
5836
+ try {
5837
+ const { readFile: readFile18 } = await import("fs/promises");
5838
+ await readFile18(opts.markerPath, "utf-8");
5839
+ return;
5840
+ } catch {
5841
+ }
5842
+ let token;
5843
+ try {
5844
+ token = await opts.getAuthToken();
5845
+ } catch {
5846
+ return;
5847
+ }
5848
+ if (!token)
5849
+ return;
5850
+ try {
5851
+ const res = await opts.fetchImpl(`${opts.apiUrl}/v1/account/mcp-log/consent`, {
5852
+ method: "POST",
5853
+ headers: {
5854
+ "Content-Type": "application/json",
5855
+ Authorization: `Bearer ${token}`
5856
+ }
5857
+ });
5858
+ if (!res.ok)
5859
+ return;
5860
+ const fs18 = await import("fs/promises");
5861
+ const path = await import("path");
5862
+ await fs18.mkdir(path.dirname(opts.markerPath), { recursive: true });
5863
+ await fs18.writeFile(opts.markerPath, (/* @__PURE__ */ new Date()).toISOString() + "\n", {
5864
+ encoding: "utf-8",
5865
+ mode: 384
5866
+ });
5867
+ } catch {
5868
+ }
5869
+ }
5813
5870
 
5814
5871
  // ../listener/dist/mcp/auto-config/index.js
5815
5872
  import { homedir as homedir4 } from "os";
@@ -9716,86 +9773,40 @@ function flagPath() {
9716
9773
  function logPath() {
9717
9774
  return join38(getConfigDir2(), LOG_FILE);
9718
9775
  }
9719
- async function readFlag() {
9720
- try {
9721
- const body = await readFile17(flagPath(), "utf-8");
9722
- return JSON.parse(body);
9723
- } catch {
9724
- return {
9725
- enabled: false,
9726
- consentGrantedAt: null,
9727
- consentSentToServer: false
9728
- };
9729
- }
9730
- }
9731
9776
  async function writeFlag(flag) {
9732
9777
  const path = flagPath();
9733
9778
  await mkdir18(dirname17(path), { recursive: true });
9734
9779
  await writeFile18(path, JSON.stringify(flag, null, 2), { encoding: "utf-8", mode: 384 });
9735
9780
  }
9736
- async function showConsentPrompt() {
9737
- if (!process.stdin.isTTY) {
9738
- console.error("mcp-log on requires an interactive terminal for consent.");
9739
- return false;
9781
+ async function mcpLogOn() {
9782
+ let flagOnDisk = null;
9783
+ try {
9784
+ flagOnDisk = JSON.parse(await readFile17(flagPath(), "utf-8"));
9785
+ } catch {
9786
+ flagOnDisk = null;
9740
9787
  }
9741
- console.log(`Enabling MCP query logging will write a JSONL file to:
9742
- ${logPath()}
9743
-
9744
- Each entry captures tool name, parameters, result shape, and timing
9745
- of every MCP query the listener serves locally. The data stays on
9746
- your machine unless you also run \`repowise mcp-log upload\` (future).
9747
-
9748
- Consent is permanent \u2014 only full account deletion removes it.
9749
- \`repowise mcp-log off\` stops local logging without revoking consent.
9750
- `);
9751
- return await promptYesNo("Grant permanent consent and enable logging? [y/N] ");
9752
- }
9753
- async function promptYesNo(prompt) {
9754
- process.stdout.write(prompt);
9755
- return await new Promise((resolve4) => {
9756
- const onData = (chunk) => {
9757
- const answer = chunk.toString("utf-8").trim().toLowerCase();
9758
- process.stdin.off("data", onData);
9759
- if (typeof process.stdin.pause === "function") {
9760
- process.stdin.pause();
9761
- }
9762
- resolve4(answer === "y" || answer === "yes");
9788
+ if (flagOnDisk && flagOnDisk.enabled === false) {
9789
+ const next = {
9790
+ ...flagOnDisk,
9791
+ enabled: true
9763
9792
  };
9764
- process.stdin.on("data", onData);
9765
- if (typeof process.stdin.resume === "function") {
9766
- process.stdin.resume();
9767
- }
9768
- });
9769
- }
9770
- async function mcpLogOn() {
9771
- const flag = await readFlag();
9772
- if (flag.enabled && flag.consentSentToServer) {
9773
- process.stderr.write("MCP logging is already enabled.\n");
9793
+ await writeFlag(next);
9794
+ process.stderr.write(`MCP logging re-enabled. Log file: ${logPath()}
9795
+ `);
9774
9796
  return;
9775
9797
  }
9776
- if (!flag.consentGrantedAt) {
9777
- const consented = await showConsentPrompt();
9778
- if (!consented) {
9779
- process.stderr.write("Consent not granted. MCP logging remains disabled.\n");
9780
- process.exitCode = 1;
9781
- return;
9782
- }
9783
- flag.consentGrantedAt = (/* @__PURE__ */ new Date()).toISOString();
9784
- }
9785
- flag.enabled = true;
9786
- if (!flag.consentSentToServer) {
9798
+ process.stderr.write("MCP logging is already enabled.\n");
9799
+ if (!flagOnDisk || !flagOnDisk.consentSentToServer) {
9787
9800
  const synced = await trySendConsentToServer();
9788
9801
  if (synced) {
9789
- flag.consentSentToServer = true;
9790
- } else {
9791
- process.stderr.write(
9792
- "(Could not reach API yet \u2014 consent will sync on next listener poll.)\n"
9793
- );
9802
+ const next = {
9803
+ enabled: true,
9804
+ consentGrantedAt: flagOnDisk?.consentGrantedAt ?? (/* @__PURE__ */ new Date()).toISOString(),
9805
+ consentSentToServer: true
9806
+ };
9807
+ await writeFlag(next);
9794
9808
  }
9795
9809
  }
9796
- await writeFlag(flag);
9797
- process.stderr.write(`MCP logging enabled. Log file: ${logPath()}
9798
- `);
9799
9810
  }
9800
9811
  async function trySendConsentToServer() {
9801
9812
  let apiUrl = null;
@@ -9829,25 +9840,42 @@ async function trySendConsentToServer() {
9829
9840
  }
9830
9841
  }
9831
9842
  async function mcpLogOff() {
9832
- const flag = await readFlag();
9833
- if (!flag.enabled) {
9843
+ let flagOnDisk = null;
9844
+ try {
9845
+ flagOnDisk = JSON.parse(await readFile17(flagPath(), "utf-8"));
9846
+ } catch {
9847
+ flagOnDisk = null;
9848
+ }
9849
+ if (flagOnDisk && flagOnDisk.enabled === false) {
9834
9850
  process.stderr.write("MCP logging is already disabled.\n");
9835
9851
  process.exitCode = 1;
9836
9852
  return;
9837
9853
  }
9838
- flag.enabled = false;
9839
- await writeFlag(flag);
9854
+ const next = {
9855
+ enabled: false,
9856
+ consentGrantedAt: flagOnDisk?.consentGrantedAt ?? null,
9857
+ consentSentToServer: flagOnDisk?.consentSentToServer ?? false
9858
+ };
9859
+ await writeFlag(next);
9840
9860
  process.stderr.write(
9841
9861
  "MCP logging disabled. Local log file is preserved; consent record is NOT revoked.\n"
9842
9862
  );
9843
9863
  }
9844
9864
  async function mcpLogStatus() {
9845
- const flag = await readFlag();
9865
+ let flagOnDisk = null;
9866
+ try {
9867
+ flagOnDisk = JSON.parse(await readFile17(flagPath(), "utf-8"));
9868
+ } catch {
9869
+ flagOnDisk = null;
9870
+ }
9871
+ const enabled = !flagOnDisk || flagOnDisk.enabled !== false;
9872
+ const enabledLabel = flagOnDisk == null ? "yes (default)" : flagOnDisk.enabled ? "yes" : "no";
9873
+ void enabled;
9846
9874
  process.stderr.write("MCP Log Status\n");
9847
9875
  process.stderr.write("==============\n");
9848
- process.stderr.write(`Enabled: ${flag.enabled ? "yes" : "no"}
9876
+ process.stderr.write(`Enabled: ${enabledLabel}
9849
9877
  `);
9850
- process.stderr.write(`Consent granted: ${flag.consentGrantedAt ?? "never"}
9878
+ process.stderr.write(`Consent granted: ${flagOnDisk?.consentGrantedAt ?? "never"}
9851
9879
  `);
9852
9880
  process.stderr.write(`Log file: ${logPath()}
9853
9881
  `);
@@ -9875,11 +9903,15 @@ function formatBytes(n) {
9875
9903
  return `${(n / (1024 * 1024)).toFixed(1)} MB`;
9876
9904
  }
9877
9905
  async function mcpLogViewingFlags(flags = {}) {
9878
- const flag = await readFlag();
9879
- if (!flag.consentGrantedAt) {
9906
+ let flagOnDisk = null;
9907
+ try {
9908
+ flagOnDisk = JSON.parse(await readFile17(flagPath(), "utf-8"));
9909
+ } catch {
9910
+ flagOnDisk = null;
9911
+ }
9912
+ if (flagOnDisk && flagOnDisk.enabled === false) {
9880
9913
  process.stderr.write(
9881
- `MCP query logs are collected automatically and stored encrypted on disk.
9882
- Run \`repowise mcp-log on\` to grant consent and view them.
9914
+ `MCP logging is disabled. Run \`repowise mcp-log on\` to re-enable and view logs.
9883
9915
  `
9884
9916
  );
9885
9917
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repowisestage",
3
- "version": "0.0.48",
3
+ "version": "0.0.49",
4
4
  "type": "module",
5
5
  "description": "AI-optimized codebase context generator",
6
6
  "bin": {