@claude-flow/cli 3.25.5 → 3.26.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/.claude/.proven-config-version +1 -0
- package/.claude/helpers/.helpers-version +1 -1
- package/.claude/helpers/helpers.manifest.json +5 -4
- package/.claude/helpers/hook-handler.cjs +129 -0
- package/.claude/helpers/statusline.cjs +771 -505
- package/.claude/proven-config.json +42 -0
- package/catalog-manifest.json +12 -0
- package/dist/src/commands/advisor.d.ts +15 -0
- package/dist/src/commands/advisor.js +94 -0
- package/dist/src/commands/doctor.js +151 -32
- package/dist/src/commands/funnel.d.ts +13 -0
- package/dist/src/commands/funnel.js +103 -0
- package/dist/src/commands/hooks.js +112 -46
- package/dist/src/commands/index.js +10 -0
- package/dist/src/commands/init.js +44 -0
- package/dist/src/commands/proxy.d.ts +21 -0
- package/dist/src/commands/proxy.js +310 -0
- package/dist/src/commands/security.js +29 -0
- package/dist/src/commands/settings.d.ts +19 -0
- package/dist/src/commands/settings.js +180 -0
- package/dist/src/commands/version.d.ts +42 -0
- package/dist/src/commands/version.js +106 -0
- package/dist/src/funnel/advisor-tip.d.ts +58 -0
- package/dist/src/funnel/advisor-tip.js +92 -0
- package/dist/src/funnel/attribution.d.ts +37 -0
- package/dist/src/funnel/attribution.js +101 -0
- package/dist/src/funnel/consent.d.ts +22 -0
- package/dist/src/funnel/consent.js +55 -0
- package/dist/src/funnel/credit-errors.d.ts +31 -0
- package/dist/src/funnel/credit-errors.js +88 -0
- package/dist/src/funnel/credit-notifier.d.ts +44 -0
- package/dist/src/funnel/credit-notifier.js +74 -0
- package/dist/src/funnel/disclosure.d.ts +46 -0
- package/dist/src/funnel/disclosure.js +97 -0
- package/dist/src/funnel/enrollment.d.ts +36 -0
- package/dist/src/funnel/enrollment.js +64 -0
- package/dist/src/funnel/environment.d.ts +17 -0
- package/dist/src/funnel/environment.js +39 -0
- package/dist/src/funnel/event-transport.d.ts +51 -0
- package/dist/src/funnel/event-transport.js +199 -0
- package/dist/src/funnel/events.d.ts +42 -0
- package/dist/src/funnel/events.js +150 -0
- package/dist/src/funnel/index.d.ts +20 -0
- package/dist/src/funnel/index.js +20 -0
- package/dist/src/funnel/insights.d.ts +49 -0
- package/dist/src/funnel/insights.js +120 -0
- package/dist/src/funnel/local-signals.d.ts +15 -0
- package/dist/src/funnel/local-signals.js +68 -0
- package/dist/src/funnel/message-transport.d.ts +51 -0
- package/dist/src/funnel/message-transport.js +149 -0
- package/dist/src/funnel/messages.d.ts +55 -0
- package/dist/src/funnel/messages.js +160 -0
- package/dist/src/funnel/power-saver-notifier.d.ts +44 -0
- package/dist/src/funnel/power-saver-notifier.js +92 -0
- package/dist/src/funnel/precedence.d.ts +16 -0
- package/dist/src/funnel/precedence.js +85 -0
- package/dist/src/funnel/promo.d.ts +41 -0
- package/dist/src/funnel/promo.js +144 -0
- package/dist/src/funnel/rate-limit-notifier.d.ts +55 -0
- package/dist/src/funnel/rate-limit-notifier.js +102 -0
- package/dist/src/funnel/rotation.d.ts +19 -0
- package/dist/src/funnel/rotation.js +70 -0
- package/dist/src/funnel/state.d.ts +13 -0
- package/dist/src/funnel/state.js +52 -0
- package/dist/src/funnel/toggle-cooldown.d.ts +17 -0
- package/dist/src/funnel/toggle-cooldown.js +32 -0
- package/dist/src/funnel/types.d.ts +86 -0
- package/dist/src/funnel/types.js +26 -0
- package/dist/src/init/executor.js +25 -19
- package/dist/src/init/helper-refresh.d.ts +33 -2
- package/dist/src/init/helper-refresh.js +102 -12
- package/dist/src/init/helpers-generator.js +52 -0
- package/dist/src/init/mcp-generator.js +11 -6
- package/dist/src/init/statusline-generator.js +282 -116
- package/dist/src/services/daemon-autostart.js +28 -5
- package/dist/src/services/fable-harness.d.ts +39 -0
- package/dist/src/services/fable-harness.js +41 -0
- package/package.json +16 -4
- package/plugins/ruflo-metaharness/scripts/smoke.sh +18 -5
- package/dist/src/ruvector/lattice-wasm.d.ts +0 -14
- package/dist/src/ruvector/lattice-wasm.js +0 -144
- package/plugins/ruflo-metaharness/.claude-flow/data/pending-insights.jsonl +0 -5
- package/plugins/ruflo-metaharness/.claude-flow/neural/stats.json +0 -6
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consent domains and versioned receipts — ADR-302.
|
|
3
|
+
*
|
|
4
|
+
* Four+ distinct decisions, never bundled: account, proxy-install,
|
|
5
|
+
* telemetry, cloud-routing, hosted-memory. A receipt is written on both
|
|
6
|
+
* grant AND decline (a decline is a decision, not an absence). A stale
|
|
7
|
+
* policyVersion means the consent must be re-asked before the capability
|
|
8
|
+
* activates — never silently carried forward.
|
|
9
|
+
*/
|
|
10
|
+
import { CONSENT_POLICY_VERSION } from './types.js';
|
|
11
|
+
import { readStateJson, writeStateJson } from './state.js';
|
|
12
|
+
const CONSENT_FILE = 'consent.json';
|
|
13
|
+
export const CONSENT_DOMAINS = [
|
|
14
|
+
'account',
|
|
15
|
+
'proxy-install',
|
|
16
|
+
'telemetry',
|
|
17
|
+
'cloud-routing',
|
|
18
|
+
'hosted-memory',
|
|
19
|
+
'sponsored-downtime',
|
|
20
|
+
'power-saver',
|
|
21
|
+
'training-data-sharing',
|
|
22
|
+
'advisor-tips',
|
|
23
|
+
];
|
|
24
|
+
export function readConsents() {
|
|
25
|
+
return readStateJson(CONSENT_FILE) ?? {};
|
|
26
|
+
}
|
|
27
|
+
export function getConsent(domain) {
|
|
28
|
+
const file = readConsents();
|
|
29
|
+
return (file[domain] ?? { granted: false, policyVersion: CONSENT_POLICY_VERSION, at: null, surface: null });
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Effective consent: granted AND at the current policy version. A receipt
|
|
33
|
+
* from an older policy version is treated as not-consented (re-ask, never
|
|
34
|
+
* carry forward).
|
|
35
|
+
*/
|
|
36
|
+
export function hasConsent(domain) {
|
|
37
|
+
const r = getConsent(domain);
|
|
38
|
+
return r.granted === true && r.at !== null && r.policyVersion === CONSENT_POLICY_VERSION;
|
|
39
|
+
}
|
|
40
|
+
export function recordConsent(domain, granted, surface, now = new Date()) {
|
|
41
|
+
const file = readConsents();
|
|
42
|
+
const receipt = {
|
|
43
|
+
granted,
|
|
44
|
+
policyVersion: CONSENT_POLICY_VERSION,
|
|
45
|
+
at: now.toISOString(),
|
|
46
|
+
surface,
|
|
47
|
+
};
|
|
48
|
+
file[domain] = receipt;
|
|
49
|
+
writeStateJson(CONSENT_FILE, file);
|
|
50
|
+
return receipt;
|
|
51
|
+
}
|
|
52
|
+
export function revokeConsent(domain, surface) {
|
|
53
|
+
return recordConsent(domain, false, surface);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=consent.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credit-error taxonomy and fail-closed classifier — ADR-303.
|
|
3
|
+
*
|
|
4
|
+
* Adapters map machine-readable provider codes into the canonical
|
|
5
|
+
* CreditErrorCode enum. Message text is NEVER parsed. Anything unmapped
|
|
6
|
+
* stays unclassified (confidence 0) and falls through to the ordinary
|
|
7
|
+
* error path. Only COGNITUM_CREDIT_EXHAUSTED — asserted by the Cognitum
|
|
8
|
+
* ledger, the single credit authority — may trigger the funnel surface.
|
|
9
|
+
*/
|
|
10
|
+
import { type NormalizedCreditError } from './types.js';
|
|
11
|
+
export interface ProviderErrorLike {
|
|
12
|
+
/** Machine-readable provider error code (e.g. `error.type` / `error.code`). */
|
|
13
|
+
providerCode?: string;
|
|
14
|
+
/** HTTP status, when the transport exposes one. */
|
|
15
|
+
status?: number;
|
|
16
|
+
}
|
|
17
|
+
export declare function classifyCreditError(err: ProviderErrorLike): NormalizedCreditError;
|
|
18
|
+
export interface CreditPromptSession {
|
|
19
|
+
creditPromptShown: boolean;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The ADR-303 gate, fail-closed and frequency-capped: fires only for a
|
|
23
|
+
* confident, non-retryable Cognitum-ledger exhaustion, at most once per
|
|
24
|
+
* session. Everything else falls through to the ordinary error path.
|
|
25
|
+
*/
|
|
26
|
+
export declare function shouldShowCreditRecovery(error: NormalizedCreditError, session: CreditPromptSession): boolean;
|
|
27
|
+
/** Full contextual screen (interactive TTY, first occurrence). */
|
|
28
|
+
export declare function renderCreditRecovery(authenticated: boolean): string;
|
|
29
|
+
/** Single-line hint (non-TTY, CI, or repeat occurrences in a session). */
|
|
30
|
+
export declare const CREDIT_RECOVERY_HINT = "Hint: ruflo auth login enables the free local Meta LLM proxy";
|
|
31
|
+
//# sourceMappingURL=credit-errors.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credit-error taxonomy and fail-closed classifier — ADR-303.
|
|
3
|
+
*
|
|
4
|
+
* Adapters map machine-readable provider codes into the canonical
|
|
5
|
+
* CreditErrorCode enum. Message text is NEVER parsed. Anything unmapped
|
|
6
|
+
* stays unclassified (confidence 0) and falls through to the ordinary
|
|
7
|
+
* error path. Only COGNITUM_CREDIT_EXHAUSTED — asserted by the Cognitum
|
|
8
|
+
* ledger, the single credit authority — may trigger the funnel surface.
|
|
9
|
+
*/
|
|
10
|
+
import { CreditErrorCode } from './types.js';
|
|
11
|
+
/**
|
|
12
|
+
* Provider-code → canonical-code table. Keys are exact machine-readable
|
|
13
|
+
* code strings from provider error payloads (mirrors the ADR-308 server
|
|
14
|
+
* taxonomy 1:1). Versioned by code review; unmapped codes land nowhere.
|
|
15
|
+
*/
|
|
16
|
+
const PROVIDER_CODE_TABLE = {
|
|
17
|
+
// Cognitum ledger (the single credit authority — ADR-303)
|
|
18
|
+
cognitum_credit_exhausted: { code: CreditErrorCode.COGNITUM_CREDIT_EXHAUSTED, retryable: false },
|
|
19
|
+
// Upstream provider quota/billing — NOT a Cognitum upsell moment
|
|
20
|
+
insufficient_quota: { code: CreditErrorCode.PROVIDER_QUOTA_EXHAUSTED, retryable: false },
|
|
21
|
+
billing_hard_limit_reached: { code: CreditErrorCode.PROVIDER_QUOTA_EXHAUSTED, retryable: false },
|
|
22
|
+
quota_exceeded: { code: CreditErrorCode.PROVIDER_QUOTA_EXHAUSTED, retryable: false },
|
|
23
|
+
// Retryable rate limits
|
|
24
|
+
rate_limit_exceeded: { code: CreditErrorCode.PROVIDER_RATE_LIMITED, retryable: true },
|
|
25
|
+
rate_limit_error: { code: CreditErrorCode.PROVIDER_RATE_LIMITED, retryable: true },
|
|
26
|
+
overloaded_error: { code: CreditErrorCode.SERVICE_UNAVAILABLE, retryable: true },
|
|
27
|
+
// Auth
|
|
28
|
+
authentication_error: { code: CreditErrorCode.AUTHENTICATION_FAILED, retryable: false },
|
|
29
|
+
invalid_api_key: { code: CreditErrorCode.AUTHENTICATION_FAILED, retryable: false },
|
|
30
|
+
permission_error: { code: CreditErrorCode.AUTHENTICATION_FAILED, retryable: false },
|
|
31
|
+
// Outages
|
|
32
|
+
api_error: { code: CreditErrorCode.SERVICE_UNAVAILABLE, retryable: true },
|
|
33
|
+
service_unavailable: { code: CreditErrorCode.SERVICE_UNAVAILABLE, retryable: true },
|
|
34
|
+
};
|
|
35
|
+
export function classifyCreditError(err) {
|
|
36
|
+
const key = err.providerCode?.trim().toLowerCase();
|
|
37
|
+
if (key && Object.prototype.hasOwnProperty.call(PROVIDER_CODE_TABLE, key)) {
|
|
38
|
+
const mapped = PROVIDER_CODE_TABLE[key];
|
|
39
|
+
return { code: mapped.code, confidence: 1, retryable: mapped.retryable, cause: err };
|
|
40
|
+
}
|
|
41
|
+
// Status-only signals are structural (401/403 → auth; 5xx → outage), but a
|
|
42
|
+
// bare 429 is ambiguous between rate-limit and quota — leave it unmapped.
|
|
43
|
+
if (err.status === 401 || err.status === 403) {
|
|
44
|
+
return { code: CreditErrorCode.AUTHENTICATION_FAILED, confidence: 1, retryable: false, cause: err };
|
|
45
|
+
}
|
|
46
|
+
if (err.status !== undefined && err.status >= 500) {
|
|
47
|
+
return { code: CreditErrorCode.SERVICE_UNAVAILABLE, confidence: 1, retryable: true, cause: err };
|
|
48
|
+
}
|
|
49
|
+
return { code: null, confidence: 0, retryable: false, cause: err };
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The ADR-303 gate, fail-closed and frequency-capped: fires only for a
|
|
53
|
+
* confident, non-retryable Cognitum-ledger exhaustion, at most once per
|
|
54
|
+
* session. Everything else falls through to the ordinary error path.
|
|
55
|
+
*/
|
|
56
|
+
export function shouldShowCreditRecovery(error, session) {
|
|
57
|
+
return (error.code === CreditErrorCode.COGNITUM_CREDIT_EXHAUSTED &&
|
|
58
|
+
error.confidence === 1 &&
|
|
59
|
+
!error.retryable &&
|
|
60
|
+
!session.creditPromptShown);
|
|
61
|
+
}
|
|
62
|
+
/** Full contextual screen (interactive TTY, first occurrence). */
|
|
63
|
+
export function renderCreditRecovery(authenticated) {
|
|
64
|
+
const lines = [
|
|
65
|
+
'Daily hosted credits exhausted.',
|
|
66
|
+
'',
|
|
67
|
+
'Continue immediately by enabling',
|
|
68
|
+
'your free local Meta LLM Proxy.',
|
|
69
|
+
'',
|
|
70
|
+
'Benefits',
|
|
71
|
+
' ✓ Unlimited local requests',
|
|
72
|
+
' ✓ Automatic model routing',
|
|
73
|
+
' ✓ Lower latency',
|
|
74
|
+
' ✓ Privacy preserving',
|
|
75
|
+
' ✓ Cloud fallback',
|
|
76
|
+
'',
|
|
77
|
+
];
|
|
78
|
+
if (authenticated) {
|
|
79
|
+
lines.push('Start local proxy?', ' ruflo proxy enable');
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
lines.push('Sign in:', ' ruflo auth login');
|
|
83
|
+
}
|
|
84
|
+
return lines.join('\n');
|
|
85
|
+
}
|
|
86
|
+
/** Single-line hint (non-TTY, CI, or repeat occurrences in a session). */
|
|
87
|
+
export const CREDIT_RECOVERY_HINT = 'Hint: ruflo auth login enables the free local Meta LLM proxy';
|
|
88
|
+
//# sourceMappingURL=credit-errors.js.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credit-exhaustion notifier — writes a marker file so the ADR-303 recovery
|
|
3
|
+
* surface fires on the next appropriate command render, and keeps a short
|
|
4
|
+
* user-visible notification in `~/.ruflo/credit-status.json`.
|
|
5
|
+
*
|
|
6
|
+
* This is NOT the ADR-303 credit-error classifier — that lives in
|
|
7
|
+
* `credit-errors.ts` and reads provider error codes to decide when a
|
|
8
|
+
* credit surface fires *during* a command. This module is the OUT-OF-BAND
|
|
9
|
+
* signal path: the analytics transport detected a credit-exhausted
|
|
10
|
+
* response (HTTP 402 or ADR-303 machine-readable code), and we need to
|
|
11
|
+
* warn the user asynchronously.
|
|
12
|
+
*
|
|
13
|
+
* State is cheap and durable:
|
|
14
|
+
* ~/.ruflo/credit-status.json = { exhausted: bool, since: ISO, cleared: ISO|null }
|
|
15
|
+
*
|
|
16
|
+
* Cleared automatically when the user opens the enrollment / signup
|
|
17
|
+
* surface, or explicitly via `ruflo funnel credit-clear`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const CREDIT_STATUS_FILE = "credit-status.json";
|
|
20
|
+
export interface CreditStatus {
|
|
21
|
+
exhausted: boolean;
|
|
22
|
+
since: string | null;
|
|
23
|
+
cleared: string | null;
|
|
24
|
+
}
|
|
25
|
+
/** Read the current credit status. Never throws. */
|
|
26
|
+
export declare function readCreditStatus(): CreditStatus;
|
|
27
|
+
/**
|
|
28
|
+
* Mark credit as exhausted — idempotent. Sets `since` on the first mark,
|
|
29
|
+
* leaves it alone on subsequent marks so the user sees a stable "since"
|
|
30
|
+
* timestamp until they clear it.
|
|
31
|
+
*/
|
|
32
|
+
export declare function markCreditExhausted(now?: Date): void;
|
|
33
|
+
/**
|
|
34
|
+
* Clear credit-exhaustion status. Called when the user completes signup or
|
|
35
|
+
* runs `ruflo funnel credit-clear`. `cleared` is stamped so the previous
|
|
36
|
+
* `since` remains inspectable for one recovery cycle.
|
|
37
|
+
*/
|
|
38
|
+
export declare function clearCreditStatus(now?: Date): void;
|
|
39
|
+
/**
|
|
40
|
+
* User-facing single-line summary — plain text, no ANSI. Callers style it
|
|
41
|
+
* themselves. Returns null when credit isn't exhausted (no surface).
|
|
42
|
+
*/
|
|
43
|
+
export declare function creditExhaustedNotice(now?: Date): string | null;
|
|
44
|
+
//# sourceMappingURL=credit-notifier.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Credit-exhaustion notifier — writes a marker file so the ADR-303 recovery
|
|
3
|
+
* surface fires on the next appropriate command render, and keeps a short
|
|
4
|
+
* user-visible notification in `~/.ruflo/credit-status.json`.
|
|
5
|
+
*
|
|
6
|
+
* This is NOT the ADR-303 credit-error classifier — that lives in
|
|
7
|
+
* `credit-errors.ts` and reads provider error codes to decide when a
|
|
8
|
+
* credit surface fires *during* a command. This module is the OUT-OF-BAND
|
|
9
|
+
* signal path: the analytics transport detected a credit-exhausted
|
|
10
|
+
* response (HTTP 402 or ADR-303 machine-readable code), and we need to
|
|
11
|
+
* warn the user asynchronously.
|
|
12
|
+
*
|
|
13
|
+
* State is cheap and durable:
|
|
14
|
+
* ~/.ruflo/credit-status.json = { exhausted: bool, since: ISO, cleared: ISO|null }
|
|
15
|
+
*
|
|
16
|
+
* Cleared automatically when the user opens the enrollment / signup
|
|
17
|
+
* surface, or explicitly via `ruflo funnel credit-clear`.
|
|
18
|
+
*/
|
|
19
|
+
import { readStateJson, writeStateJson } from './state.js';
|
|
20
|
+
export const CREDIT_STATUS_FILE = 'credit-status.json';
|
|
21
|
+
/** Read the current credit status. Never throws. */
|
|
22
|
+
export function readCreditStatus() {
|
|
23
|
+
const raw = readStateJson(CREDIT_STATUS_FILE);
|
|
24
|
+
return {
|
|
25
|
+
exhausted: raw?.exhausted ?? false,
|
|
26
|
+
since: raw?.since ?? null,
|
|
27
|
+
cleared: raw?.cleared ?? null,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Mark credit as exhausted — idempotent. Sets `since` on the first mark,
|
|
32
|
+
* leaves it alone on subsequent marks so the user sees a stable "since"
|
|
33
|
+
* timestamp until they clear it.
|
|
34
|
+
*/
|
|
35
|
+
export function markCreditExhausted(now = new Date()) {
|
|
36
|
+
const current = readCreditStatus();
|
|
37
|
+
if (current.exhausted && current.since)
|
|
38
|
+
return; // already flagged
|
|
39
|
+
writeStateJson(CREDIT_STATUS_FILE, {
|
|
40
|
+
exhausted: true,
|
|
41
|
+
since: current.since ?? now.toISOString(),
|
|
42
|
+
cleared: null,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Clear credit-exhaustion status. Called when the user completes signup or
|
|
47
|
+
* runs `ruflo funnel credit-clear`. `cleared` is stamped so the previous
|
|
48
|
+
* `since` remains inspectable for one recovery cycle.
|
|
49
|
+
*/
|
|
50
|
+
export function clearCreditStatus(now = new Date()) {
|
|
51
|
+
const current = readCreditStatus();
|
|
52
|
+
writeStateJson(CREDIT_STATUS_FILE, {
|
|
53
|
+
exhausted: false,
|
|
54
|
+
since: current.since,
|
|
55
|
+
cleared: now.toISOString(),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* User-facing single-line summary — plain text, no ANSI. Callers style it
|
|
60
|
+
* themselves. Returns null when credit isn't exhausted (no surface).
|
|
61
|
+
*/
|
|
62
|
+
export function creditExhaustedNotice(now = new Date()) {
|
|
63
|
+
const status = readCreditStatus();
|
|
64
|
+
if (!status.exhausted)
|
|
65
|
+
return null;
|
|
66
|
+
const since = status.since ? Date.parse(status.since) : NaN;
|
|
67
|
+
if (Number.isNaN(since)) {
|
|
68
|
+
return 'Cognitum credits exhausted · run: ruflo funnel signup';
|
|
69
|
+
}
|
|
70
|
+
const ageHours = Math.max(0, Math.round((now.getTime() - since) / (60 * 60 * 1000)));
|
|
71
|
+
const when = ageHours < 1 ? 'just now' : ageHours < 24 ? `${ageHours}h ago` : `${Math.round(ageHours / 24)}d ago`;
|
|
72
|
+
return `Cognitum credits exhausted (${when}) · run: ruflo funnel signup`;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=credit-notifier.js.map
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Existing-install disclosure gate — ADR-301, amended by ADR-311 to source
|
|
3
|
+
* the disclosure MESSAGE itself from the remote feed rather than hardcoding
|
|
4
|
+
* it in the CLI. Everything about WHETHER/WHEN to show a disclosure stays
|
|
5
|
+
* local (state machine below); everything about WHAT it says comes from
|
|
6
|
+
* the same remote pool as tips/promos, validated through the identical
|
|
7
|
+
* ADR-301 content pipeline (isValidMessage in messages.ts).
|
|
8
|
+
*
|
|
9
|
+
* Invariants (release-blocking, tested):
|
|
10
|
+
* - No promotional content before disclosure.
|
|
11
|
+
* - The manage instruction appears in the disclosure text itself.
|
|
12
|
+
* - Shown once per user (user-level receipt), not once per project.
|
|
13
|
+
* - Declining disables all funnel surfaces (enforced in precedence.ts).
|
|
14
|
+
* - Fail-closed: if the remote feed has never successfully populated a
|
|
15
|
+
* disclosure-class message, there is nothing to show — no local
|
|
16
|
+
* fallback text exists (ADR-311 "zero local promo content").
|
|
17
|
+
*
|
|
18
|
+
* The disclosure text stays on the promo row for a grace window after its
|
|
19
|
+
* first render so a single flash can't count as "the user was told"; only
|
|
20
|
+
* after the window do promotional messages become eligible.
|
|
21
|
+
*/
|
|
22
|
+
import type { DisclosureRecord, FunnelMessage } from './types.js';
|
|
23
|
+
/** How long the disclosure text keeps the row before promo becomes eligible. */
|
|
24
|
+
export declare const DISCLOSURE_GRACE_MS: number;
|
|
25
|
+
export declare const DISCLOSURE_ROTATION_SLOT_MS: number;
|
|
26
|
+
/**
|
|
27
|
+
* Deterministic slot-based selection over the remote disclosure pool — no
|
|
28
|
+
* RNG so the choice is reproducible for a given wall-clock instant. Returns
|
|
29
|
+
* null when the pool is empty (cold start before first fetch, or the remote
|
|
30
|
+
* feed is unreachable) — the caller must treat null as "show nothing".
|
|
31
|
+
*/
|
|
32
|
+
export declare function selectDisclosureMessage(now?: Date): FunnelMessage | null;
|
|
33
|
+
export declare function getDisclosure(): DisclosureRecord;
|
|
34
|
+
/** Record that the disclosure text was rendered (idempotent). */
|
|
35
|
+
export declare function recordDisclosureShown(now?: Date): DisclosureRecord;
|
|
36
|
+
/** User explicitly declined (e.g. `ruflo funnel disable`). */
|
|
37
|
+
export declare function recordDisclosureDeclined(now?: Date): DisclosureRecord;
|
|
38
|
+
/** Re-enable after a prior decline (explicit user action only). */
|
|
39
|
+
export declare function recordDisclosureReenabled(now?: Date): DisclosureRecord;
|
|
40
|
+
/**
|
|
41
|
+
* Whether promotional/educational messages may render. True only after the
|
|
42
|
+
* disclosure was shown AND its grace window has elapsed. While the window is
|
|
43
|
+
* open the row must carry the disclosure text itself.
|
|
44
|
+
*/
|
|
45
|
+
export declare function promoEligible(now?: Date): boolean;
|
|
46
|
+
//# sourceMappingURL=disclosure.d.ts.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Existing-install disclosure gate — ADR-301, amended by ADR-311 to source
|
|
3
|
+
* the disclosure MESSAGE itself from the remote feed rather than hardcoding
|
|
4
|
+
* it in the CLI. Everything about WHETHER/WHEN to show a disclosure stays
|
|
5
|
+
* local (state machine below); everything about WHAT it says comes from
|
|
6
|
+
* the same remote pool as tips/promos, validated through the identical
|
|
7
|
+
* ADR-301 content pipeline (isValidMessage in messages.ts).
|
|
8
|
+
*
|
|
9
|
+
* Invariants (release-blocking, tested):
|
|
10
|
+
* - No promotional content before disclosure.
|
|
11
|
+
* - The manage instruction appears in the disclosure text itself.
|
|
12
|
+
* - Shown once per user (user-level receipt), not once per project.
|
|
13
|
+
* - Declining disables all funnel surfaces (enforced in precedence.ts).
|
|
14
|
+
* - Fail-closed: if the remote feed has never successfully populated a
|
|
15
|
+
* disclosure-class message, there is nothing to show — no local
|
|
16
|
+
* fallback text exists (ADR-311 "zero local promo content").
|
|
17
|
+
*
|
|
18
|
+
* The disclosure text stays on the promo row for a grace window after its
|
|
19
|
+
* first render so a single flash can't count as "the user was told"; only
|
|
20
|
+
* after the window do promotional messages become eligible.
|
|
21
|
+
*/
|
|
22
|
+
import { readStateJson, writeStateJson } from './state.js';
|
|
23
|
+
import { getRemoteMessages } from './message-transport.js';
|
|
24
|
+
const DISCLOSURE_FILE = 'funnel-disclosure.json';
|
|
25
|
+
/** How long the disclosure text keeps the row before promo becomes eligible. */
|
|
26
|
+
export const DISCLOSURE_GRACE_MS = 24 * 60 * 60 * 1000; // 24h
|
|
27
|
+
// One disclosure variant per 5-minute wall-clock slot. Longer than the
|
|
28
|
+
// 20-second rotation cadence so a user watching the statusline sees the
|
|
29
|
+
// same variant long enough to read it, but short enough that a fresh
|
|
30
|
+
// session gets a different one than the previous one did.
|
|
31
|
+
export const DISCLOSURE_ROTATION_SLOT_MS = 5 * 60 * 1000;
|
|
32
|
+
/** Remote-cached messages tagged class==='disclosure' — the only source. */
|
|
33
|
+
function getDisclosureMessagePool() {
|
|
34
|
+
return getRemoteMessages().filter((m) => m.class === 'disclosure');
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Deterministic slot-based selection over the remote disclosure pool — no
|
|
38
|
+
* RNG so the choice is reproducible for a given wall-clock instant. Returns
|
|
39
|
+
* null when the pool is empty (cold start before first fetch, or the remote
|
|
40
|
+
* feed is unreachable) — the caller must treat null as "show nothing".
|
|
41
|
+
*/
|
|
42
|
+
export function selectDisclosureMessage(now = new Date()) {
|
|
43
|
+
const pool = getDisclosureMessagePool();
|
|
44
|
+
if (pool.length === 0)
|
|
45
|
+
return null;
|
|
46
|
+
const slot = Math.floor(now.getTime() / DISCLOSURE_ROTATION_SLOT_MS);
|
|
47
|
+
return pool[slot % pool.length];
|
|
48
|
+
}
|
|
49
|
+
export function getDisclosure() {
|
|
50
|
+
const rec = readStateJson(DISCLOSURE_FILE);
|
|
51
|
+
if (rec && isValidState(rec.state))
|
|
52
|
+
return rec;
|
|
53
|
+
return { state: 'never_seen', firstShownAt: null };
|
|
54
|
+
}
|
|
55
|
+
function isValidState(s) {
|
|
56
|
+
return s === 'never_seen' || s === 'disclosed_enabled' || s === 'disclosed_disabled';
|
|
57
|
+
}
|
|
58
|
+
/** Record that the disclosure text was rendered (idempotent). */
|
|
59
|
+
export function recordDisclosureShown(now = new Date()) {
|
|
60
|
+
const current = getDisclosure();
|
|
61
|
+
if (current.state !== 'never_seen')
|
|
62
|
+
return current;
|
|
63
|
+
const rec = { state: 'disclosed_enabled', firstShownAt: now.toISOString() };
|
|
64
|
+
writeStateJson(DISCLOSURE_FILE, rec);
|
|
65
|
+
return rec;
|
|
66
|
+
}
|
|
67
|
+
/** User explicitly declined (e.g. `ruflo funnel disable`). */
|
|
68
|
+
export function recordDisclosureDeclined(now = new Date()) {
|
|
69
|
+
const current = getDisclosure();
|
|
70
|
+
const rec = {
|
|
71
|
+
state: 'disclosed_disabled',
|
|
72
|
+
firstShownAt: current.firstShownAt ?? now.toISOString(),
|
|
73
|
+
};
|
|
74
|
+
writeStateJson(DISCLOSURE_FILE, rec);
|
|
75
|
+
return rec;
|
|
76
|
+
}
|
|
77
|
+
/** Re-enable after a prior decline (explicit user action only). */
|
|
78
|
+
export function recordDisclosureReenabled(now = new Date()) {
|
|
79
|
+
const rec = { state: 'disclosed_enabled', firstShownAt: now.toISOString() };
|
|
80
|
+
writeStateJson(DISCLOSURE_FILE, rec);
|
|
81
|
+
return rec;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether promotional/educational messages may render. True only after the
|
|
85
|
+
* disclosure was shown AND its grace window has elapsed. While the window is
|
|
86
|
+
* open the row must carry the disclosure text itself.
|
|
87
|
+
*/
|
|
88
|
+
export function promoEligible(now = new Date()) {
|
|
89
|
+
const rec = getDisclosure();
|
|
90
|
+
if (rec.state !== 'disclosed_enabled' || !rec.firstShownAt)
|
|
91
|
+
return false;
|
|
92
|
+
const first = Date.parse(rec.firstShownAt);
|
|
93
|
+
if (Number.isNaN(first))
|
|
94
|
+
return false;
|
|
95
|
+
return now.getTime() - first >= DISCLOSURE_GRACE_MS;
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=disclosure.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-initialization capability enrollment — ADR-302.
|
|
3
|
+
*
|
|
4
|
+
* One-time, non-blocking, skippable. Gates, all of which must pass:
|
|
5
|
+
* - interactive TTY (never in CI / piped / automation)
|
|
6
|
+
* - not skipped via --no-signup
|
|
7
|
+
* - funnel enabled under the ADR-305 precedence chain
|
|
8
|
+
* - never shown before (user-level record, not per-project)
|
|
9
|
+
*
|
|
10
|
+
* Accepting authorizes exactly ONE thing: a pointer to `ruflo auth login`.
|
|
11
|
+
* It does not install the proxy, does not enable telemetry, and does not
|
|
12
|
+
* enable cloud routing (separate consent domains — ADR-302). The enrollment
|
|
13
|
+
* outcome never affects init's exit code.
|
|
14
|
+
*/
|
|
15
|
+
interface EnrollmentRecord {
|
|
16
|
+
shownAt: string;
|
|
17
|
+
outcome: 'accepted' | 'skipped';
|
|
18
|
+
}
|
|
19
|
+
export declare function getEnrollmentRecord(): EnrollmentRecord | null;
|
|
20
|
+
export declare const ENROLLMENT_SCREEN: string;
|
|
21
|
+
export declare const ENROLLMENT_SKIP_TEXT = "You can enable later:\n ruflo auth login";
|
|
22
|
+
export interface EnrollmentGateContext {
|
|
23
|
+
noSignup: boolean;
|
|
24
|
+
cwd?: string;
|
|
25
|
+
env?: NodeJS.ProcessEnv;
|
|
26
|
+
}
|
|
27
|
+
/** All ADR-302 gates. Pure check — does not write state. */
|
|
28
|
+
export declare function shouldOfferEnrollment(ctx: EnrollmentGateContext): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Record the user's decision. Both accept and skip are terminal — the
|
|
31
|
+
* prompt never reappears (ADR-302). Accepting records the `account`
|
|
32
|
+
* consent receipt; skipping records the decline.
|
|
33
|
+
*/
|
|
34
|
+
export declare function recordEnrollmentOutcome(accepted: boolean, now?: Date): void;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=enrollment.d.ts.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-initialization capability enrollment — ADR-302.
|
|
3
|
+
*
|
|
4
|
+
* One-time, non-blocking, skippable. Gates, all of which must pass:
|
|
5
|
+
* - interactive TTY (never in CI / piped / automation)
|
|
6
|
+
* - not skipped via --no-signup
|
|
7
|
+
* - funnel enabled under the ADR-305 precedence chain
|
|
8
|
+
* - never shown before (user-level record, not per-project)
|
|
9
|
+
*
|
|
10
|
+
* Accepting authorizes exactly ONE thing: a pointer to `ruflo auth login`.
|
|
11
|
+
* It does not install the proxy, does not enable telemetry, and does not
|
|
12
|
+
* enable cloud routing (separate consent domains — ADR-302). The enrollment
|
|
13
|
+
* outcome never affects init's exit code.
|
|
14
|
+
*/
|
|
15
|
+
import { isCI, isInteractive } from './environment.js';
|
|
16
|
+
import { resolveFunnelEnabled } from './precedence.js';
|
|
17
|
+
import { recordConsent } from './consent.js';
|
|
18
|
+
import { readStateJson, writeStateJson } from './state.js';
|
|
19
|
+
const ENROLLMENT_FILE = 'enrollment.json';
|
|
20
|
+
export function getEnrollmentRecord() {
|
|
21
|
+
return readStateJson(ENROLLMENT_FILE);
|
|
22
|
+
}
|
|
23
|
+
export const ENROLLMENT_SCREEN = [
|
|
24
|
+
'────────────────────────────',
|
|
25
|
+
'Unlock additional capabilities?',
|
|
26
|
+
'',
|
|
27
|
+
' ✓ Local Meta LLM Proxy',
|
|
28
|
+
' ✓ Multi-model routing',
|
|
29
|
+
' ✓ Hosted memory',
|
|
30
|
+
' ✓ Enterprise rate limits',
|
|
31
|
+
' ✓ Premium agents',
|
|
32
|
+
' ✓ Cloud synchronization',
|
|
33
|
+
'',
|
|
34
|
+
'Free account: https://cognitum.one',
|
|
35
|
+
].join('\n');
|
|
36
|
+
export const ENROLLMENT_SKIP_TEXT = 'You can enable later:\n ruflo auth login';
|
|
37
|
+
/** All ADR-302 gates. Pure check — does not write state. */
|
|
38
|
+
export function shouldOfferEnrollment(ctx) {
|
|
39
|
+
const env = ctx.env ?? process.env;
|
|
40
|
+
if (ctx.noSignup)
|
|
41
|
+
return false;
|
|
42
|
+
if (isCI(env))
|
|
43
|
+
return false;
|
|
44
|
+
if (!isInteractive())
|
|
45
|
+
return false;
|
|
46
|
+
if (!resolveFunnelEnabled(ctx.cwd ?? process.cwd(), env).enabled)
|
|
47
|
+
return false;
|
|
48
|
+
if (getEnrollmentRecord() !== null)
|
|
49
|
+
return false; // one-time only
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Record the user's decision. Both accept and skip are terminal — the
|
|
54
|
+
* prompt never reappears (ADR-302). Accepting records the `account`
|
|
55
|
+
* consent receipt; skipping records the decline.
|
|
56
|
+
*/
|
|
57
|
+
export function recordEnrollmentOutcome(accepted, now = new Date()) {
|
|
58
|
+
writeStateJson(ENROLLMENT_FILE, {
|
|
59
|
+
shownAt: now.toISOString(),
|
|
60
|
+
outcome: accepted ? 'accepted' : 'skipped',
|
|
61
|
+
});
|
|
62
|
+
recordConsent('account', accepted, 'post-init', now);
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=enrollment.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment gates for funnel surfaces (ADR-301/302).
|
|
3
|
+
*
|
|
4
|
+
* CI and non-interactive environments never see funnel content; reduced
|
|
5
|
+
* motion / screen readers get static text only (which is all the funnel
|
|
6
|
+
* renders anyway — there is deliberately no animation path in this module).
|
|
7
|
+
*/
|
|
8
|
+
export declare function isCI(env?: NodeJS.ProcessEnv): boolean;
|
|
9
|
+
export declare function isInteractive(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Statusline invocations are spawned by an interactive host (Claude Code)
|
|
12
|
+
* with piped stdio, so isTTY is false there even though the session is
|
|
13
|
+
* interactive. Surfaces pass their own interactivity signal; this helper is
|
|
14
|
+
* the strict check used by directly-invoked prompts (init enrollment).
|
|
15
|
+
*/
|
|
16
|
+
export declare function reducedMotion(env?: NodeJS.ProcessEnv): boolean;
|
|
17
|
+
//# sourceMappingURL=environment.d.ts.map
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment gates for funnel surfaces (ADR-301/302).
|
|
3
|
+
*
|
|
4
|
+
* CI and non-interactive environments never see funnel content; reduced
|
|
5
|
+
* motion / screen readers get static text only (which is all the funnel
|
|
6
|
+
* renders anyway — there is deliberately no animation path in this module).
|
|
7
|
+
*/
|
|
8
|
+
const CI_ENV_VARS = [
|
|
9
|
+
'CI',
|
|
10
|
+
'GITHUB_ACTIONS',
|
|
11
|
+
'GITLAB_CI',
|
|
12
|
+
'CIRCLECI',
|
|
13
|
+
'TRAVIS',
|
|
14
|
+
'BUILDKITE',
|
|
15
|
+
'JENKINS_URL',
|
|
16
|
+
'TEAMCITY_VERSION',
|
|
17
|
+
'TF_BUILD', // Azure Pipelines
|
|
18
|
+
];
|
|
19
|
+
export function isCI(env = process.env) {
|
|
20
|
+
return CI_ENV_VARS.some((v) => {
|
|
21
|
+
const val = env[v];
|
|
22
|
+
return val !== undefined && val !== '' && val !== '0' && val.toLowerCase?.() !== 'false';
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function isInteractive() {
|
|
26
|
+
return Boolean(process.stdout.isTTY && process.stdin.isTTY);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Statusline invocations are spawned by an interactive host (Claude Code)
|
|
30
|
+
* with piped stdio, so isTTY is false there even though the session is
|
|
31
|
+
* interactive. Surfaces pass their own interactivity signal; this helper is
|
|
32
|
+
* the strict check used by directly-invoked prompts (init enrollment).
|
|
33
|
+
*/
|
|
34
|
+
export function reducedMotion(env = process.env) {
|
|
35
|
+
return Boolean(env.NO_COLOR !== undefined ||
|
|
36
|
+
env.RUFLO_REDUCED_MOTION === '1' ||
|
|
37
|
+
env.TERM === 'dumb');
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=environment.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event transport — batches the local funnel event queue and posts it to the
|
|
3
|
+
* Cognitum analytics Cloud Function (ADR-308 endpoint contract).
|
|
4
|
+
*
|
|
5
|
+
* Design discipline (ADR-308 client failure policy — all normative):
|
|
6
|
+
* 1. Telemetry never blocks the CLI. Every network call is best-effort,
|
|
7
|
+
* capped by a short timeout, and swallows every error path.
|
|
8
|
+
* 2. Events are LOCAL FIRST. The queue in `events.ts` accumulates
|
|
9
|
+
* regardless of API reachability. This transport is the flush layer.
|
|
10
|
+
* 3. Idempotency: every batch carries a UUIDv4 idempotency key so a retry
|
|
11
|
+
* never double-counts (ADR-308 idempotent-batches invariant).
|
|
12
|
+
* 4. Exponential backoff on transient failures. Successful flushes stamp
|
|
13
|
+
* a "last flush" timestamp so we don't hammer the API each render.
|
|
14
|
+
* 5. Consent-gated. Zero network activity when telemetry consent is off.
|
|
15
|
+
* 6. Bounded. Never send more than MAX_BATCH events at once, so a large
|
|
16
|
+
* backlog doesn't blow the endpoint request-size limit.
|
|
17
|
+
* 7. Credit-exhaustion detection. If the endpoint replies 402 (Payment
|
|
18
|
+
* Required) or the body carries the ADR-303
|
|
19
|
+
* `COGNITUM_CREDIT_EXHAUSTED` code, we surface via `credit-notifier.ts`
|
|
20
|
+
* — the same recovery UX ADR-303 already ships.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Default endpoint — the ruflo-funnel-analytics endpoint on the ruv.io
|
|
24
|
+
* domain, mapped via Cloud Run domain mapping to the cognitum-analytics
|
|
25
|
+
* Cloud Function on cognitum-20260110. Overridable by env for staging or
|
|
26
|
+
* self-hosted deploys. The domain choice is deliberate: an rUv-authored
|
|
27
|
+
* OSS project's telemetry endpoint belongs on rUv's own domain, not on
|
|
28
|
+
* cognitum.one — that keeps the CLI attribution honest.
|
|
29
|
+
*/
|
|
30
|
+
export declare const DEFAULT_ENDPOINT: string;
|
|
31
|
+
/** Cap per POST — server enforces its own limits too; this is a safety net. */
|
|
32
|
+
export declare const MAX_BATCH = 100;
|
|
33
|
+
/** Min interval between flushes (ms). Rate limits the client from within. */
|
|
34
|
+
export declare const MIN_FLUSH_INTERVAL_MS = 60000;
|
|
35
|
+
/** POST timeout — telemetry must not stall the CLI. */
|
|
36
|
+
export declare const FLUSH_TIMEOUT_MS = 4000;
|
|
37
|
+
/**
|
|
38
|
+
* Best-effort flush of the local event queue to the endpoint. Returns a
|
|
39
|
+
* summary the CLI can log at --verbose; the caller should never fail on it.
|
|
40
|
+
*/
|
|
41
|
+
export declare function flushEvents(opts?: {
|
|
42
|
+
endpoint?: string;
|
|
43
|
+
release?: string;
|
|
44
|
+
force?: boolean;
|
|
45
|
+
now?: Date;
|
|
46
|
+
}): Promise<{
|
|
47
|
+
flushed: number;
|
|
48
|
+
skipped: string | null;
|
|
49
|
+
status?: number;
|
|
50
|
+
}>;
|
|
51
|
+
//# sourceMappingURL=event-transport.d.ts.map
|