codeconscious 0.1.2 → 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 +2 -0
- package/dist/cli.cjs +107 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,6 +11,8 @@ 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 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
|
|
14
16
|
- `codeconscious status` show login, hook state and installed version
|
|
15
17
|
- `npx codeconscious --version` print the version
|
|
16
18
|
- `codeconscious --help` list all commands
|
package/dist/cli.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// codeconscious-version: 0.1.
|
|
2
|
+
// codeconscious-version: 0.1.3
|
|
3
3
|
"use strict";
|
|
4
4
|
var __create = Object.create;
|
|
5
5
|
var __defProp = Object.defineProperty;
|
|
@@ -7318,6 +7318,14 @@ var TokenResponseSchema = external_exports.union([
|
|
|
7318
7318
|
TokenGrantedResponseSchema,
|
|
7319
7319
|
TokenPendingResponseSchema
|
|
7320
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
|
+
});
|
|
7321
7329
|
var MAX_DIFF_CHARS = 1e6;
|
|
7322
7330
|
var DiffsRequestSchema = external_exports.object({
|
|
7323
7331
|
/** `owner/name` of the repository the commit belongs to. */
|
|
@@ -7553,6 +7561,7 @@ function writeConfig(dir, config) {
|
|
|
7553
7561
|
} catch {
|
|
7554
7562
|
}
|
|
7555
7563
|
import_node_fs2.default.renameSync(tmp, file);
|
|
7564
|
+
clearAuthExpired(dir);
|
|
7556
7565
|
} catch (err) {
|
|
7557
7566
|
import_node_fs2.default.rmSync(tmp, { force: true });
|
|
7558
7567
|
throw err;
|
|
@@ -7563,7 +7572,33 @@ function clearConfig(dir) {
|
|
|
7563
7572
|
import_node_fs2.default.rmSync(configPath(dir), { force: true });
|
|
7564
7573
|
} catch {
|
|
7565
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
|
+
}
|
|
7594
|
+
}
|
|
7595
|
+
function clearAuthExpired(dir) {
|
|
7596
|
+
try {
|
|
7597
|
+
import_node_fs2.default.rmSync(authExpiredPath(dir), { force: true });
|
|
7598
|
+
} catch {
|
|
7599
|
+
}
|
|
7566
7600
|
}
|
|
7601
|
+
var AUTH_EXPIRED_MESSAGE = "Your CLI login expired or was revoked. Run: npx codeconscious@latest init";
|
|
7567
7602
|
function getToken(env = process.env) {
|
|
7568
7603
|
return readConfig(configDir(env)).token;
|
|
7569
7604
|
}
|
|
@@ -7598,8 +7633,10 @@ function createApiClient(opts) {
|
|
|
7598
7633
|
const shouldLog = opts.log ?? true;
|
|
7599
7634
|
async function call(method, pathAndQuery, schema, body) {
|
|
7600
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));
|
|
7601
7638
|
if (!result.ok && shouldLog) {
|
|
7602
|
-
logLine(`api ${method} ${pathAndQuery.split("?")[0]} -> ${result.error}
|
|
7639
|
+
logLine(`api ${method} ${pathAndQuery.split("?")[0]} -> ${result.error}`, opts.env);
|
|
7603
7640
|
}
|
|
7604
7641
|
return result;
|
|
7605
7642
|
}
|
|
@@ -7624,6 +7661,7 @@ function createApiClient(opts) {
|
|
|
7624
7661
|
});
|
|
7625
7662
|
const text2 = await res.text();
|
|
7626
7663
|
if (!res.ok) return { ok: false, status: res.status, error: `HTTP ${res.status}` };
|
|
7664
|
+
if (!schema) return { ok: true, data: void 0 };
|
|
7627
7665
|
let json;
|
|
7628
7666
|
try {
|
|
7629
7667
|
json = JSON.parse(text2);
|
|
@@ -7659,6 +7697,9 @@ function createApiClient(opts) {
|
|
|
7659
7697
|
const query = `?repo=${encodeURIComponent(repo)}&sha=${encodeURIComponent(sha)}`;
|
|
7660
7698
|
return await call("GET", `/questions/next${query}`, QuestionsNextResponseSchema);
|
|
7661
7699
|
},
|
|
7700
|
+
async revokeToken() {
|
|
7701
|
+
return await call("DELETE", "/cli/token", void 0);
|
|
7702
|
+
},
|
|
7662
7703
|
async postAnswer(body) {
|
|
7663
7704
|
return await call("POST", "/answers", AnswersResponseSchema, body);
|
|
7664
7705
|
}
|
|
@@ -7920,7 +7961,7 @@ function hooksInstalled(dir) {
|
|
|
7920
7961
|
// src/version.ts
|
|
7921
7962
|
var import_node_fs6 = __toESM(require("node:fs"), 1);
|
|
7922
7963
|
var import_node_path6 = __toESM(require("node:path"), 1);
|
|
7923
|
-
var VERSION = true ? "0.1.
|
|
7964
|
+
var VERSION = true ? "0.1.3" : "dev";
|
|
7924
7965
|
var VERSION_MARKER = "codeconscious-version:";
|
|
7925
7966
|
var MARKER_RE = new RegExp(`^// ${VERSION_MARKER} ([0-9A-Za-z.+-]{1,64})$`, "m");
|
|
7926
7967
|
function installedRuntimeVersion(cfgDir) {
|
|
@@ -8022,7 +8063,7 @@ async function runInit(deps) {
|
|
|
8022
8063
|
return 1;
|
|
8023
8064
|
}
|
|
8024
8065
|
const apiBase = apiBaseUrl(deps.env);
|
|
8025
|
-
if (!getToken(deps.env)) {
|
|
8066
|
+
if (!getToken(deps.env) || isAuthExpired(cfgDir)) {
|
|
8026
8067
|
const api = createApiClient({
|
|
8027
8068
|
baseUrl: apiBase,
|
|
8028
8069
|
timeoutMs: 1e4,
|
|
@@ -8091,6 +8132,28 @@ or re-run with --force to add it (without any machine-specific path).`
|
|
|
8091
8132
|
say?.outro("Done. You will get one question per push (press s to skip).");
|
|
8092
8133
|
return 0;
|
|
8093
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
|
+
}
|
|
8094
8157
|
async function runUninstall(deps) {
|
|
8095
8158
|
const say = deps.quiet ? void 0 : dist_exports;
|
|
8096
8159
|
const dir = hooksDir(deps.cwd);
|
|
@@ -8100,8 +8163,7 @@ async function runUninstall(deps) {
|
|
|
8100
8163
|
}
|
|
8101
8164
|
for (const report of uninstallHooks(dir)) say?.log.step(describe(report));
|
|
8102
8165
|
if (deps.all) {
|
|
8103
|
-
|
|
8104
|
-
say?.log.step("Signed out (token deleted).");
|
|
8166
|
+
await runLogout(deps);
|
|
8105
8167
|
}
|
|
8106
8168
|
say?.outro("CodeConscious hooks removed from this repository.");
|
|
8107
8169
|
return 0;
|
|
@@ -8117,7 +8179,11 @@ function statusLines(deps) {
|
|
|
8117
8179
|
lines.push(`Hook runtime: ${runtime}, differs from this CLI (${update})`);
|
|
8118
8180
|
else lines.push(`Hook runtime: ${runtime}`);
|
|
8119
8181
|
lines.push(`API: ${apiBaseUrl(deps.env)}`);
|
|
8120
|
-
|
|
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
|
+
}
|
|
8121
8187
|
const dir = hooksDir(deps.cwd);
|
|
8122
8188
|
if (dir) {
|
|
8123
8189
|
const state = hooksInstalled(dir);
|
|
@@ -8429,7 +8495,8 @@ async function runQuiz(deps) {
|
|
|
8429
8495
|
baseUrl: apiBaseUrl(deps.env),
|
|
8430
8496
|
token,
|
|
8431
8497
|
timeoutMs: QUIZ_TIMEOUT_MS,
|
|
8432
|
-
fetchImpl: deps.fetchImpl
|
|
8498
|
+
fetchImpl: deps.fetchImpl,
|
|
8499
|
+
env: deps.env
|
|
8433
8500
|
});
|
|
8434
8501
|
const ask = deps.ask ?? ((q, t2) => askQuestion(q, t2, { timeoutMs: ANSWER_CEILING_MS, countdown: false }));
|
|
8435
8502
|
const confirmAnother = deps.confirmAnother ?? (async (t2) => {
|
|
@@ -8445,6 +8512,10 @@ async function runQuiz(deps) {
|
|
|
8445
8512
|
for (let round = 0; round < MAX_QUESTIONS; round++) {
|
|
8446
8513
|
const next = await api.nextQuestion(repo, sha);
|
|
8447
8514
|
if (!next.ok) {
|
|
8515
|
+
if (next.status === 401) {
|
|
8516
|
+
say(AUTH_EXPIRED_MESSAGE);
|
|
8517
|
+
return 0;
|
|
8518
|
+
}
|
|
8448
8519
|
say("Could not reach CodeConscious. Try again later.");
|
|
8449
8520
|
return 0;
|
|
8450
8521
|
}
|
|
@@ -8799,6 +8870,16 @@ var TOKEN_PATTERNS = [
|
|
|
8799
8870
|
// Slack
|
|
8800
8871
|
/\bAIza[0-9A-Za-z_-]{35}\b/g,
|
|
8801
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
|
|
8802
8883
|
/\bSG\.[A-Za-z0-9_-]{16,}\.[A-Za-z0-9_-]{16,}/g,
|
|
8803
8884
|
// SendGrid
|
|
8804
8885
|
/\bre_[A-Za-z0-9]{20,}\b/g,
|
|
@@ -8807,6 +8888,8 @@ var TOKEN_PATTERNS = [
|
|
|
8807
8888
|
// JWT
|
|
8808
8889
|
/-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z0-9 ]*PRIVATE KEY-----|$)/g
|
|
8809
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;
|
|
8810
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;
|
|
8811
8894
|
var UNQUOTED = /((?:api[_-]?key|apikey|secret|token|passwd|password|pwd|private[_-]?key|access[_-]?key)[A-Za-z0-9_]*\s*[:=]\s*)([^\s"'`,;()<>{}[\]]{8,})/gi;
|
|
8812
8895
|
function looksLikeSecretValue(value) {
|
|
@@ -8830,6 +8913,14 @@ function redactSecrets(text2) {
|
|
|
8830
8913
|
};
|
|
8831
8914
|
let out = text2;
|
|
8832
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
|
+
});
|
|
8833
8924
|
out = out.replace(ASSIGNMENT, (_m, key, quote) => {
|
|
8834
8925
|
count++;
|
|
8835
8926
|
return `${key}${quote}${REDACTED}${quote}`;
|
|
@@ -8927,7 +9018,8 @@ async function runUpload(deps) {
|
|
|
8927
9018
|
baseUrl: apiBaseUrl(deps.env),
|
|
8928
9019
|
token,
|
|
8929
9020
|
timeoutMs: HOOK_TIMEOUT_MS,
|
|
8930
|
-
fetchImpl: deps.fetchImpl
|
|
9021
|
+
fetchImpl: deps.fetchImpl,
|
|
9022
|
+
env: deps.env
|
|
8931
9023
|
});
|
|
8932
9024
|
const res = await api.postDiff(body.data);
|
|
8933
9025
|
return res.ok ? "uploaded" : "failed";
|
|
@@ -8955,7 +9047,8 @@ async function runPrePush(deps) {
|
|
|
8955
9047
|
baseUrl: apiBaseUrl(deps.env),
|
|
8956
9048
|
token,
|
|
8957
9049
|
timeoutMs: HOOK_TIMEOUT_MS,
|
|
8958
|
-
fetchImpl: deps.fetchImpl
|
|
9050
|
+
fetchImpl: deps.fetchImpl,
|
|
9051
|
+
env: deps.env
|
|
8959
9052
|
});
|
|
8960
9053
|
const next = await api.nextQuestion(repo, sha);
|
|
8961
9054
|
if (!next.ok) return "failed-open";
|
|
@@ -9034,6 +9127,7 @@ Usage:
|
|
|
9034
9127
|
codeconscious quiz answer pending questions for your recent commits
|
|
9035
9128
|
(run it after an AI agent committed for you)
|
|
9036
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
|
|
9037
9131
|
codeconscious --version print the version (-v, or: codeconscious version)
|
|
9038
9132
|
codeconscious uninstall remove the hooks from this repository (--all also signs out)
|
|
9039
9133
|
|
|
@@ -9070,6 +9164,9 @@ async function main() {
|
|
|
9070
9164
|
case "uninstall":
|
|
9071
9165
|
process.exit(await runUninstall({ ...deps, all: rest.includes("--all") }));
|
|
9072
9166
|
break;
|
|
9167
|
+
case "logout":
|
|
9168
|
+
process.exit(await runLogout(deps));
|
|
9169
|
+
break;
|
|
9073
9170
|
case "quiz":
|
|
9074
9171
|
process.exit(await runQuiz({ cwd: deps.cwd, env: deps.env }));
|
|
9075
9172
|
break;
|
package/package.json
CHANGED