@routinecrew/routinecode 2.31.77 → 2.31.86
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 -2
- package/bin/cli.sh +23 -0
- package/bin/prompt-vault.dat +1 -0
- package/bin/prompt-vault.js +51 -1
- package/bin/rc-board.js +58 -0
- package/bin/rc-config.js +756 -1
- package/bin/rc-credit-turn.js +2 -1
- package/bin/rc-grant.js +2 -1
- package/bin/rc-login.js +2 -0
- package/bin/rc-map.js +132 -0
- package/bin/rc-privacy.js +200 -0
- package/bin/rc-skills.js +31 -0
- package/bin/rc-team.js +2 -1
- package/bin/setup.js +4 -0
- package/hooks/cc-compat-watch.js +2 -1
- package/hooks/claim-questions.json +40 -0
- package/hooks/hooks-config.json +108 -1
- package/hooks/lib/agent_budget.py +122 -0
- package/hooks/lib/agent_telemetry.py +143 -0
- package/hooks/lib/attest_reader.py +15 -6
- package/hooks/lib/attribution_judge.py +109 -0
- package/hooks/lib/board-golden.json +268 -0
- package/hooks/lib/board.py +503 -0
- package/hooks/lib/board_sync.py +535 -0
- package/hooks/lib/cc-surface.json +1 -1
- package/hooks/lib/claim_structure.py +412 -0
- package/hooks/lib/completion_log.py +12 -5
- package/hooks/lib/config_bash_track.py +114 -28
- package/hooks/lib/config_guard.py +137 -5
- package/hooks/lib/edit_tracker.py +182 -0
- package/hooks/lib/error_line.py +94 -0
- package/hooks/lib/escalation_restore.py +66 -0
- package/hooks/lib/i18n.py +37 -15
- package/hooks/lib/knowledge_items.py +1407 -0
- package/hooks/lib/knowledge_scope.py +123 -0
- package/hooks/lib/known_solution.py +37 -9
- package/hooks/lib/log_compact.py +85 -0
- package/hooks/lib/metacog_signals.py +228 -0
- package/hooks/lib/orch_decision.py +690 -0
- package/hooks/lib/premise-golden.json +96 -0
- package/hooks/lib/presence.py +10 -3
- package/hooks/lib/privacy_log.py +35 -0
- package/hooks/lib/receipt.py +137 -14
- package/hooks/lib/review_gate.py +83 -0
- package/hooks/lib/routine_skill_eval.py +213 -0
- package/hooks/lib/secret_filter.py +2 -1
- package/hooks/lib/skill_drafts.py +188 -0
- package/hooks/lib/sync_manager.py +121 -26
- package/hooks/lib/usage_v2.py +680 -0
- package/hooks/lib/work_kind.py +198 -0
- package/hooks/lib/work_kind_events.py +361 -0
- package/hooks/pending-drainer.sh +28 -0
- package/hooks/post-agent-budget.sh +50 -0
- package/hooks/post-agent-return.sh +89 -3
- package/hooks/post-bash-failure.sh +39 -0
- package/hooks/post-bash-knowledge.sh +15 -34
- package/hooks/post-bash-verify.sh +33 -16
- package/hooks/post-build-check.sh +16 -18
- package/hooks/post-config-context.sh +13 -0
- package/hooks/post-delegation-nudge.sh +12 -1
- package/hooks/post-edit-track.sh +19 -28
- package/hooks/post-orch-decision.sh +35 -0
- package/hooks/post-read-config-context.sh +20 -0
- package/hooks/pre-account-guard.sh +1 -1
- package/hooks/pre-agent-spawn.mjs +2 -1
- package/hooks/pre-agent-spawn.sh +12 -1
- package/hooks/pre-bash-guard.sh +61 -3
- package/hooks/pre-bash-knowledge.sh +46 -0
- package/hooks/pre-credit-guard.sh +1 -1
- package/hooks/pre-edit-board.sh +44 -0
- package/hooks/pre-edit-check.sh +29 -5
- package/hooks/pre-edit-config-gate.sh +1 -1
- package/hooks/pre-edit-domain-gate.sh +23 -22
- package/hooks/pre-mark-complete.sh +32 -4
- package/hooks/pre-read-knowledge-inject.sh +34 -24
- package/hooks/pre-review-gate.sh +17 -0
- package/hooks/recorder-runner.sh +25 -2
- package/hooks/session-start-compact.sh +28 -0
- package/hooks/session-start.sh +167 -19
- package/hooks/skill-knowledge.sh +37 -0
- package/hooks/stop-claim-check.v3.sh +21 -3
- package/hooks/stop-usage-metrics.sh +138 -83
- package/hooks/subagent-stop-usage.sh +25 -0
- package/hooks/user-prompt-submit.sh +10 -4
- package/mcp-db-manager/dist/analyzers/duplicate-detector.js +1 -1
- package/mcp-db-manager/dist/core/model-parser.js +1 -1
- package/mcp-db-manager/dist/core/schema-reader.js +1 -1
- package/mcp-db-manager/dist/executors/migration-executor.js +1 -1
- package/mcp-db-manager/dist/generators/migration-generator.js +1 -1
- package/mcp-db-manager/dist/index.js +1 -1
- package/mcp-db-manager/dist/validators/schema-validator.js +1 -1
- package/mcp-dev-tester/dist/analyzers/auth-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/backend-analyzer.js +1 -1
- package/mcp-dev-tester/dist/analyzers/endpoint-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/frontend-analyzer.js +1 -1
- package/mcp-dev-tester/dist/analyzers/runtime-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/analyzers/type-comparator.js +1 -1
- package/mcp-dev-tester/dist/analyzers/validation-diagnoser.js +1 -1
- package/mcp-dev-tester/dist/attestation.js +1 -1
- package/mcp-dev-tester/dist/browser/playwright-manager.js +1 -1
- package/mcp-dev-tester/dist/browser/ui-tester.js +1 -1
- package/mcp-dev-tester/dist/config/project-config.js +1 -1
- package/mcp-dev-tester/dist/index.js +1 -1
- package/mcp-dev-tester/dist/testers/api-tester.js +1 -1
- package/mcp-doc-fetcher/dist/index.js +1 -1
- package/mcp-html-renderer/dist/index.js +1 -1
- package/mcp-html-renderer/dist/preview.js +1 -1
- package/mcp-html-renderer/dist/template-engine.js +1 -1
- package/mcp-intelligence/dist/concept-catalog.js +1 -1
- package/mcp-intelligence/dist/concept-server-proxy.js +1 -1
- package/mcp-intelligence/dist/config-auth.js +1 -1
- package/mcp-intelligence/dist/contracts.generated.js +1 -1
- package/mcp-intelligence/dist/domain-templates.js +1 -1
- package/mcp-intelligence/dist/grounding.js +1 -1
- package/mcp-intelligence/dist/handlers.js +1 -1
- package/mcp-intelligence/dist/index.js +1 -1
- package/mcp-intelligence/dist/intelligence-file.js +1 -1
- package/mcp-intelligence/dist/knowledge-critic.js +1 -1
- package/mcp-intelligence/dist/knowledge-guide.js +1 -0
- package/mcp-intelligence/dist/knowledge-handlers.js +1 -1
- package/mcp-intelligence/dist/knowledge-migrate.js +1 -0
- package/mcp-intelligence/dist/knowledge-record.js +1 -0
- package/mcp-intelligence/dist/knowledge-scope.js +1 -0
- package/mcp-intelligence/dist/mention-extractor.js +1 -1
- package/mcp-intelligence/dist/provenance.js +1 -1
- package/mcp-intelligence/dist/sanitize.generated.js +242 -0
- package/mcp-intelligence/dist/semantic-embedder.js +1 -1
- package/mcp-log-watcher/dist/config-auth.js +1 -1
- package/mcp-log-watcher/dist/file-watcher.js +1 -1
- package/mcp-log-watcher/dist/index.js +1 -1
- package/mcp-log-watcher/dist/known-solutions.js +1 -1
- package/mcp-log-watcher/dist/log-store.js +1 -1
- package/mcp-log-watcher/dist/sanitize.generated.js +242 -0
- package/mcp-log-watcher/dist/websocket-server.js +1 -1
- package/mcp-log-watcher/package.json +1 -1
- package/mcp-plan-manager/dist/__tests__/file-ops-knowledge-dir.test.js +1 -1
- package/mcp-plan-manager/dist/__tests__/plan-parser.test.js +1 -1
- package/mcp-plan-manager/dist/file-ops.js +1 -1
- package/mcp-plan-manager/dist/index.js +1 -1
- package/mcp-plan-manager/dist/plan-parser.js +1 -1
- package/mcp-project-context/dist/git-ops.js +1 -1
- package/mcp-project-context/dist/index.js +1 -1
- package/mcp-project-context/dist/project-analysis.js +1 -1
- package/mcp-routinecode/dist/agent-tracker.js +1 -1
- package/mcp-routinecode/dist/analysis-ledger.js +590 -0
- package/mcp-routinecode/dist/attestation.js +1 -1
- package/mcp-routinecode/dist/blast-radius.js +1 -1
- package/mcp-routinecode/dist/board.js +1 -0
- package/mcp-routinecode/dist/build-id.js +1 -0
- package/mcp-routinecode/dist/changeset.js +1 -1
- package/mcp-routinecode/dist/config-auth.js +1 -1
- package/mcp-routinecode/dist/config-map/applied.js +1 -0
- package/mcp-routinecode/dist/config-map/arch-graph.js +1 -1
- package/mcp-routinecode/dist/config-map/architect-store.js +1132 -1
- package/mcp-routinecode/dist/config-map/assign.js +1 -1
- package/mcp-routinecode/dist/config-map/audit-cli.js +1 -1
- package/mcp-routinecode/dist/config-map/audit.js +1 -1
- package/mcp-routinecode/dist/config-map/blocks.js +1 -1
- package/mcp-routinecode/dist/config-map/briefing.js +541 -1
- package/mcp-routinecode/dist/config-map/certify.js +10 -5
- package/mcp-routinecode/dist/config-map/const-use.js +1 -1
- package/mcp-routinecode/dist/config-map/context.js +219 -0
- package/mcp-routinecode/dist/config-map/convention-candidates.js +1 -0
- package/mcp-routinecode/dist/config-map/decisions.js +1 -1
- package/mcp-routinecode/dist/config-map/decls.js +1 -1
- package/mcp-routinecode/dist/config-map/drift.js +1 -1
- package/mcp-routinecode/dist/config-map/dup-safety.js +1 -1
- package/mcp-routinecode/dist/config-map/extract.js +1 -1
- package/mcp-routinecode/dist/config-map/field-contract.js +1 -1
- package/mcp-routinecode/dist/config-map/gate.js +796 -1
- package/mcp-routinecode/dist/config-map/hash.js +1 -1
- package/mcp-routinecode/dist/config-map/ident-norm.js +1 -1
- package/mcp-routinecode/dist/config-map/index-store.js +1051 -1
- package/mcp-routinecode/dist/config-map/light-eval.js +253 -1
- package/mcp-routinecode/dist/config-map/link.js +1 -1
- package/mcp-routinecode/dist/config-map/linked-repos.js +1 -1
- package/mcp-routinecode/dist/config-map/lookup.js +1 -1
- package/mcp-routinecode/dist/config-map/louvain.js +1 -1
- package/mcp-routinecode/dist/config-map/maintenance-cli.js +1 -1
- package/mcp-routinecode/dist/config-map/names.js +1 -1
- package/mcp-routinecode/dist/config-map/post-bash-eval.js +105 -0
- package/mcp-routinecode/dist/config-map/proposals.js +1 -1
- package/mcp-routinecode/dist/config-map/ratchet.js +148 -0
- package/mcp-routinecode/dist/config-map/recheck.js +148 -1
- package/mcp-routinecode/dist/config-map/repo-id.js +1 -1
- package/mcp-routinecode/dist/config-map/route-security.js +1 -1
- package/mcp-routinecode/dist/config-map/rule-import.js +1 -1
- package/mcp-routinecode/dist/config-map/scc.js +1 -1
- package/mcp-routinecode/dist/config-map/shape-eval.js +1 -1
- package/mcp-routinecode/dist/config-map/shape.js +1 -1
- package/mcp-routinecode/dist/config-map/snapshot.js +1 -1
- package/mcp-routinecode/dist/config-map/sole-impl.js +1 -1
- package/mcp-routinecode/dist/config-map/stable-id.js +1 -1
- package/mcp-routinecode/dist/config-map/store.js +1 -1
- package/mcp-routinecode/dist/config-map/swagger-check.js +1 -1
- package/mcp-routinecode/dist/config-map/task-eval.js +369 -1
- package/mcp-routinecode/dist/config-map/templates.js +1 -1
- package/mcp-routinecode/dist/contracts.generated.js +1 -1
- package/mcp-routinecode/dist/coverage.js +1 -1
- package/mcp-routinecode/dist/edit-tracker.js +1 -0
- package/mcp-routinecode/dist/explorer-advisor.js +1 -1
- package/mcp-routinecode/dist/failure-tracker.js +1 -1
- package/mcp-routinecode/dist/file-lock-registry.js +1 -1
- package/mcp-routinecode/dist/file-risk-scorer.js +1 -1
- package/mcp-routinecode/dist/index.js +1 -1
- package/mcp-routinecode/dist/known-solutions.js +1 -1
- package/mcp-routinecode/dist/ledger-miner.js +1 -1
- package/mcp-routinecode/dist/normalize-sig.js +1 -0
- package/mcp-routinecode/dist/observed-draft.js +1 -1
- package/mcp-routinecode/dist/observed-escalation.js +1 -0
- package/mcp-routinecode/dist/pattern-matcher.js +1 -1
- package/mcp-routinecode/dist/route-match.js +1 -1
- package/mcp-routinecode/dist/routines.js +1 -1
- package/mcp-routinecode/dist/rule-engine.js +1 -1
- package/mcp-routinecode/dist/rule-promoter.js +1 -1
- package/mcp-routinecode/dist/sanitize.generated.js +242 -0
- package/mcp-routinecode/dist/session-registry.js +1 -0
- package/mcp-routinecode/dist/skill-pack/sync.js +629 -0
- package/mcp-routinecode/dist/skill-pack/validate.js +278 -0
- package/mcp-routinecode/dist/telemetry-analyzer.js +1 -1
- package/mcp-routinecode/dist/test-runner.js +1 -1
- package/mcp-routinecode/dist/verification.js +1 -1
- package/mcp-routinecode/dist/viral-loop.js +1 -1
- package/mcp-routinecode/package.json +1 -1
- package/package.json +3 -3
- package/plugin/.claude-plugin/plugin.json +1 -1
- package/plugin/agents/analyzer.md.sealed +1 -1
- package/plugin/agents/architect.md.sealed +1 -1
- package/plugin/agents/crawler.md.sealed +1 -1
- package/plugin/agents/explorer.md.sealed +1 -1
- package/plugin/agents/implementor.md.sealed +1 -1
- package/plugin/agents/looker.md.sealed +1 -1
- package/plugin/agents/planner.md.sealed +1 -1
- package/plugin/agents/recorder.md.sealed +1 -1
- package/plugin/agents/reviewer.md.sealed +1 -1
- package/plugin/agents/verifier.md.sealed +1 -1
- package/plugin/commands/analyze.md.sealed +1 -1
- package/plugin/commands/plan.md.sealed +1 -1
- package/plugin/commands/rc.md.sealed +1 -1
- package/plugin/commands/receipt.md.sealed +1 -1
- package/plugin/commands/recharge.md.sealed +1 -1
- package/plugin/commands/routines.md.sealed +1 -1
- package/plugin/commands/share.md.sealed +1 -1
- package/plugin/routinecode-prompt.md.sealed +1 -1
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
// ⚠️ AUTO-GENERATED from shared/sanitize.ts — DO NOT EDIT.
|
|
2
|
+
// 수정은 정본(shared/sanitize.ts)에서 하고 `node scripts/sync-contracts.mjs` 재실행.
|
|
3
|
+
/**
|
|
4
|
+
* sanitize — 지식 전송 최소화의 단일 정본 (설계 15 §4.1·§4.2·§4.4).
|
|
5
|
+
*
|
|
6
|
+
* ⚠️ 이 파일이 정본이다. 각 서버의 `src/sanitize.generated.ts`는 빌드 시
|
|
7
|
+
* `scripts/sync-contracts.mjs`가 복사한 것 — 직접 수정하지 마라.
|
|
8
|
+
*
|
|
9
|
+
* 규칙: 전송 직전이 아니라 **큐 적재 전**에 적용한다. Python 드레이너(hooks/pending-drainer.sh)에는
|
|
10
|
+
* 재구현하지 않는다. 드레이너는 `sv` 표식이 있는 항목만 보낸다.
|
|
11
|
+
*
|
|
12
|
+
* SANITIZE_RULES·normalizePaths 는 서버 anonymizer.ts 와 같은 구현이다.
|
|
13
|
+
* 공통 벡터 = shared/path-sanitize-vectors.json (양쪽 테스트가 같은 파일을 읽는다).
|
|
14
|
+
*
|
|
15
|
+
* 공통 한계(클라이언트·서버 동일, 벡터 knownLimits 로 고정):
|
|
16
|
+
* - 공백이 든 Windows 경로는 첫 공백까지만 치환한다 (C:\Program Files\x → `<path> Files\x`).
|
|
17
|
+
* - 알려진 루트가 아니고 확장자도 없는 절대 경로는 유지한다 (/code/service/main). API 경로와 구분할 수 없다.
|
|
18
|
+
* - 폴더 없는 파일 이름은 유지한다 (refund.service.ts failed). `package.json is missing` 같은 일반 문장과 구분할 수 없다.
|
|
19
|
+
* - 세그먼트가 64개를 넘는 경로는 앞부분만 치환된다. 선형 시간을 위한 상한이고, 이런 입력은 멱등도 보장하지 않는다.
|
|
20
|
+
*/
|
|
21
|
+
import * as fs from 'fs';
|
|
22
|
+
import * as path from 'path';
|
|
23
|
+
import { homedir } from 'os';
|
|
24
|
+
/** 전송 본문 최상위 동의 버전(설계 15 §4.4). 서버 KNOWLEDGE_CONSENT_ENFORCE 가 이 값의 유무를 본다. */
|
|
25
|
+
export const CONSENT_VERSION = 1;
|
|
26
|
+
/** 큐 항목 정제 표식. 드레이너는 이 값이 없는 지식 항목을 보내지 않고 flushPending 에 넘긴다. */
|
|
27
|
+
export const SANITIZE_VERSION = 1;
|
|
28
|
+
/**
|
|
29
|
+
* 시크릿·개인정보 마스킹 규칙(순서 고정). 공개 행 점검 스크립트도 같은 규칙을 쓴다(public-row-scan.ts).
|
|
30
|
+
* kind: secret=자격증명, pii=회사·개인 식별 단서, path=사용자 디렉터리.
|
|
31
|
+
*
|
|
32
|
+
* ReDoS: 겹치는 시작 위치마다 끝까지 훑는 규칙(email·jwt·db_url)은 반복 횟수에 상한을 둔다.
|
|
33
|
+
* 상한 없는 `+`·`{n,}` 를 새로 넣지 마라. 20KB 공격 문자열 1건이 200ms, 100KB 는 수 초였다.
|
|
34
|
+
*/
|
|
35
|
+
export const SANITIZE_RULES = [
|
|
36
|
+
// User directory paths
|
|
37
|
+
{ id: 'unix_user_dir', kind: 'path', re: /\/Users\/[^/]+\//g, to: '/Users/***/' },
|
|
38
|
+
{ id: 'linux_home_dir', kind: 'path', re: /\/home\/[^/]+\//g, to: '/home/***/' },
|
|
39
|
+
{ id: 'windows_user_dir', kind: 'path', re: /C:\\Users\\[^\\]+\\/g, to: 'C:\\Users\\***\\' },
|
|
40
|
+
// IP addresses
|
|
41
|
+
{ id: 'ip_address', kind: 'pii', re: /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/g, to: '***.***.***.***' },
|
|
42
|
+
// Bare provider tokens (구분자 없이도 마스킹) — sk-ant-…, sk-…, sk-proj-… 등
|
|
43
|
+
{ id: 'provider_key', kind: 'secret', re: /\bsk-(?:ant-|proj-|ws-|live-|test-)?[a-zA-Z0-9]{2,}-?[a-zA-Z0-9_-]{16,}/g, to: 'sk-***' },
|
|
44
|
+
// AWS access key IDs / GitHub tokens (구분자 없는 고정 포맷)
|
|
45
|
+
{ id: 'aws_key', kind: 'secret', re: /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g, to: '***AWS_KEY***' },
|
|
46
|
+
{ id: 'github_token', kind: 'secret', re: /\bgh[pousr]_[A-Za-z0-9]{20,}\b/g, to: '***GH_TOKEN***' },
|
|
47
|
+
// R3: PEM 개인키 블록 전체 마스킹 (cross-tenant 유출 방지). END 가 없으면 끝까지 지운다(길이 상한에 잘린 키가 남지 않게)
|
|
48
|
+
{ id: 'private_key', kind: 'secret', re: /-----BEGIN (?:RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY-----[\s\S]*?(?:-----END (?:RSA |EC |OPENSSH |DSA |PGP )?PRIVATE KEY-----|$)/g, to: '***PRIVATE_KEY***' },
|
|
49
|
+
// R3: JWT (eyJ….eyJ….sig) — 세션/위임 토큰
|
|
50
|
+
{ id: 'jwt', kind: 'secret', re: /\beyJ[A-Za-z0-9_-]{5,1024}\.eyJ[A-Za-z0-9_-]{5,20000}\.[A-Za-z0-9_-]{5,4096}/g, to: '***JWT***' },
|
|
51
|
+
// R3: 공급자 고정 포맷 토큰 — Slack / Google / Stripe / Bearer 헤더
|
|
52
|
+
{ id: 'slack_token', kind: 'secret', re: /\bxox[baprs]-[A-Za-z0-9-]{10,}/g, to: '***SLACK_TOKEN***' },
|
|
53
|
+
{ id: 'google_key', kind: 'secret', re: /\bAIza[0-9A-Za-z_-]{35}\b/g, to: '***GOOGLE_KEY***' },
|
|
54
|
+
{ id: 'stripe_key', kind: 'secret', re: /\b(?:sk|pk|rk)_(?:live|test)_[A-Za-z0-9]{16,}/g, to: '***STRIPE_KEY***' },
|
|
55
|
+
{ id: 'bearer_token', kind: 'secret', re: /\bBearer\s+[A-Za-z0-9._~+/-]{20,}=*/gi, to: 'Bearer ***' },
|
|
56
|
+
// R3: 고엔트로피 hex 시크릿(64자+, sha256/토큰류) — 지식 의미 손실 없음
|
|
57
|
+
{ id: 'hex_secret', kind: 'secret', re: /\b[a-fA-F0-9]{64,}\b/g, to: '***HEX_SECRET***' },
|
|
58
|
+
// key=value / key: value 형태
|
|
59
|
+
{ id: 'key_value_secret', kind: 'secret', re: /(api[-_]?key|token|secret|password|credential)[=:\s]["']?[a-zA-Z0-9_\-]{10,}/gi, to: '$1=***' },
|
|
60
|
+
// Email addresses
|
|
61
|
+
{ id: 'email', kind: 'pii', re: /[a-zA-Z0-9._%+-]{1,64}@[a-zA-Z0-9.-]{1,255}\.[a-zA-Z]{2,63}/g, to: '***@***.***' },
|
|
62
|
+
// DB connection strings
|
|
63
|
+
{ id: 'db_url', kind: 'secret', re: /postgres(ql)?:\/\/[^@]{1,1024}@[^/]{1,255}/g, to: 'postgresql://***:***@***' },
|
|
64
|
+
];
|
|
65
|
+
/**
|
|
66
|
+
* 정제 입력 길이 상한(문자 수). 초과분은 버리고 끝에 TRUNCATED_MARKER 를 붙인다. 결과는 표식 포함 이 값을 넘지 않는다.
|
|
67
|
+
* 서버 DTO 도 같은 값을 max 로 쓴다. 새 CLI 는 정제가 먼저 자르므로 400 이 나지 않는다.
|
|
68
|
+
*/
|
|
69
|
+
export const SANITIZE_MAX_CHARS = 20_000;
|
|
70
|
+
export const TRUNCATED_MARKER = ' [truncated]';
|
|
71
|
+
const CLAMP_TOKEN_WINDOW = 512;
|
|
72
|
+
/** 잘린 토큰은 앞부분만 남아 규칙이 못 잡으므로 경계 근처 공백까지 물러나서 자른다. 서로게이트 쌍은 쪼개지 않는다. */
|
|
73
|
+
export function clampText(text) {
|
|
74
|
+
if (text.length <= SANITIZE_MAX_CHARS)
|
|
75
|
+
return text;
|
|
76
|
+
let cut = SANITIZE_MAX_CHARS - TRUNCATED_MARKER.length;
|
|
77
|
+
for (let i = cut - 1; i >= cut - CLAMP_TOKEN_WINDOW; i--) {
|
|
78
|
+
if (/\s/.test(text[i])) {
|
|
79
|
+
cut = i;
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const last = text.charCodeAt(cut - 1);
|
|
84
|
+
if (last >= 0xd800 && last <= 0xdbff)
|
|
85
|
+
cut -= 1;
|
|
86
|
+
return text.slice(0, cut) + TRUNCATED_MARKER;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 경로 정규화 2차 방어 (설계 15 §4.2). 파일 경로를 `<path>` 로 치환한다.
|
|
90
|
+
*
|
|
91
|
+
* 치환: 드라이브·홈·`./`·`../`·UNC 로 시작하는 경로, 알려진 루트의 절대 경로, 파일 확장자가 있는 경로.
|
|
92
|
+
* 유지: URL(file:// 제외), API 경로(/api/v1/users), 확장자 없는 단어 조합(text/html, and/or, @types/node).
|
|
93
|
+
*
|
|
94
|
+
* 세그먼트에 `*` 를 허용해 과거 마스킹 결과(/Users/ 다음 `***` 세그먼트)도 잡는다.
|
|
95
|
+
* 토큰 시작에서만 시도하고 길이를 제한해 입력 길이에 선형으로 동작한다.
|
|
96
|
+
*/
|
|
97
|
+
export const PATH_PLACEHOLDER = '<path>';
|
|
98
|
+
const SEG_START = String.raw `\p{L}\p{N}_.@+~*\-`;
|
|
99
|
+
const SEG = `[${SEG_START}()\\[\\]]`;
|
|
100
|
+
const PATH_TOKEN_RE = new RegExp(String.raw `(?<![${SEG_START}/\\])(?:`
|
|
101
|
+
+ String.raw `(?<url>[a-zA-Z][a-zA-Z0-9+.\-]{0,30}://[^\s"'<>` + '`' + `]*)`
|
|
102
|
+
+ '|'
|
|
103
|
+
+ String.raw `(?<prefix>[A-Za-z]:|\$HOME|\$\{HOME\}|%[A-Za-z]{2,20}%|[${SEG_START}]{1,255})?`
|
|
104
|
+
+ String.raw `(?<body>(?:[/\\]{1,2}${SEG}{1,255}){1,64})[/\\]?`
|
|
105
|
+
+ String.raw `(?::\d+){0,2}`
|
|
106
|
+
+ ')', 'gu');
|
|
107
|
+
const ALWAYS_PATH_PREFIX = /^(?:[A-Za-z]:|\$HOME|\$\{HOME\}|%[A-Za-z]{2,20}%|~|\.{1,2})$/;
|
|
108
|
+
const KNOWN_ROOTS = new Set([
|
|
109
|
+
'Users', 'home', 'root', 'var', 'opt', 'etc', 'tmp', 'private', 'mnt', 'srv', 'usr', 'Volumes', 'workspace', 'workspaces',
|
|
110
|
+
]);
|
|
111
|
+
const FILE_NAME_RE = new RegExp('(?:\\.(?:'
|
|
112
|
+
+ 'ts|tsx|mts|cts|js|jsx|mjs|cjs|json|jsonl|py|pyi|go|rs|java|kt|kts|rb|php|sh|bash|zsh|sql|md|mdx|ya?ml|toml|ini|conf|cfg'
|
|
113
|
+
+ '|css|scss|less|html?|vue|svelte|c|h|cc|cpp|hpp|cs|swift|m|mm|lock|txt|log|csv|pem|key|crt|xml|proto|prisma|gradle|tf|bak'
|
|
114
|
+
+ ')|(?:^|\\.)env(?:\\.[\\w-]+)?|^(?:Dockerfile|Makefile)(?:\\.[\\w-]+)?)$', 'i');
|
|
115
|
+
/** 끝의 문장부호·짝 없는 닫는 괄호를 경로 밖으로 돌려준다. */
|
|
116
|
+
function splitTrailing(token) {
|
|
117
|
+
let end = token.length;
|
|
118
|
+
for (;;) {
|
|
119
|
+
const ch = token[end - 1];
|
|
120
|
+
const core = token.slice(0, end);
|
|
121
|
+
const unbalanced = (open, close) => core.split(close).length > core.split(open).length;
|
|
122
|
+
if (ch === '.' || (ch === ')' && unbalanced('(', ')')) || (ch === ']' && unbalanced('[', ']'))) {
|
|
123
|
+
end -= 1;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
return [core, token.slice(end)];
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function isFilePath(prefix, body) {
|
|
130
|
+
if (ALWAYS_PATH_PREFIX.test(prefix))
|
|
131
|
+
return true;
|
|
132
|
+
const segments = body.split(/[/\\]+/).filter(Boolean);
|
|
133
|
+
if (!prefix) {
|
|
134
|
+
if (body.startsWith('\\\\') && segments.length >= 2)
|
|
135
|
+
return true;
|
|
136
|
+
if (segments.length >= 2 && KNOWN_ROOTS.has(segments[0]))
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
return FILE_NAME_RE.test(segments[segments.length - 1] ?? '');
|
|
140
|
+
}
|
|
141
|
+
export function normalizePaths(text) {
|
|
142
|
+
return text.replace(PATH_TOKEN_RE, (match, ...rest) => {
|
|
143
|
+
const groups = rest[rest.length - 1];
|
|
144
|
+
if (groups.url !== undefined)
|
|
145
|
+
return /^file:/i.test(groups.url) ? PATH_PLACEHOLDER : match;
|
|
146
|
+
const prefix = groups.prefix ?? '';
|
|
147
|
+
const [body, trailing] = splitTrailing(groups.body ?? '');
|
|
148
|
+
return isFilePath(prefix, body) ? `${PATH_PLACEHOLDER}${trailing}` : match;
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
export function sanitizeSecrets(text) {
|
|
152
|
+
return SANITIZE_RULES.reduce((out, rule) => out.replace(rule.re, rule.to), clampText(text));
|
|
153
|
+
}
|
|
154
|
+
/** 시크릿 → 경로 순서 고정. 멱등이다. 마스킹이 글자 수를 늘릴 수 있어 끝에서 한 번 더 자른다. */
|
|
155
|
+
export function sanitizeText(text) {
|
|
156
|
+
return clampText(normalizePaths(sanitizeSecrets(text)));
|
|
157
|
+
}
|
|
158
|
+
/** 객체·배열 안의 모든 문자열을 정제한다. 키 이름은 그대로 둔다. */
|
|
159
|
+
export function sanitizeDeep(value) {
|
|
160
|
+
if (typeof value === 'string')
|
|
161
|
+
return sanitizeText(value);
|
|
162
|
+
if (Array.isArray(value))
|
|
163
|
+
return value.map(v => sanitizeDeep(v));
|
|
164
|
+
if (value && typeof value === 'object') {
|
|
165
|
+
const out = {};
|
|
166
|
+
for (const [k, v] of Object.entries(value))
|
|
167
|
+
out[k] = sanitizeDeep(v);
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
return value;
|
|
171
|
+
}
|
|
172
|
+
/** 스니펫 필드. shareSnippets=true 일 때만 보낸다(설계 15 D1). */
|
|
173
|
+
export const SNIPPET_FIELDS = ['fixCode', 'codeExample'];
|
|
174
|
+
/**
|
|
175
|
+
* 엔드포인트별 전송 허용 필드 = 서버 DTO 선언 키. 로컬 entry 의 files·project 등은 서버가 어차피 버리므로 아예 보내지 않는다.
|
|
176
|
+
* 여기 없는 키는 네트워크로 나가지 않는다. shared/data-manifest.json 과 계약 테스트로 묶인다.
|
|
177
|
+
*/
|
|
178
|
+
export const KNOWLEDGE_WIRE_FIELDS = {
|
|
179
|
+
'error-fix': ['domain', 'stack', 'library', 'errorSignature', 'errorCode', 'errorCategory', 'rootCause', 'fixApproach', 'fixCode', 'attempts', 'tagging'],
|
|
180
|
+
pattern: ['domain', 'patternType', 'title', 'description', 'codeExample', 'preconditions', 'applicableTo', 'tagging'],
|
|
181
|
+
quirk: ['library', 'versionRange', 'title', 'quirk', 'evidence', 'workaround', 'severity', 'category', 'tagging'],
|
|
182
|
+
'domain-knowledge': ['category', 'title', 'knowledge', 'scope', 'source', 'project', 'tagging'],
|
|
183
|
+
'ontology/verify': ['errorFixId', 'ref', 'result', 'project', 'techStack', 'source', 'serverObservedResolution', 'resolutionSig', 'resolutionOracle', 'resolutionAttempts', 'projectKey'],
|
|
184
|
+
};
|
|
185
|
+
/** 동의 버전이 없으면 보내지 않고 버리는 config 본문. 이전 기본값(상세 공유 on)으로 큐에 들어간 항목이다. */
|
|
186
|
+
const CONSENT_REQUIRED_CONFIG = new Set(['config/snapshots', 'config/proposals']);
|
|
187
|
+
export function isLegacyConfigItem(endpoint, data) {
|
|
188
|
+
return CONSENT_REQUIRED_CONFIG.has(endpoint) && (data?.consentVersion === undefined || data?.consentVersion === null);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* 지식 본문을 전송 형태로 바꾼다. 멱등이고, 한 번 지운 스니펫은 되살아나지 않는다.
|
|
192
|
+
* config/ 본문은 자체 계약(detailOptIn)을 따르므로 건드리지 않는다.
|
|
193
|
+
*/
|
|
194
|
+
export function prepareKnowledgeBody(endpoint, data, opts = {}) {
|
|
195
|
+
if (endpoint.startsWith('config/'))
|
|
196
|
+
return data;
|
|
197
|
+
const allowed = KNOWLEDGE_WIRE_FIELDS[endpoint];
|
|
198
|
+
const out = {};
|
|
199
|
+
for (const [k, v] of Object.entries(data)) {
|
|
200
|
+
if (allowed && !allowed.includes(k))
|
|
201
|
+
continue;
|
|
202
|
+
if (SNIPPET_FIELDS.includes(k) && opts.shareSnippets !== true)
|
|
203
|
+
continue;
|
|
204
|
+
out[k] = k === 'tagging' ? onlyOrigin(v) : sanitizeDeep(v);
|
|
205
|
+
}
|
|
206
|
+
out.consentVersion = CONSENT_VERSION;
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
/** tagging 은 origin 만 보낸다. touchedPaths·toolTrail 은 서버 DTO 에 있어도 CLI 가 보내지 않는다. */
|
|
210
|
+
function onlyOrigin(v) {
|
|
211
|
+
const origin = v?.origin;
|
|
212
|
+
return origin === undefined ? {} : { origin: sanitizeDeep(origin) };
|
|
213
|
+
}
|
|
214
|
+
/** 지금 지식 서버로 내용을 보내도 되는가(기록·검색·grounding 공통). */
|
|
215
|
+
export function knowledgeSendAllowed(c) {
|
|
216
|
+
return c.syncEnabled === true && c.knowledgeSyncDisabled !== true && c.loggedOut !== true;
|
|
217
|
+
}
|
|
218
|
+
/** 나중에 보낼 항목을 큐에 넣어도 되는가. 끄기 상태에서 기록한 항목은 켠 뒤에도 나가지 않는다. */
|
|
219
|
+
export function queueAllowed(c) {
|
|
220
|
+
return c.knowledgeSyncDisabled !== true && c.loggedOut !== true;
|
|
221
|
+
}
|
|
222
|
+
// ── 전송 기록 (설계 15 §4.5) — 엔드포인트·키 이름·크기만. 값은 절대 남기지 않는다 ───
|
|
223
|
+
const PRIVACY_LOG_MAX_BYTES = 1024 * 1024;
|
|
224
|
+
export function privacyLogPath() {
|
|
225
|
+
return path.join(process.env.ROUTINECODE_DIR || path.join(homedir(), '.routinecode'), 'privacy-log.jsonl');
|
|
226
|
+
}
|
|
227
|
+
/** fail-open. url 의 호스트·쿼리 값은 버린다. 쿼리는 키 이름만 keys 로 넘긴다. */
|
|
228
|
+
export function logTransmission(url, body) {
|
|
229
|
+
try {
|
|
230
|
+
const p = privacyLogPath();
|
|
231
|
+
fs.mkdirSync(path.dirname(p), { recursive: true });
|
|
232
|
+
const size = fs.existsSync(p) ? fs.statSync(p).size : 0;
|
|
233
|
+
if (size > PRIVACY_LOG_MAX_BYTES)
|
|
234
|
+
fs.renameSync(p, p + '.1');
|
|
235
|
+
const endpoint = url.replace(/^https?:\/\/[^/]+/, '').split('?')[0];
|
|
236
|
+
const isObj = !!body && typeof body === 'object' && !Array.isArray(body);
|
|
237
|
+
const keys = isObj ? Object.keys(body).sort() : [];
|
|
238
|
+
const bytes = body === undefined ? 0 : Buffer.byteLength(JSON.stringify(body));
|
|
239
|
+
fs.appendFileSync(p, JSON.stringify({ ts: new Date().toISOString(), endpoint, keys, bytes }) + '\n', { mode: 0o600 });
|
|
240
|
+
}
|
|
241
|
+
catch { /* 기록 실패가 전송을 막지 않는다 */ }
|
|
242
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import*as a61a from'fs';import*as a61b from'path';import{homedir}from'os';import{spawnSync}from'child_process';export function boardRoot(){return process.env.ROUTINECODE_BOARD_DIR||a61b['join'](homedir(),'.routinecode','board');}export function sessionsDir(){return a61b['join'](boardRoot(),'sessions');}export function sessionPid(){const a=Number(process.env.ROUTINECODE_SESSION_PID);return Number['isInteger'](a)&&a>0x1?a:process['ppid'];}function lstart(a){try{const b=spawnSync('ps',['-o','lstart=','-p',String(a)],{'encoding':'utf-8','timeout':0xbb8}),c=(b['stdout']??'')['trim']();return b['status']===0x0&&c?c:null;}catch{return null;}}export function sessionIdOf(a,b){for(const c of[a61b['join'](sessionsDir(),b+'.json'),...a?[a61b['join'](a,'sessions',b+'.json')]:[]]){try{const e=JSON['parse'](a61a['readFileSync'](c,'utf-8'));if(e&&typeof e['session']==='string'&&e['session']){if(typeof e['start']==='string'&&e['start']){const f=lstart(b);if(f!==null&&f!==e['start'])continue;}return e['session']['slice'](0x0,0xc);}}catch{}}return'pid-'+b;}export function currentSessionId(){const a=sessionIdOf(null,sessionPid());return a['startsWith']('pid-')?null:a;}
|