codeconscious 0.1.1 → 0.1.3
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 +26 -1
- package/dist/cli.cjs +174 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,7 +11,10 @@ npx codeconscious init
|
|
|
11
11
|
- `codeconscious init` install hooks in the current git repo (chains with husky, lefthook, `core.hooksPath`; nothing is overwritten) and log in
|
|
12
12
|
- `codeconscious uninstall` remove the hooks and restore the previous state
|
|
13
13
|
- `codeconscious quiz` answer the pending question for your current commit (and a few more, one at a time)
|
|
14
|
-
- `codeconscious
|
|
14
|
+
- `codeconscious logout` revoke this machine's login on the server (2 s, best effort) and delete the local token; hooks then stay silent until you run `init` again
|
|
15
|
+
- If a command says "Your CLI login expired or was revoked", run `npx codeconscious@latest init` to log in again
|
|
16
|
+
- `codeconscious status` show login, hook state and installed version
|
|
17
|
+
- `npx codeconscious --version` print the version
|
|
15
18
|
- `codeconscious --help` list all commands
|
|
16
19
|
|
|
17
20
|
## On push, and when an AI agent commits for you
|
|
@@ -20,6 +23,28 @@ On `git push` you see a one-line teaser: "Press space or enter to answer (15s),
|
|
|
20
23
|
|
|
21
24
|
If an AI agent commits for you, run `npx codeconscious quiz` afterwards.
|
|
22
25
|
|
|
26
|
+
## Updating
|
|
27
|
+
|
|
28
|
+
The hooks run a copy of the CLI stored at `~/.codeconscious/cli.cjs`, not the npx cache, so a new release does not reach you on its own. To update, run this once:
|
|
29
|
+
|
|
30
|
+
```sh
|
|
31
|
+
npx codeconscious@latest init
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
It is safe to re-run: you stay signed in, no hook is duplicated, and the stored copy is replaced. Repos whose hooks live in `.git/hooks` or a global `core.hooksPath` share that one copy, so a single run updates all of them. Only repos without hooks need their own `init`.
|
|
35
|
+
|
|
36
|
+
Repos whose hooks live in a tracked folder (husky, or `init --force`) call `codeconscious` from your PATH instead of the shared copy, so re-running `init` does not update those. They update with the PATH install, for example `npm i -g codeconscious@latest`.
|
|
37
|
+
|
|
38
|
+
To check the version:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
npx codeconscious --version # or -v; the version of the CLI you ran
|
|
42
|
+
npx codeconscious@latest status # also shows the version of the installed hook runtime
|
|
43
|
+
npm view codeconscious version # latest published version
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
There is no auto-update, by design. Hooks never reach the network except the 2 s fail-open API calls described below, so they never check for or download new code.
|
|
47
|
+
|
|
23
48
|
## Privacy
|
|
24
49
|
|
|
25
50
|
- Only diffs leave your machine, never the full repo.
|
package/dist/cli.cjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
// codeconscious-version: 0.1.3
|
|
2
3
|
"use strict";
|
|
3
4
|
var __create = Object.create;
|
|
4
5
|
var __defProp = Object.defineProperty;
|
|
@@ -39,8 +40,8 @@ if (typeof u.styleText !== "function") {
|
|
|
39
40
|
|
|
40
41
|
// src/commands.ts
|
|
41
42
|
var import_node_child_process2 = require("node:child_process");
|
|
42
|
-
var
|
|
43
|
-
var
|
|
43
|
+
var import_node_fs7 = __toESM(require("node:fs"), 1);
|
|
44
|
+
var import_node_path7 = __toESM(require("node:path"), 1);
|
|
44
45
|
|
|
45
46
|
// ../../node_modules/@clack/prompts/dist/index.mjs
|
|
46
47
|
var dist_exports = {};
|
|
@@ -3414,8 +3415,8 @@ function getErrorMap() {
|
|
|
3414
3415
|
|
|
3415
3416
|
// ../../node_modules/zod/v3/helpers/parseUtil.js
|
|
3416
3417
|
var makeIssue = (params) => {
|
|
3417
|
-
const { data, path:
|
|
3418
|
-
const fullPath = [...
|
|
3418
|
+
const { data, path: path9, errorMaps, issueData } = params;
|
|
3419
|
+
const fullPath = [...path9, ...issueData.path || []];
|
|
3419
3420
|
const fullIssue = {
|
|
3420
3421
|
...issueData,
|
|
3421
3422
|
path: fullPath
|
|
@@ -3531,11 +3532,11 @@ var errorUtil;
|
|
|
3531
3532
|
|
|
3532
3533
|
// ../../node_modules/zod/v3/types.js
|
|
3533
3534
|
var ParseInputLazyPath = class {
|
|
3534
|
-
constructor(parent, value,
|
|
3535
|
+
constructor(parent, value, path9, key) {
|
|
3535
3536
|
this._cachedPath = [];
|
|
3536
3537
|
this.parent = parent;
|
|
3537
3538
|
this.data = value;
|
|
3538
|
-
this._path =
|
|
3539
|
+
this._path = path9;
|
|
3539
3540
|
this._key = key;
|
|
3540
3541
|
}
|
|
3541
3542
|
get path() {
|
|
@@ -7317,6 +7318,14 @@ var TokenResponseSchema = external_exports.union([
|
|
|
7317
7318
|
TokenGrantedResponseSchema,
|
|
7318
7319
|
TokenPendingResponseSchema
|
|
7319
7320
|
]);
|
|
7321
|
+
var RevokeTokenResponseSchema = external_exports.object({
|
|
7322
|
+
revoked: external_exports.literal(true)
|
|
7323
|
+
});
|
|
7324
|
+
var RevokeAllTokensResponseSchema = external_exports.object({
|
|
7325
|
+
revoked: external_exports.literal(true),
|
|
7326
|
+
/** Number of tokens revoked by this call; `0` when none were active. */
|
|
7327
|
+
count: external_exports.number().int().nonnegative()
|
|
7328
|
+
});
|
|
7320
7329
|
var MAX_DIFF_CHARS = 1e6;
|
|
7321
7330
|
var DiffsRequestSchema = external_exports.object({
|
|
7322
7331
|
/** `owner/name` of the repository the commit belongs to. */
|
|
@@ -7552,6 +7561,7 @@ function writeConfig(dir, config) {
|
|
|
7552
7561
|
} catch {
|
|
7553
7562
|
}
|
|
7554
7563
|
import_node_fs2.default.renameSync(tmp, file);
|
|
7564
|
+
clearAuthExpired(dir);
|
|
7555
7565
|
} catch (err) {
|
|
7556
7566
|
import_node_fs2.default.rmSync(tmp, { force: true });
|
|
7557
7567
|
throw err;
|
|
@@ -7562,7 +7572,33 @@ function clearConfig(dir) {
|
|
|
7562
7572
|
import_node_fs2.default.rmSync(configPath(dir), { force: true });
|
|
7563
7573
|
} catch {
|
|
7564
7574
|
}
|
|
7575
|
+
clearAuthExpired(dir);
|
|
7576
|
+
}
|
|
7577
|
+
function authExpiredPath(dir) {
|
|
7578
|
+
return import_node_path2.default.join(dir, "auth-expired");
|
|
7579
|
+
}
|
|
7580
|
+
function markAuthExpired(dir) {
|
|
7581
|
+
try {
|
|
7582
|
+
ensurePrivateDir(dir);
|
|
7583
|
+
import_node_fs2.default.writeFileSync(authExpiredPath(dir), `${(/* @__PURE__ */ new Date()).toISOString()}
|
|
7584
|
+
`, { mode: 384 });
|
|
7585
|
+
} catch {
|
|
7586
|
+
}
|
|
7587
|
+
}
|
|
7588
|
+
function isAuthExpired(dir) {
|
|
7589
|
+
try {
|
|
7590
|
+
return import_node_fs2.default.existsSync(authExpiredPath(dir));
|
|
7591
|
+
} catch {
|
|
7592
|
+
return false;
|
|
7593
|
+
}
|
|
7565
7594
|
}
|
|
7595
|
+
function clearAuthExpired(dir) {
|
|
7596
|
+
try {
|
|
7597
|
+
import_node_fs2.default.rmSync(authExpiredPath(dir), { force: true });
|
|
7598
|
+
} catch {
|
|
7599
|
+
}
|
|
7600
|
+
}
|
|
7601
|
+
var AUTH_EXPIRED_MESSAGE = "Your CLI login expired or was revoked. Run: npx codeconscious@latest init";
|
|
7566
7602
|
function getToken(env = process.env) {
|
|
7567
7603
|
return readConfig(configDir(env)).token;
|
|
7568
7604
|
}
|
|
@@ -7597,8 +7633,10 @@ function createApiClient(opts) {
|
|
|
7597
7633
|
const shouldLog = opts.log ?? true;
|
|
7598
7634
|
async function call(method, pathAndQuery, schema, body) {
|
|
7599
7635
|
const result = await attempt(method, pathAndQuery, schema, body);
|
|
7636
|
+
if (result.ok && opts.token) clearAuthExpired(configDir(opts.env));
|
|
7637
|
+
if (!result.ok && result.status === 401 && opts.token) markAuthExpired(configDir(opts.env));
|
|
7600
7638
|
if (!result.ok && shouldLog) {
|
|
7601
|
-
logLine(`api ${method} ${pathAndQuery.split("?")[0]} -> ${result.error}
|
|
7639
|
+
logLine(`api ${method} ${pathAndQuery.split("?")[0]} -> ${result.error}`, opts.env);
|
|
7602
7640
|
}
|
|
7603
7641
|
return result;
|
|
7604
7642
|
}
|
|
@@ -7623,6 +7661,7 @@ function createApiClient(opts) {
|
|
|
7623
7661
|
});
|
|
7624
7662
|
const text2 = await res.text();
|
|
7625
7663
|
if (!res.ok) return { ok: false, status: res.status, error: `HTTP ${res.status}` };
|
|
7664
|
+
if (!schema) return { ok: true, data: void 0 };
|
|
7626
7665
|
let json;
|
|
7627
7666
|
try {
|
|
7628
7667
|
json = JSON.parse(text2);
|
|
@@ -7658,6 +7697,9 @@ function createApiClient(opts) {
|
|
|
7658
7697
|
const query = `?repo=${encodeURIComponent(repo)}&sha=${encodeURIComponent(sha)}`;
|
|
7659
7698
|
return await call("GET", `/questions/next${query}`, QuestionsNextResponseSchema);
|
|
7660
7699
|
},
|
|
7700
|
+
async revokeToken() {
|
|
7701
|
+
return await call("DELETE", "/cli/token", void 0);
|
|
7702
|
+
},
|
|
7661
7703
|
async postAnswer(body) {
|
|
7662
7704
|
return await call("POST", "/answers", AnswersResponseSchema, body);
|
|
7663
7705
|
}
|
|
@@ -7916,20 +7958,47 @@ function hooksInstalled(dir) {
|
|
|
7916
7958
|
return result;
|
|
7917
7959
|
}
|
|
7918
7960
|
|
|
7961
|
+
// src/version.ts
|
|
7962
|
+
var import_node_fs6 = __toESM(require("node:fs"), 1);
|
|
7963
|
+
var import_node_path6 = __toESM(require("node:path"), 1);
|
|
7964
|
+
var VERSION = true ? "0.1.3" : "dev";
|
|
7965
|
+
var VERSION_MARKER = "codeconscious-version:";
|
|
7966
|
+
var MARKER_RE = new RegExp(`^// ${VERSION_MARKER} ([0-9A-Za-z.+-]{1,64})$`, "m");
|
|
7967
|
+
function installedRuntimeVersion(cfgDir) {
|
|
7968
|
+
let fd;
|
|
7969
|
+
try {
|
|
7970
|
+
fd = import_node_fs6.default.openSync(import_node_path6.default.join(cfgDir, "cli.cjs"), "r");
|
|
7971
|
+
} catch {
|
|
7972
|
+
return null;
|
|
7973
|
+
}
|
|
7974
|
+
try {
|
|
7975
|
+
const buf = Buffer.alloc(512);
|
|
7976
|
+
const n3 = import_node_fs6.default.readSync(fd, buf, 0, 512, 0);
|
|
7977
|
+
return MARKER_RE.exec(buf.subarray(0, n3).toString("utf8").replace(/\r/g, ""))?.[1];
|
|
7978
|
+
} catch {
|
|
7979
|
+
return void 0;
|
|
7980
|
+
} finally {
|
|
7981
|
+
try {
|
|
7982
|
+
import_node_fs6.default.closeSync(fd);
|
|
7983
|
+
} catch {
|
|
7984
|
+
}
|
|
7985
|
+
}
|
|
7986
|
+
}
|
|
7987
|
+
|
|
7919
7988
|
// src/commands.ts
|
|
7920
7989
|
var defaultSleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
7921
7990
|
function installRuntime(dir, cliPath) {
|
|
7922
7991
|
if (!cliPath) return void 0;
|
|
7923
7992
|
try {
|
|
7924
|
-
const real =
|
|
7993
|
+
const real = import_node_fs7.default.realpathSync(cliPath);
|
|
7925
7994
|
if (!real.endsWith(".cjs")) return real;
|
|
7926
|
-
const target =
|
|
7995
|
+
const target = import_node_path7.default.join(dir, "cli.cjs");
|
|
7927
7996
|
if (real === target) return target;
|
|
7928
|
-
|
|
7997
|
+
import_node_fs7.default.mkdirSync(dir, { recursive: true, mode: 448 });
|
|
7929
7998
|
const tmp = `${target}.${process.pid}.tmp`;
|
|
7930
|
-
|
|
7931
|
-
|
|
7932
|
-
|
|
7999
|
+
import_node_fs7.default.copyFileSync(real, tmp);
|
|
8000
|
+
import_node_fs7.default.chmodSync(tmp, 493);
|
|
8001
|
+
import_node_fs7.default.renameSync(tmp, target);
|
|
7933
8002
|
return target;
|
|
7934
8003
|
} catch {
|
|
7935
8004
|
return cliPath;
|
|
@@ -7971,9 +8040,9 @@ function describe(report) {
|
|
|
7971
8040
|
}
|
|
7972
8041
|
function hooksDirInWorkTree(root, dir) {
|
|
7973
8042
|
try {
|
|
7974
|
-
const rel =
|
|
7975
|
-
if (rel === "" || rel.startsWith("..") ||
|
|
7976
|
-
return rel.split(
|
|
8043
|
+
const rel = import_node_path7.default.relative(import_node_fs7.default.realpathSync(root), import_node_fs7.default.realpathSync(dir));
|
|
8044
|
+
if (rel === "" || rel.startsWith("..") || import_node_path7.default.isAbsolute(rel)) return false;
|
|
8045
|
+
return rel.split(import_node_path7.default.sep)[0] !== ".git";
|
|
7977
8046
|
} catch {
|
|
7978
8047
|
return false;
|
|
7979
8048
|
}
|
|
@@ -7994,7 +8063,7 @@ async function runInit(deps) {
|
|
|
7994
8063
|
return 1;
|
|
7995
8064
|
}
|
|
7996
8065
|
const apiBase = apiBaseUrl(deps.env);
|
|
7997
|
-
if (!getToken(deps.env)) {
|
|
8066
|
+
if (!getToken(deps.env) || isAuthExpired(cfgDir)) {
|
|
7998
8067
|
const api = createApiClient({
|
|
7999
8068
|
baseUrl: apiBase,
|
|
8000
8069
|
timeoutMs: 1e4,
|
|
@@ -8048,7 +8117,7 @@ async function runInit(deps) {
|
|
|
8048
8117
|
}
|
|
8049
8118
|
if (!deps.force && hooksDirInWorkTree(root, dir)) {
|
|
8050
8119
|
say?.log.warn(
|
|
8051
|
-
`Your hooks live inside the repository (${
|
|
8120
|
+
`Your hooks live inside the repository (${import_node_path7.default.relative(root, dir) || "."}, e.g. husky), so they are tracked and shared with your team. Not touching them.
|
|
8052
8121
|
Add this line to your pre-push and post-commit hooks yourself:
|
|
8053
8122
|
codeconscious hook <pre-push|post-commit> "$@" || true
|
|
8054
8123
|
or re-run with --force to add it (without any machine-specific path).`
|
|
@@ -8063,6 +8132,28 @@ or re-run with --force to add it (without any machine-specific path).`
|
|
|
8063
8132
|
say?.outro("Done. You will get one question per push (press s to skip).");
|
|
8064
8133
|
return 0;
|
|
8065
8134
|
}
|
|
8135
|
+
async function runLogout(deps) {
|
|
8136
|
+
const say = deps.quiet ? void 0 : dist_exports;
|
|
8137
|
+
const token = getToken(deps.env);
|
|
8138
|
+
let revoked = false;
|
|
8139
|
+
if (token) {
|
|
8140
|
+
const api = createApiClient({
|
|
8141
|
+
baseUrl: apiBaseUrl(deps.env),
|
|
8142
|
+
token,
|
|
8143
|
+
timeoutMs: HOOK_TIMEOUT_MS,
|
|
8144
|
+
fetchImpl: deps.fetchImpl,
|
|
8145
|
+
env: deps.env
|
|
8146
|
+
});
|
|
8147
|
+
revoked = (await api.revokeToken()).ok;
|
|
8148
|
+
}
|
|
8149
|
+
clearConfig(configDir(deps.env));
|
|
8150
|
+
if (!token) say?.log.step("Not signed in.");
|
|
8151
|
+
else if (revoked) say?.log.step("Signed out (token revoked).");
|
|
8152
|
+
else {
|
|
8153
|
+
say?.log.step("Removed the local token; could not confirm revocation on the server.");
|
|
8154
|
+
}
|
|
8155
|
+
return 0;
|
|
8156
|
+
}
|
|
8066
8157
|
async function runUninstall(deps) {
|
|
8067
8158
|
const say = deps.quiet ? void 0 : dist_exports;
|
|
8068
8159
|
const dir = hooksDir(deps.cwd);
|
|
@@ -8072,16 +8163,27 @@ async function runUninstall(deps) {
|
|
|
8072
8163
|
}
|
|
8073
8164
|
for (const report of uninstallHooks(dir)) say?.log.step(describe(report));
|
|
8074
8165
|
if (deps.all) {
|
|
8075
|
-
|
|
8076
|
-
say?.log.step("Signed out (token deleted).");
|
|
8166
|
+
await runLogout(deps);
|
|
8077
8167
|
}
|
|
8078
8168
|
say?.outro("CodeConscious hooks removed from this repository.");
|
|
8079
8169
|
return 0;
|
|
8080
8170
|
}
|
|
8081
|
-
function
|
|
8171
|
+
function statusLines(deps) {
|
|
8082
8172
|
const lines = [];
|
|
8173
|
+
lines.push(`Version: ${VERSION}`);
|
|
8174
|
+
const runtime = installedRuntimeVersion(configDir(deps.env));
|
|
8175
|
+
const update = "run: npx codeconscious@latest init";
|
|
8176
|
+
if (runtime === null) lines.push("Hook runtime: not installed");
|
|
8177
|
+
else if (runtime === void 0) lines.push(`Hook runtime: older than ${VERSION} (${update})`);
|
|
8178
|
+
else if (runtime !== VERSION)
|
|
8179
|
+
lines.push(`Hook runtime: ${runtime}, differs from this CLI (${update})`);
|
|
8180
|
+
else lines.push(`Hook runtime: ${runtime}`);
|
|
8083
8181
|
lines.push(`API: ${apiBaseUrl(deps.env)}`);
|
|
8084
|
-
|
|
8182
|
+
if (getToken(deps.env) && isAuthExpired(configDir(deps.env))) {
|
|
8183
|
+
lines.push(`Signed in: no. ${AUTH_EXPIRED_MESSAGE}`);
|
|
8184
|
+
} else {
|
|
8185
|
+
lines.push(`Signed in: ${getToken(deps.env) ? "yes" : "no (run: npx codeconscious init)"}`);
|
|
8186
|
+
}
|
|
8085
8187
|
const dir = hooksDir(deps.cwd);
|
|
8086
8188
|
if (dir) {
|
|
8087
8189
|
const state = hooksInstalled(dir);
|
|
@@ -8094,13 +8196,16 @@ function runStatus(deps) {
|
|
|
8094
8196
|
if (dir && getToken(deps.env)) {
|
|
8095
8197
|
lines.push("Skipped a question, or an agent committed for you? Run: npx codeconscious quiz");
|
|
8096
8198
|
}
|
|
8199
|
+
return lines;
|
|
8200
|
+
}
|
|
8201
|
+
function runStatus(deps) {
|
|
8097
8202
|
if (deps.quiet) return 0;
|
|
8098
|
-
note(
|
|
8203
|
+
note(statusLines(deps).join("\n"), "CodeConscious status");
|
|
8099
8204
|
return 0;
|
|
8100
8205
|
}
|
|
8101
8206
|
|
|
8102
8207
|
// src/quiz.ts
|
|
8103
|
-
var
|
|
8208
|
+
var import_node_fs8 = __toESM(require("node:fs"), 1);
|
|
8104
8209
|
var import_node_tty2 = __toESM(require("node:tty"), 1);
|
|
8105
8210
|
function openTty() {
|
|
8106
8211
|
try {
|
|
@@ -8109,7 +8214,7 @@ function openTty() {
|
|
|
8109
8214
|
return { input: process.stdin, output: process.stderr, close: () => process.stdin.pause() };
|
|
8110
8215
|
}
|
|
8111
8216
|
const device = process.platform === "win32" ? "\\\\.\\CONIN$" : "/dev/tty";
|
|
8112
|
-
const fd =
|
|
8217
|
+
const fd = import_node_fs8.default.openSync(device, process.platform === "win32" ? "r+" : "r");
|
|
8113
8218
|
const input = new import_node_tty2.default.ReadStream(fd);
|
|
8114
8219
|
return {
|
|
8115
8220
|
input,
|
|
@@ -8390,7 +8495,8 @@ async function runQuiz(deps) {
|
|
|
8390
8495
|
baseUrl: apiBaseUrl(deps.env),
|
|
8391
8496
|
token,
|
|
8392
8497
|
timeoutMs: QUIZ_TIMEOUT_MS,
|
|
8393
|
-
fetchImpl: deps.fetchImpl
|
|
8498
|
+
fetchImpl: deps.fetchImpl,
|
|
8499
|
+
env: deps.env
|
|
8394
8500
|
});
|
|
8395
8501
|
const ask = deps.ask ?? ((q, t2) => askQuestion(q, t2, { timeoutMs: ANSWER_CEILING_MS, countdown: false }));
|
|
8396
8502
|
const confirmAnother = deps.confirmAnother ?? (async (t2) => {
|
|
@@ -8406,6 +8512,10 @@ async function runQuiz(deps) {
|
|
|
8406
8512
|
for (let round = 0; round < MAX_QUESTIONS; round++) {
|
|
8407
8513
|
const next = await api.nextQuestion(repo, sha);
|
|
8408
8514
|
if (!next.ok) {
|
|
8515
|
+
if (next.status === 401) {
|
|
8516
|
+
say(AUTH_EXPIRED_MESSAGE);
|
|
8517
|
+
return 0;
|
|
8518
|
+
}
|
|
8409
8519
|
say("Could not reach CodeConscious. Try again later.");
|
|
8410
8520
|
return 0;
|
|
8411
8521
|
}
|
|
@@ -8446,8 +8556,8 @@ async function runQuiz(deps) {
|
|
|
8446
8556
|
|
|
8447
8557
|
// src/hooks-run.ts
|
|
8448
8558
|
var import_node_child_process3 = require("node:child_process");
|
|
8449
|
-
var
|
|
8450
|
-
var
|
|
8559
|
+
var import_node_fs9 = __toESM(require("node:fs"), 1);
|
|
8560
|
+
var import_node_path8 = __toESM(require("node:path"), 1);
|
|
8451
8561
|
|
|
8452
8562
|
// src/filter.ts
|
|
8453
8563
|
var MAX_UPLOAD_CHARS = 6e4;
|
|
@@ -8760,6 +8870,16 @@ var TOKEN_PATTERNS = [
|
|
|
8760
8870
|
// Slack
|
|
8761
8871
|
/\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
8762
8872
|
// Google API key
|
|
8873
|
+
/\bsb_(?:secret|publishable)_[A-Za-z0-9_-]{16,}/g,
|
|
8874
|
+
// Supabase
|
|
8875
|
+
/\bnpm_[A-Za-z0-9]{36}\b/g,
|
|
8876
|
+
// npm
|
|
8877
|
+
/\bhf_[A-Za-z0-9]{30,}\b/g,
|
|
8878
|
+
// Hugging Face
|
|
8879
|
+
/\bglpat-[A-Za-z0-9_-]{20,}/g,
|
|
8880
|
+
// GitLab
|
|
8881
|
+
/\bwhsec_[A-Za-z0-9+/=]{16,}/g,
|
|
8882
|
+
// Stripe webhook secret
|
|
8763
8883
|
/\bSG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}/g,
|
|
8764
8884
|
// SendGrid
|
|
8765
8885
|
/\bre_[A-Za-z0-9]{20,}\b/g,
|
|
@@ -8768,6 +8888,8 @@ var TOKEN_PATTERNS = [
|
|
|
8768
8888
|
// JWT
|
|
8769
8889
|
/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY-----|$)/g
|
|
8770
8890
|
];
|
|
8891
|
+
var BEARER_HEADER = /(\bauthorization["']?\s*(?:[:=,]|=>)\s*["'`]?bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi;
|
|
8892
|
+
var AWS_SECRET = /(\baws[_-]?secret[A-Za-z0-9_-]*["']?\s*[:=]\s*["'`]?)[A-Za-z0-9/+=]{40}(?![A-Za-z0-9/+=])/gi;
|
|
8771
8893
|
var ASSIGNMENT = /((?:api[_-]?key|apikey|secret|token|passwd|password|pwd|auth|bearer|private[_-]?key|access[_-]?key)[A-Za-z0-9_]*["']?\s*[:=]\s*)(["'`])([^"'`\s]{8,})\2/gi;
|
|
8772
8894
|
var UNQUOTED = /((?:api[_-]?key|apikey|secret|token|passwd|password|pwd|private[_-]?key|access[_-]?key)[A-Za-z0-9_]*\s*[:=]\s*)([^\s"'`,;()<>{}[\]]{8,})/gi;
|
|
8773
8895
|
function looksLikeSecretValue(value) {
|
|
@@ -8791,6 +8913,14 @@ function redactSecrets(text2) {
|
|
|
8791
8913
|
};
|
|
8792
8914
|
let out = text2;
|
|
8793
8915
|
for (const pattern of TOKEN_PATTERNS) out = out.replace(pattern, bump(REDACTED));
|
|
8916
|
+
out = out.replace(BEARER_HEADER, (_m, head) => {
|
|
8917
|
+
count++;
|
|
8918
|
+
return `${head}${REDACTED}`;
|
|
8919
|
+
});
|
|
8920
|
+
out = out.replace(AWS_SECRET, (_m, head) => {
|
|
8921
|
+
count++;
|
|
8922
|
+
return `${head}${REDACTED}`;
|
|
8923
|
+
});
|
|
8794
8924
|
out = out.replace(ASSIGNMENT, (_m, key, quote) => {
|
|
8795
8925
|
count++;
|
|
8796
8926
|
return `${key}${quote}${REDACTED}${quote}`;
|
|
@@ -8857,7 +8987,7 @@ function readIgnoreFiles(root) {
|
|
|
8857
8987
|
const out = [];
|
|
8858
8988
|
for (const name of [".gitignore", ".codeconsciousignore"]) {
|
|
8859
8989
|
try {
|
|
8860
|
-
out.push(
|
|
8990
|
+
out.push(import_node_fs9.default.readFileSync(import_node_path8.default.join(root, name), "utf8"));
|
|
8861
8991
|
} catch {
|
|
8862
8992
|
}
|
|
8863
8993
|
}
|
|
@@ -8888,7 +9018,8 @@ async function runUpload(deps) {
|
|
|
8888
9018
|
baseUrl: apiBaseUrl(deps.env),
|
|
8889
9019
|
token,
|
|
8890
9020
|
timeoutMs: HOOK_TIMEOUT_MS,
|
|
8891
|
-
fetchImpl: deps.fetchImpl
|
|
9021
|
+
fetchImpl: deps.fetchImpl,
|
|
9022
|
+
env: deps.env
|
|
8892
9023
|
});
|
|
8893
9024
|
const res = await api.postDiff(body.data);
|
|
8894
9025
|
return res.ok ? "uploaded" : "failed";
|
|
@@ -8916,7 +9047,8 @@ async function runPrePush(deps) {
|
|
|
8916
9047
|
baseUrl: apiBaseUrl(deps.env),
|
|
8917
9048
|
token,
|
|
8918
9049
|
timeoutMs: HOOK_TIMEOUT_MS,
|
|
8919
|
-
fetchImpl: deps.fetchImpl
|
|
9050
|
+
fetchImpl: deps.fetchImpl,
|
|
9051
|
+
env: deps.env
|
|
8920
9052
|
});
|
|
8921
9053
|
const next = await api.nextQuestion(repo, sha);
|
|
8922
9054
|
if (!next.ok) return "failed-open";
|
|
@@ -8994,7 +9126,9 @@ Usage:
|
|
|
8994
9126
|
(--force: also write hooks into a tracked hooks dir such as .husky)
|
|
8995
9127
|
codeconscious quiz answer pending questions for your recent commits
|
|
8996
9128
|
(run it after an AI agent committed for you)
|
|
8997
|
-
codeconscious status show login and
|
|
9129
|
+
codeconscious status show login, hook state and installed version
|
|
9130
|
+
codeconscious logout revoke this machine's login on the server and delete the local token
|
|
9131
|
+
codeconscious --version print the version (-v, or: codeconscious version)
|
|
8998
9132
|
codeconscious uninstall remove the hooks from this repository (--all also signs out)
|
|
8999
9133
|
|
|
9000
9134
|
Env: CODECONSCIOUS_API_URL (default https://code-conscious.com), CODECONSCIOUS_SKIP=1 to disable the quiz.
|
|
@@ -9012,6 +9146,11 @@ async function main() {
|
|
|
9012
9146
|
});
|
|
9013
9147
|
return hookMain(rest[0], rest.slice(1), { cwd: process.cwd(), env: process.env });
|
|
9014
9148
|
}
|
|
9149
|
+
if (command === "--version" || command === "-v" || command === "version") {
|
|
9150
|
+
process.stdout.write(`${VERSION}
|
|
9151
|
+
`);
|
|
9152
|
+
process.exit(0);
|
|
9153
|
+
}
|
|
9015
9154
|
const deps = {
|
|
9016
9155
|
cwd: process.cwd(),
|
|
9017
9156
|
env: process.env,
|
|
@@ -9025,6 +9164,9 @@ async function main() {
|
|
|
9025
9164
|
case "uninstall":
|
|
9026
9165
|
process.exit(await runUninstall({ ...deps, all: rest.includes("--all") }));
|
|
9027
9166
|
break;
|
|
9167
|
+
case "logout":
|
|
9168
|
+
process.exit(await runLogout(deps));
|
|
9169
|
+
break;
|
|
9028
9170
|
case "quiz":
|
|
9029
9171
|
process.exit(await runQuiz({ cwd: deps.cwd, env: deps.env }));
|
|
9030
9172
|
break;
|
package/package.json
CHANGED