diff --git a/.github/connectors/README.md b/.github/connectors/README.md index a594bc90fae..3fc1b819de5 100644 --- a/.github/connectors/README.md +++ b/.github/connectors/README.md @@ -7,14 +7,24 @@ Runtime code and Actions read **environment variable names** only — never secr | Secret name | Purpose | Used by | |-------------|---------|--------| -| `OPERATOR_GITHUB_TOKEN` | Write/admin PAT for CodeRabbit autofix, privileged comments, continuous-ops | peer-review-orchestrator, continuous-ops, auto-jules | +| `OPERATOR_GITHUB_TOKEN` | Primary write/admin PAT (CodeRabbit autofix, privileged comments, continuous-ops) | peer-review-orchestrator, continuous-ops, auto-jules | +| **`ARCHWIZ_GITHUB_TOKEN`** | **Second Admin PAT (ArchWiz / 4π¢hw12)** — same powers as OPERATOR **except delete_repo** | parallel admin lane; preferred when set | +| `OPERATOR_TOKEN` | Optional alias/fallback for OPERATOR | older workflows | | `GITHUB_TOKEN` | Default Actions token (contents/PRs/issues scoped) | all workflows | +| `DEEPSEEK_TOKEN` | **DeepSeek model auth only** (not a GitHub PAT) | deepseek-ci, multi-ai-cli | | `OMNI_API_KEY` / `OMNIROUTE_API_KEY` | OmniRoute free-tier peer | model-router, http-llm-invoke | | `OMNI_BASE_URL` | Optional override (must be https allow-listed host) | http-llm-invoke | | `OPENROUTER_API_KEY` | OpenRouter free-tier peer (`:free` models only) | model-router, http-llm-invoke | | `GEMINI_API_KEY` | Gemini residual path | gemini-* workflows | | Linear / Vercel / other | Connected via Grok Connectors or separate secrets as needed | agent-feedback-linear-sync, deploy | +### Token boundaries (hard rules) + +1. **GitHub admin PATs** (`OPERATOR_*`, `ARCHWIZ_*`) → `gh` / REST / git only. +2. **Model tokens** (`DEEPSEEK_TOKEN`, Omni, OpenRouter, Gemini) → provider APIs only. +3. Never cross-wire (no GH PAT as DeepSeek Bearer; no DeepSeek token as `GH_TOKEN`). +4. Create/rotate ArchWiz PAT: `docs/ops/ARCHWIZ-ADMIN-TOKEN.md`. + ## Provider allow-list (http-llm-invoke) - `cloud.omniroute.online` diff --git a/.github/connectors/github.yaml b/.github/connectors/github.yaml index de09cf291eb..e0cf5db85e6 100644 --- a/.github/connectors/github.yaml +++ b/.github/connectors/github.yaml @@ -6,9 +6,16 @@ github: base_url: https://api.github.com token_env: GITHUB_TOKEN operator_token_env: OPERATOR_GITHUB_TOKEN + archwiz_token_env: ARCHWIZ_GITHUB_TOKEN + # Preference chain for privileged writes: + # ARCHWIZ_GITHUB_TOKEN || OPERATOR_GITHUB_TOKEN || OPERATOR_TOKEN || GITHUB_TOKEN permissions_expected: - contents: read|write - pull-requests: write - issues: write - - actions: read + - actions: read|write - checks: read + - statuses: read + - workflows: write + forbidden: + - delete_repo diff --git a/.github/workflows/agent-continuous-ops.yml b/.github/workflows/agent-continuous-ops.yml index 5ece9aa9087..7647509b1bb 100644 --- a/.github/workflows/agent-continuous-ops.yml +++ b/.github/workflows/agent-continuous-ops.yml @@ -1,17 +1,22 @@ name: Continuous agent ops # 24/7 unattended advancement of open agent PRs. -# Complements event-driven agent-review-auto-jules + peer-review-orchestrator: -# those fire on bot feedback; this catches PRs that went quiet, got dirty, -# or never received a follow-up after peer-review-ready. +# High-performance rewrite (OPERATOR 2026-08-10/11): +# - No false "4-day stall" on brand-new / never-commented PRs +# - Self-nudge excluded from loop + approval; SHA sticky-skip +# - checks:read so failing status detection works +# - Display moniker heyVern; live ping only @jules # -# Requires: Jules GitHub App (repo access). Optional: secrets.JULES_API_KEY -# Security: no secrets in prompts; OPERATOR_TOKEN only for comment write if set. +# Complements event-driven agent-review-auto-jules + peer-review-orchestrator. +# Requires: Jules GitHub App. Optional: OPERATOR_GITHUB_TOKEN for privileged comments. on: schedule: - # Every 2 hours — enough to clear lag without burning review quota - - cron: '17 */2 * * *' +<<<<<<< HEAD + # Every hour — enough to clear lag without burning review quota +======= +>>>>>>> origin/master + - cron: '17 * * * *' workflow_dispatch: inputs: force_all: @@ -32,18 +37,29 @@ permissions: {} jobs: sweep: runs-on: ubuntu-latest - timeout-minutes: 10 + timeout-minutes: 12 permissions: - contents: read + contents: write pull-requests: write issues: write + checks: read + statuses: read steps: + - name: Checkout monorepo + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + + - name: Calculate Response Time Lag Index + env: + OPERATOR_GITHUB_TOKEN: ${{ secrets.OPERATOR_GITHUB_TOKEN || secrets.OPERATOR_TOKEN || secrets.GITHUB_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + run: | + python3 scripts/ci/calculate_lag_index.py + - name: Sweep open PRs and advance stuck work uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 env: FORCE_ALL: ${{ github.event.inputs.force_all || 'false' }} MAX_PRS: ${{ github.event.inputs.max_prs || '8' }} - # Prefer operator token so @jules / @coderabbitai accept write-path comments HAS_OPERATOR: ${{ secrets.OPERATOR_GITHUB_TOKEN != '' || secrets.OPERATOR_TOKEN != '' }} with: github-token: ${{ secrets.OPERATOR_GITHUB_TOKEN || secrets.OPERATOR_TOKEN || secrets.GITHUB_TOKEN }} @@ -51,8 +67,30 @@ jobs: const forceAll = process.env.FORCE_ALL === 'true'; const maxPrs = Math.min(Number(process.env.MAX_PRS) || 8, 20); const marker = ''; - const debounceMs = 90 * 60 * 1000; // 90 minutes - const staleMs = 3 * 60 * 60 * 1000; // 3 hours without agent activity +<<<<<<< HEAD + + // Default fallbacks + const defaultDebounceMs = 90 * 60 * 1000; // 90 minutes + const defaultStaleMs = 3 * 60 * 60 * 1000; // 3 hours without agent activity + + // Load dynamic lag index if available + const fs = require('fs'); + let lagIndex = {}; + try { + if (fs.existsSync('docs/ops/response_time_lag_index.json')) { + lagIndex = JSON.parse(fs.readFileSync('docs/ops/response_time_lag_index.json', 'utf8')); + core.info('Successfully loaded dynamic response time lag index.'); + } + } catch (e) { + core.info('Could not load lag index, using default fallbacks: ' + e.message); + } +======= + const debounceMs = 45 * 60 * 1000; + const stickyDebounceMs = 6 * 60 * 60 * 1000; // sticky reasons: 6h if SHA unchanged + const staleMs = 2 * 60 * 60 * 1000; + const stallMs = 4 * 24 * 60 * 60 * 1000; + const emptyDiffMinAgeMs = 30 * 60 * 1000; +>>>>>>> origin/master const agentLogins = [ 'google-labs-jules', 'devin-ai-integration', 'coderabbitai', @@ -62,8 +100,8 @@ jobs: const l = (login || '').toLowerCase(); return agentLogins.some(a => l.includes(a)); }; + const isSelfNudge = (c) => c.body && c.body.includes(marker); - // List open non-draft PRs (newest activity first) const prs = await github.paginate(github.rest.pulls.list, { owner: context.repo.owner, repo: context.repo.repo, @@ -82,9 +120,9 @@ jobs: for (const pr of eligible) { if (acted >= maxPrs) break; - // Fresh mergeability let mergeable = pr.mergeable; let mergeableState = pr.mergeable_state; + let changedFiles = pr.changed_files; try { const { data: fresh } = await github.rest.pulls.get({ owner: context.repo.owner, @@ -93,11 +131,11 @@ jobs: }); mergeable = fresh.mergeable; mergeableState = fresh.mergeable_state; + changedFiles = fresh.changed_files; } catch (e) { core.info(`PR #${pr.number} get skip: ${e.message}`); } - // Comments for debounce + last agent activity const comments = await github.paginate(github.rest.issues.listComments, { owner: context.repo.owner, repo: context.repo.repo, @@ -105,25 +143,128 @@ jobs: per_page: 100, }); + // Get dynamic debounce and stale times + let debounceMs = defaultDebounceMs; + let staleMs = defaultStaleMs; + + if (lagIndex.by_pr && lagIndex.by_pr[String(pr.number)]) { + const metrics = lagIndex.by_pr[String(pr.number)]; + if (metrics.suggested_debounce_ms) { + debounceMs = metrics.suggested_debounce_ms; + } + if (metrics.suggested_stale_ms) { + staleMs = metrics.suggested_stale_ms; + } + } else if (lagIndex.global_averages) { + if (lagIndex.global_averages.suggested_debounce_ms) { + debounceMs = lagIndex.global_averages.suggested_debounce_ms; + } + if (lagIndex.global_averages.suggested_stale_ms) { + staleMs = lagIndex.global_averages.suggested_stale_ms; + } + } + + core.info(`PR #${pr.number}: Using debounceMs=${debounceMs} (${Math.round(debounceMs/60000)}m), staleMs=${staleMs} (${Math.round(staleMs/3600000)}h)`); + const lastOps = comments - .filter(c => c.body && c.body.includes(marker)) + .filter(isSelfNudge) .sort((a, b) => new Date(b.created_at) - new Date(a.created_at))[0]; + + // Sticky skip: same head SHA already nudged → long quiet period + let lastOpsSha = null; + if (lastOps && lastOps.body) { + const m = lastOps.body.match(/^sha:\s*([0-9a-f]{7,40})/m); + if (m) lastOpsSha = m[1]; + } if (lastOps && !forceAll) { const age = Date.now() - new Date(lastOps.created_at).getTime(); - if (age < debounceMs) { - core.info(`PR #${pr.number}: debounced (${Math.round(age/60000)}m ago)`); + const sameSha = lastOpsSha && pr.head.sha.startsWith(lastOpsSha); + const limit = sameSha ? stickyDebounceMs : debounceMs; + if (age < limit) { + core.info(`PR #${pr.number}: debounced (${Math.round(age/60000)}m, sameSha=${!!sameSha})`); continue; } } - const lastAgentComment = comments - .filter(c => isAgent(c.user?.login)) - .sort((a, b) => new Date(b.created_at) - new Date(a.created_at))[0]; + const agentComments = comments + .filter(c => isAgent(c.user?.login) && !isSelfNudge(c)) + .sort((a, b) => new Date(b.created_at) - new Date(a.created_at)); + + const lastAgentComment = agentComments[0] || null; const lastAgentAge = lastAgentComment ? Date.now() - new Date(lastAgentComment.created_at).getTime() - : Infinity; + : null; + + let statusFailed = false; + let failCount = 0; + try { + const checkRuns = await github.paginate(github.rest.checks.listForRef, { + owner: context.repo.owner, + repo: context.repo.repo, + ref: pr.head.sha, + per_page: 50, + }); + // Prefer latest run per check name + const byName = new Map(); + for (const c of (checkRuns || [])) { + const prev = byName.get(c.name); + if (!prev || new Date(c.completed_at || c.started_at || 0) > new Date(prev.completed_at || prev.started_at || 0)) { + byName.set(c.name, c); + } + } + const latest = [...byName.values()].filter(c => c.status === 'completed'); + // Do NOT treat cancelled as failure (concurrency cancel-in-progress is normal) + const failed = latest.filter(c => + ['failure', 'timed_out', 'action_required'].includes(c.conclusion) + ); + if (failed.length > 0) { + statusFailed = true; + failCount = failed.length; + } + } catch (e) { + core.info(`PR #${pr.number} checks skip: ${e.message}`); + } + + let requestingApproval = false; + const approvalRegex = /\b(requesting approval|waiting for approval|please approve|requires approval)\b/i; + if (lastAgentComment && lastAgentComment.body && approvalRegex.test(lastAgentComment.body)) { + requestingApproval = true; + } + + let loopDetected = false; + if (agentComments.length >= 3) { + let lastCommitTime = null; + try { + const { data: headCommit } = await github.rest.repos.getCommit({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: pr.head.sha, + }); + lastCommitTime = new Date( + headCommit.commit.committer?.date || headCommit.commit.author?.date || 0 + ).getTime(); + } catch (e) { + core.info(`PR #${pr.number} getCommit skip: ${e.message}`); + } + + if (lastCommitTime != null && lastCommitTime > 0) { + const newestAgent = agentComments[0].user?.login; + let consecutive = 0; + for (const c of agentComments) { + if (c.user?.login === newestAgent && + new Date(c.created_at).getTime() > lastCommitTime) { + consecutive += 1; + } else { + break; + } + } + if (consecutive >= 3) loopDetected = true; + } + } + + const prAgeMs = Date.now() - new Date(pr.created_at).getTime(); + const emptyDiff = (changedFiles === 0) && prAgeMs > emptyDiffMinAgeMs; - // Open review threads (unresolved) let openThreads = 0; try { const q = ` @@ -149,41 +290,56 @@ jobs: const dirty = mergeableState === 'dirty' || mergeable === false; const blocked = mergeableState === 'blocked' || mergeableState === 'unstable'; - const stale = lastAgentAge > staleMs; - const needsWork = dirty || (blocked && openThreads > 0) || (stale && openThreads > 0); + const stale = lastAgentAge != null && lastAgentAge > staleMs; + const stale4Days = lastAgentAge != null && lastAgentAge > stallMs; - if (!needsWork && !forceAll) { + const needsWork = dirty || + (blocked && openThreads > 0) || + (stale && openThreads > 0) || + stale4Days || + statusFailed || + requestingApproval || + loopDetected || + emptyDiff || + forceAll; + + if (!needsWork) { core.info(`PR #${pr.number}: clean enough (state=${mergeableState} threads=${openThreads})`); continue; } - // Build action prompt const reasons = []; if (dirty) reasons.push('merge conflict / dirty vs base'); if (blocked && openThreads > 0) reasons.push(`${openThreads} unresolved review thread(s)`); if (stale) reasons.push(`stale agent activity (${Math.round(lastAgentAge/3600000)}h)`); + if (stale4Days) reasons.push('4-day stall (BUG #159 — inactive after prior agent activity)'); + if (statusFailed) reasons.push(`status checks failing (${failCount})`); + if (requestingApproval) reasons.push('agent requesting approval'); + if (loopDetected) reasons.push('loop (consecutive agent comments without commits)'); + if (emptyDiff) reasons.push('empty diff (0 changed files, age>30m)'); if (forceAll) reasons.push('forced sweep'); const instructions = []; - if (dirty) { - instructions.push('1. Rebase or merge base into head; resolve conflicts; push.'); - instructions.push('2. Prefer content-preserving resolution; cite Implements: if board item applies.'); - } + if (dirty) instructions.push('- Rebase/merge base into head; resolve conflicts; push.'); if (openThreads > 0) { - instructions.push(`${dirty ? '3' : '1'}. Address **all open review threads** (CodeRabbit, Devin, Copilot).`); - instructions.push(`${dirty ? '4' : '2'}. Prefer minimal diffs; preserve Sentinel 0o600/0o700.`); + instructions.push('- Address **all open review threads** (CodeRabbit, Devin, Copilot).'); + instructions.push('- Prefer minimal diffs; preserve Sentinel 0o600/0o700.'); } - instructions.push('Push commits to the existing head branch. Do not retarget base without cause.'); - instructions.push('Skip pure nits only if they conflict with security/gates.'); - instructions.push('If the PR is superseded, close it with a pointer to the replacement.'); + if (stale4Days) instructions.push('- **4-day stall (#159):** revive with concrete next step or close if superseded.'); + if (statusFailed) instructions.push('- **Checks failed:** fix or comment context if transient.'); + if (requestingApproval) instructions.push('- **Approval path:** ready for human/OPERATOR, or continue with explicit steering.'); + if (loopDetected) instructions.push('- **Loop break:** change approach or files; stop identical comment cycles.'); + if (emptyDiff) instructions.push('- **Empty diff:** commit and push real changes.'); + instructions.push('- Push to existing head branch. No Class 3/4 artifacts.'); + // Display moniker only — live trigger is @jules (do not @heyVern real users) const body = [ marker, `sha: ${pr.head.sha}`, `state: ${mergeableState}`, `threads_open: ${openThreads}`, '', - `@jules **Continuous ops** (GHA agent-continuous-ops) — unattended advance.`, + `@jules **opsSweep** (heyVern lane) — high-perf unattended advance.`, '', `PR #${pr.number} · \`${pr.head.ref}\` → \`${pr.base.ref}\``, `**Why:** ${reasons.join('; ')}`, @@ -191,8 +347,8 @@ jobs: '### Instructions', ...instructions, '', - 'Read AGENTS.md. No Class 3/4 artifacts. No secret leaks.', - 'Agent: Grok orchestration · Profile: https://x.com/grok', + 'Monikers: docs/ops/AGENT-MONIKERS.md · Read AGENTS.md.', + 'Agent: Grok (archW1z) orchestration · https://x.com/grok', ].join('\n'); await github.rest.issues.createComment({ @@ -205,15 +361,27 @@ jobs: acted += 1; report.push(`#${pr.number} (${reasons.join(', ')})`); core.info(`PR #${pr.number}: nudged — ${reasons.join('; ')}`); - - // Brief pause to avoid secondary rate limits - await new Promise(r => setTimeout(r, 1500)); + await new Promise(r => setTimeout(r, 1200)); } core.summary - .addHeading('Continuous agent ops') - .addRaw(`Acted on **${acted}** PR(s) this sweep.`) + .addHeading('Continuous agent ops (high-perf)') + .addRaw(`Acted on **${acted}** PR(s).`) .addList(report.length ? report : ['(none eligible)']) .write(); core.setOutput('acted', String(acted)); + + - name: Commit and Push Updated Lag Index & SSOT + env: + GITHUB_TOKEN: ${{ secrets.OPERATOR_GITHUB_TOKEN || secrets.OPERATOR_TOKEN || secrets.GITHUB_TOKEN }} + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "github-actions[bot]@users.noreply.github.com" + git add docs/ops/response_time_lag_index.json docs/ops/LANE_CONSOLIDATION_SSOT.md + if ! git diff-index --quiet HEAD --; then + git commit -m "docs: dynamic update of lane consolidation lag index & SSOT" + git push origin HEAD:${{ github.ref }} || echo "Could not push changes; skipping (likely read-only token or PR branch)" + else + echo "No changes to lag index/SSOT." + fi diff --git a/.github/workflows/agent-jules-on-issues.yml b/.github/workflows/agent-jules-on-issues.yml index 19a0ccf8296..adf8c0e580b 100644 --- a/.github/workflows/agent-jules-on-issues.yml +++ b/.github/workflows/agent-jules-on-issues.yml @@ -11,18 +11,30 @@ name: Jules on Issues (label / @jules) # Optional: secrets.JULES_API_KEY for google-labs-code/jules-invoke # # SECURITY: Issue triggers are restricted — untrusted openers cannot burn quota. +# +# NOTE: push is listed only so a no-op job can succeed (avoids 0-job failure +# status pollution on every push). Real work stays issues / issue_comment only. +# skip-on-push is UNCONDITIONAL so graph always has ≥1 job. Concurrency fully +# removed. Per-issue serialization deferred. on: + push: + branches: + - '**' issues: types: [labeled, opened] issue_comment: types: [created] -concurrency: - group: jules-issue-${{ github.event.issue.number || github.run_id }} - cancel-in-progress: false - jobs: + # Always runs — guarantees the workflow never materializes as 0-job (GitHub + # marks those failed). Real work is gated on the other jobs' if conditions. + skip-on-push: + runs-on: ubuntu-latest + steps: + - name: Always-green no-op (issue/comment work lives in other jobs) + run: echo "agent-jules-on-issues — skip-on-push always green; real work gated by event if" + jules-on-label: if: | github.event_name == 'issues' && diff --git a/.github/workflows/agent-review-auto-jules.yml b/.github/workflows/agent-review-auto-jules.yml index a4342da80d3..a8b1543f5f8 100644 --- a/.github/workflows/agent-review-auto-jules.yml +++ b/.github/workflows/agent-review-auto-jules.yml @@ -1,11 +1,8 @@ name: Agent review → auto Jules # When CodeRabbit, Devin, or other review bots leave feedback, automatically -# summon Jules to apply fixes. Operator no longer comments "@jules resolve". -# -# Requires: secrets.JULES_API_KEY (optional but recommended for invoke path) -# Jules GitHub App must have repo access. Prefer Reactive Mode OFF so Jules -# also picks up the posted @jules comment on PRs it owns. +# summon Jules via @jules (display moniker: heyVern — do not @-mention strangers). +# Monikers: docs/ops/AGENT-MONIKERS.md on: pull_request_review: @@ -125,7 +122,7 @@ jobs: const path = context.payload.comment?.path || ''; const body = [ marker, - `@jules **Auto-resolve** (GHA agent-review-auto-jules) — do not wait for a human ping.`, + `@jules **Auto-resolve** (heyVern lane / GHA agent-review-auto-jules) — do not wait for a human ping.`, ``, `Bot feedback from **${bot}** on PR #${prNumber} (branch \`${head}\`).`, path ? `File: \`${path}\`` : '', @@ -142,7 +139,8 @@ jobs: `4. If conflicts with base exist, resolve them.`, `5. Skip pure nits only if they conflict with security/gates; otherwise apply autofixes.`, ``, - `Agent: Grok orchestration · Profile: https://x.com/grok`, + `Monikers: docs/ops/AGENT-MONIKERS.md`, + `Agent: Grok (archW1z) orchestration · Profile: https://x.com/grok`, ].filter(Boolean).join('\n'); await github.rest.issues.createComment({ owner: context.repo.owner, diff --git a/.github/workflows/deepseek-ci.yml b/.github/workflows/deepseek-ci.yml new file mode 100644 index 00000000000..41d83cb14da --- /dev/null +++ b/.github/workflows/deepseek-ci.yml @@ -0,0 +1,262 @@ +name: DeepSeek CI – Agentic (safe) + +# DeepSeek v4-Pro web-wrapper path for PR review / invoke. +# Security: ephemeral HOME under RUNNER_TEMP only — no session/cookie cache +# (policy from #112/#114). Work context may use agent-context-store separately. +# +# Cost control: NOT on every synchronize. Opt-in via label, mention, or dispatch. +# Agentic: @deepseek / @deepseek-ci / @deepCore (case-insensitive) — no CLI required. +# Monikers: docs/ops/AGENT-MONIKERS.md +# +# Tokens (model auth — first non-empty wins): +# DEEPSEEK_TOKEN | DEEPSEEK_API_KEY | DEEPSEEK_AUTH_TOKEN | NEXUSCLI_TOKEN +# GitHub writes: +# ARCHWIZ_GITHUB_TOKEN || OPERATOR_GITHUB_TOKEN || OPERATOR_TOKEN || GITHUB_TOKEN + +on: + pull_request: + types: [labeled, opened, reopened] + issue_comment: + types: [created] + pull_request_review_comment: + types: [created] + pull_request_review: + types: [submitted] + workflow_dispatch: + inputs: + pr_number: + description: 'PR number to review (positive decimal; empty skips PR review)' + required: false + default: '' + +concurrency: + group: deepseek-ci-${{ github.event_name }}-${{ github.event.pull_request.number || github.event.issue.number || github.run_id }} + cancel-in-progress: true + +permissions: {} + +jobs: + gate: + runs-on: ubuntu-latest + outputs: + run: ${{ steps.check.outputs.run }} + pr_number: ${{ steps.check.outputs.pr_number }} + reason: ${{ steps.check.outputs.reason }} + steps: + - id: check + env: + EVENT: ${{ github.event_name }} + ACTION: ${{ github.event.action || '' }} + LABEL: ${{ github.event.label.name || '' }} + COMMENT_BODY: ${{ github.event.comment.body || github.event.review.body || '' }} + SENDER_TYPE: ${{ github.event.sender.type || '' }} + ASSOCIATION: ${{ github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association || '' }} + # Only use issue.number if it's actually a PR (issue.pull_request is set) + PR: ${{ github.event.pull_request.number || (github.event.issue.pull_request && github.event.issue.number) || github.event.inputs.pr_number || '' }} + # Multi-name probe — user may have stored under alternate keys + HAS_MODEL: ${{ secrets.DEEPSEEK_TOKEN != '' || secrets.DEEPSEEK_API_KEY != '' || secrets.DEEPSEEK_AUTH_TOKEN != '' || secrets.NEXUSCLI_TOKEN != '' }} + HAS_GH: ${{ secrets.ARCHWIZ_GITHUB_TOKEN != '' || secrets.OPERATOR_GITHUB_TOKEN != '' || secrets.OPERATOR_TOKEN != '' }} + run: | + set -euo pipefail + run=false + reason="none" + pr_number="${PR}" + + # --- trigger detection (agentic, mirrors gemini-dispatch / jules) --- + if [ "$EVENT" = "workflow_dispatch" ]; then + run=true + reason="dispatch" + elif [ "$EVENT" = "pull_request" ]; then + if [ "$LABEL" = "deepseek-ci" ] || [ "$LABEL" = "deepseek" ] || [ "$LABEL" = "deepCore" ]; then + run=true + reason="label:$LABEL" + fi + elif [ "$EVENT" = "issue_comment" ] || [ "$EVENT" = "pull_request_review_comment" ] || [ "$EVENT" = "pull_request_review" ]; then + if [ "$SENDER_TYPE" = "User" ]; then + case "$ASSOCIATION" in + OWNER|MEMBER|COLLABORATOR) + lower=$(printf '%s' "$COMMENT_BODY" | tr '[:upper:]' '[:lower:]') + if printf '%s' "$lower" | grep -qE '(^|[^a-z0-9_])@(deepseek-ci|deepseek|deepcore)\b'; then + run=true + reason="mention" + fi + ;; + esac + fi + fi + + # Validate pr_number: accept only positive decimal integers (or empty for dispatch skip) + if [ -n "$pr_number" ]; then + if ! printf '%s' "$pr_number" | grep -qE '^[1-9][0-9]*$'; then + echo "::warning::Invalid pr_number='$pr_number' — must be positive decimal; clearing" + pr_number="" + if [ "$reason" = "dispatch" ]; then + run=false + reason="invalid_pr_number" + fi + fi + fi + + # For mention/label on non-PR issue, skip agent (ack may still fire) + if [ "$run" = "true" ] && [ -z "$pr_number" ] && [ "$reason" != "dispatch" ]; then + echo "::notice::Trigger on non-PR or missing PR number — agent skipped" + run=false + if [ "$reason" = "mention" ] || [[ "$reason" == label:* ]]; then + : # keep reason for ack diagnostic + else + reason="not_a_pr" + fi + fi + + if [ "$run" = "true" ] && [ "$HAS_MODEL" != "true" ]; then + echo "::notice::DeepSeek model auth unset — checked DEEPSEEK_TOKEN, DEEPSEEK_API_KEY, DEEPSEEK_AUTH_TOKEN, NEXUSCLI_TOKEN. Add one as a *repository* secret (Settings → Secrets and variables → Actions). Environment-scoped secrets require jobs..environment." + reason="missing_model_secret" + run=false + fi + + if [ "$HAS_GH" != "true" ]; then + echo "::notice::No ARCHWIZ/OPERATOR token — PR comments may use GITHUB_TOKEN only" + fi + + echo "run=$run" >> "$GITHUB_OUTPUT" + echo "pr_number=${pr_number}" >> "$GITHUB_OUTPUT" + echo "reason=$reason" >> "$GITHUB_OUTPUT" + echo "Gate: run=$run reason=$reason has_model=$HAS_MODEL pr=$pr_number" + + ack: + needs: gate + if: needs.gate.outputs.reason == 'mention' || needs.gate.outputs.reason == 'label:deepseek-ci' || needs.gate.outputs.reason == 'label:deepseek' || needs.gate.outputs.reason == 'label:deepCore' || needs.gate.outputs.reason == 'missing_model_secret' + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - name: Acknowledge (eyes) + tracking + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0 + env: + GATE_REASON: ${{ needs.gate.outputs.reason }} + with: + script: | + const number = context.payload.pull_request?.number || context.payload.issue?.number; + const reason = process.env.GATE_REASON || 'unknown'; + const eventName = context.eventName; + + if (context.payload.comment?.id) { + try { + if (eventName === 'pull_request_review_comment') { + await github.rest.reactions.createForPullRequestReviewComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: 'eyes', + }); + } else { + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: 'eyes', + }); + } + } catch (e) { + core.info('Comment reaction skip: ' + e.message); + } + } + + if (number && (context.payload.comment || context.payload.review || context.payload.label)) { + const isMissingSecret = reason === 'missing_model_secret'; + const bodyLines = isMissingSecret + ? [ + '`deepCore` (DeepSeek CI) trigger received but **model auth unset**.', + 'Add a repository secret: `DEEPSEEK_TOKEN` | `DEEPSEEK_API_KEY` | `DEEPSEEK_AUTH_TOKEN` | `NEXUSCLI_TOKEN`.', + `Tracking: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, + '', + '_See docs/ops/DEEPSEEK-CI.md_', + ] + : [ + `⚡ \`deepCore\` (DeepSeek CI) received. reason=\`${reason}\``, + `Tracking: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, + '', + '_See docs/ops/DEEPSEEK-CI.md_', + ]; + + try { + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: number, + body: bodyLines.join('\n'), + }); + } catch (e) { + core.info('Ack comment skip: ' + e.message); + } + } + + deepseek-agent: + needs: gate + if: needs.gate.outputs.run == 'true' + runs-on: ubuntu-latest + timeout-minutes: 15 + permissions: + contents: read + pull-requests: write + issues: write + env: + # First non-empty model secret wins (expression coalescing) + DEEPSEEK_TOKEN: ${{ secrets.DEEPSEEK_TOKEN || secrets.DEEPSEEK_API_KEY || secrets.DEEPSEEK_AUTH_TOKEN || secrets.NEXUSCLI_TOKEN }} + OPERATOR_TOKEN: ${{ secrets.ARCHWIZ_GITHUB_TOKEN || secrets.OPERATOR_GITHUB_TOKEN || secrets.OPERATOR_TOKEN || secrets.GITHUB_TOKEN }} + GH_TOKEN: ${{ secrets.ARCHWIZ_GITHUB_TOKEN || secrets.OPERATOR_GITHUB_TOKEN || secrets.OPERATOR_TOKEN || secrets.GITHUB_TOKEN }} + steps: + - name: Checkout + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + fetch-depth: 1 + + - name: Setup Node (PoW WASM) + uses: actions/setup-node@0a44ba7841725637a19e28fa30b79a866c81b0a6 # v4.0.4 + with: + node-version: '20' + + - name: Setup Python + uses: actions/setup-python@39cd14951b08e74b54015e9e001cdefcf80e669f # v5.1.1 + with: + python-version: '3.11' + + - name: Install deps + run: | + pip install --quiet curl_cffi requests pyyaml + + - name: Ephemeral home + run CI mode + env: + PYTHONPATH: ${{ github.workspace }}/multi-ai-cli + PR_NUMBER: ${{ needs.gate.outputs.pr_number }} + GITHUB_REPOSITORY: ${{ github.repository }} + run: | + set -euo pipefail + export HOME="${RUNNER_TEMP}/deepseek-webwrapper-home" + mkdir -p "$HOME" + chmod 700 "$HOME" + export DEEPSEEK_WASM_SOLVER="${GITHUB_WORKSPACE}/deepcli/pow_solver.js" + # Final guard: only positive decimal + if [ -n "${PR_NUMBER:-}" ] && ! printf '%s' "$PR_NUMBER" | grep -qE '^[1-9][0-9]*$'; then + echo "::error::Invalid PR_NUMBER=$PR_NUMBER" + exit 1 + fi + python -m ci_mode \ + --workspace "$GITHUB_WORKSPACE" \ + --cache-dir "${RUNNER_TEMP}/deepseek-cache" \ + --pr "${PR_NUMBER:-}" + + - name: Scrub ephemeral session + if: always() + run: | + rm -rf "${RUNNER_TEMP}/deepseek-webwrapper-home" "${RUNNER_TEMP}/deepseek-cache" || true + + - name: Upload non-secret summary + uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3 + if: always() + with: + name: deepseek-output + path: deepseek_output.json + if-no-files-found: ignore + retention-days: 7 diff --git a/.github/workflows/gemini-dispatch.yml b/.github/workflows/gemini-dispatch.yml index 66fc26c3957..fd987c84377 100644 --- a/.github/workflows/gemini-dispatch.yml +++ b/.github/workflows/gemini-dispatch.yml @@ -5,10 +5,8 @@ name: '🔀 Gemini Dispatch (free-tier agentic)' # # QUOTA POLICY: # - Automatic PR review on opened/synchronize is DISABLED here. -# Peer bots run first (peer-review-orchestrator → CodeRabbit autofix), -# then gemini-after-peers runs the second-pass review. -# - On-demand @gemini-cli /review|/triage|… still fires immediately. -# - Issue triage on opened/reopened still fires (Lite model via model-router). +# - On-demand @gemini-cli and case-insensitive @sparkFlux fire immediately. +# Monikers: docs/ops/AGENT-MONIKERS.md on: pull_request: @@ -41,7 +39,11 @@ jobs: ) || ( contains(fromJSON('["issue_comment", "pull_request_review_comment", "pull_request_review"]'), github.event_name) && github.event.sender.type == 'User' && - startsWith(github.event.comment.body || github.event.review.body || '', '@gemini-cli') && + ( + startsWith(github.event.comment.body || github.event.review.body || '', '@gemini-cli') || + startsWith(github.event.comment.body || github.event.review.body || '', '@sparkFlux') || + startsWith(github.event.comment.body || github.event.review.body || '', '@sparkflux') + ) && contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association || github.event.review.author_association || github.event.issue.author_association) ) runs-on: ubuntu-latest @@ -66,8 +68,12 @@ jobs: script: | const eventType = process.env.EVENT_TYPE; const request = process.env.REQUEST || ''; + const lower = request.toLowerCase(); + + const stripPrefix = (s) => s + .replace(/^@(gemini-cli|sparkflux)\b/i, '') + .trim(); - // PR number: direct PR events, else issue number when comment is on a PR let prNumber = context.payload.pull_request?.number || null; if (!prNumber && context.payload.issue?.pull_request) { prNumber = context.payload.issue.number; @@ -79,14 +85,14 @@ jobs: core.info('PR event → defer Gemini review until peer gate (saves quota)'); } else if (['issues.opened', 'issues.reopened'].includes(eventType)) { core.setOutput('command', 'triage'); - } else if (request.startsWith('@gemini-cli /review')) { + } else if (lower.startsWith('@gemini-cli /review') || lower.startsWith('@sparkflux /review')) { core.setOutput('command', 'review'); - core.setOutput('additional_context', request.replace(/^@gemini-cli \/review/, '').trim()); - } else if (request.startsWith('@gemini-cli /triage')) { + core.setOutput('additional_context', stripPrefix(request).replace(/^\/review/i, '').trim()); + } else if (lower.startsWith('@gemini-cli /triage') || lower.startsWith('@sparkflux /triage')) { core.setOutput('command', 'triage'); - } else if (request.startsWith('@gemini-cli')) { + } else if (lower.startsWith('@gemini-cli') || lower.startsWith('@sparkflux')) { core.setOutput('command', 'invoke'); - core.setOutput('additional_context', request.replace(/^@gemini-cli/, '').trim()); + core.setOutput('additional_context', stripPrefix(request)); } else { core.setOutput('command', 'none'); } @@ -99,7 +105,7 @@ jobs: state: 'open', per_page: 40, }); - const agentHints = ['jules', 'devin', 'coderabbit', 'ecc-tools', 'gemini']; + const agentHints = ['jules', 'devin', 'coderabbit', 'ecc-tools', 'gemini', 'sparkflux']; const relevant = prs.filter(p => { const u = ((p.user && p.user.login) || '').toLowerCase(); const body = ((p.body || '') + ' ' + (p.title || '')).toLowerCase(); @@ -125,12 +131,21 @@ jobs: const number = context.payload.pull_request?.number || context.payload.issue?.number; if (context.payload.comment?.id) { try { - await github.rest.reactions.createForIssueComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: context.payload.comment.id, - content: 'eyes', - }); + if (context.eventName === 'pull_request_review_comment') { + await github.rest.reactions.createForPullRequestReviewComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: 'eyes', + }); + } else { + await github.rest.reactions.createForIssueComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: context.payload.comment.id, + content: 'eyes', + }); + } } catch (e) { core.info('Comment reaction skip: ' + e.message); } @@ -140,7 +155,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, issue_number: number, - body: `🤖 **Gemini CLI** received \`${cmd}\`. Tracking: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, + body: `⚡ **sparkFlux** (Gemini CLI) received \`${cmd}\`. Tracking: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}\n\n_Live trigger: \`@gemini-cli\` (alias \`@sparkFlux\` case-insensitive). SSOT: docs/ops/AGENT-MONIKERS.md_`, }); } diff --git a/.gitignore b/.gitignore index ad78748427b..92f78bf3112 100644 --- a/.gitignore +++ b/.gitignore @@ -85,6 +85,7 @@ tree_dump.txt explore_output.txt research_dump.txt *.deepseek_api_key +deepseek_output.json # === Generated reports (we keep one latest) === monorepo-report.txt diff --git a/README.md b/README.md index 7e4c089efb7..1b20e610ba1 100644 --- a/README.md +++ b/README.md @@ -75,16 +75,17 @@ Use this ladder when orienting in the tree. `_Entry+ReadMe.md` and `termux-ecosy | Priority | Start here | What you get | |----------|------------|--------------| | 1 | `archwiz/TOOL_INDEX.md` | 28 tools / 7 categories — cockpit, forensic, autonomous, verification | -| 2 | `archwiz/CONCEPT_INDEX.md` | Concepts + status (built / reserved / not built) + feature backlog | -| 3 | `archwiz/REFERENCE_HUB.md` | Links to DATA_FLOW_MANIFEST, SYSTEM_MAP, func/llm indices | -| 4 | `archwiz/METHODOLOGY_INDEX.md` | Approaches tried, failures, what stuck | -| 5 | `archwiz/PROCEDURES.md`, `ARCHWIZARD_TASKS.md` | Runbooks and active tasks | -| 6 | `docs/RECON.md` (this RECON) | Branch/PR critique, refTemplates nesting gaps, prioritized proposals | -| 7 | `replit.md` on branch `critical-proposal` (PR #1) | Critical path/config issues and optimization proposals | -| 8 | `_Entry+ReadMe.md` | One-line command → entry table | -| 9 | `termux-ecosystem-architecture.html` | Visual ecosystem diagram | -| 10 | `refTemplates/README_RECOVERY.md` on `recreate/refTemplates-skeleton` | Metadata-only restore policy for refs | -| 0.1 | `workspace/*.md` `workspace/CAVEMAN_INDEX.md` `workspace/SYSTEM_MAP.md` `workspace/llm_map/{*.md,*.txt,*.json,*.jsonl}` | Full Ecosystem Mapping | +| 2 | `docs/ops/LANE_CONSOLIDATION_SSOT.md` | Master Consolidation, Timing Quotas/CoolDowns & Production Improvements SSOT | +| 3 | `archwiz/CONCEPT_INDEX.md` | Concepts + status (built / reserved / not built) + feature backlog | +| 4 | `archwiz/REFERENCE_HUB.md` | Links to DATA_FLOW_MANIFEST, SYSTEM_MAP, func/llm indices | +| 5 | `archwiz/METHODOLOGY_INDEX.md` | Approaches tried, failures, what stuck | +| 6 | `archwiz/PROCEDURES.md`, `ARCHWIZARD_TASKS.md` | Runbooks and active tasks | +| 7 | `docs/RECON.md` (this RECON) | Branch/PR critique, refTemplates nesting gaps, prioritized proposals | +| 8 | `replit.md` on branch `critical-proposal` (PR #1) | Critical path/config issues and optimization proposals | +| 9 | `_Entry+ReadMe.md` | One-line command → entry table | +| 10 | `termux-ecosystem-architecture.html` | Visual ecosystem diagram | +| 11 | `refTemplates/README_RECOVERY.md` on `recreate/refTemplates-skeleton` | Metadata-only restore policy for refs | +| 12 | `workspace/*.md` `workspace/CAVEMAN_INDEX.md` `workspace/SYSTEM_MAP.md` `workspace/llm_map/{*.md,*.txt,*.json,*.jsonl}` | Full Ecosystem Mapping | Quick command table (also in `_Entry+ReadMe.md`): diff --git a/commingle-swarm/web/src/components/ClientPortal.tsx b/commingle-swarm/web/src/components/ClientPortal.tsx index c0fd4c16485..46ca623aa69 100644 --- a/commingle-swarm/web/src/components/ClientPortal.tsx +++ b/commingle-swarm/web/src/components/ClientPortal.tsx @@ -1,7 +1,7 @@ import { html } from 'lit-html'; import * as API from '../api/NodeClient'; -export const ClientPortal = () => { +export const ClientPortal = (reRender: () => void) => { let vaultText = 'Loading vault snapshot...'; const load = async () => { try { @@ -10,16 +10,16 @@ export const ClientPortal = () => { } catch (e) { vaultText = 'Failed to load vault.'; } - renderView(); + reRender(); }; - // initial load - load(); - const renderView = () => html` + // Defer initialization task using setTimeout to ensure parent completes instantiation first + setTimeout(load, 0); + + return () => html`

Client portal

${vaultText}
`; - return renderView(); }; diff --git a/commingle-swarm/web/src/components/ManagerConsole.tsx b/commingle-swarm/web/src/components/ManagerConsole.tsx index c23c6a1a8f7..43f5d239188 100644 --- a/commingle-swarm/web/src/components/ManagerConsole.tsx +++ b/commingle-swarm/web/src/components/ManagerConsole.tsx @@ -1,15 +1,15 @@ import { html } from 'lit-html'; import * as API from '../api/NodeClient'; -export const ManagerConsole = () => { +export const ManagerConsole = (reRender: () => void) => { let planText = 'Click "Propose trade" to generate an allocation plan via the node.'; const propose = async () => { const trade = { asset: 'ETH/USDT', direction: 'buy', totalSize: 5, strategyId: 'S1' }; const resp = await API.proposeTrade(trade); planText = JSON.stringify(resp, null, 2); - renderView(); + reRender(); }; - const renderView = () => html` + return () => html`

Manager console

`; - return renderView(); }; diff --git a/commingle-swarm/web/src/index.tsx b/commingle-swarm/web/src/index.tsx index 61ed41e6aa1..5f79831557b 100644 --- a/commingle-swarm/web/src/index.tsx +++ b/commingle-swarm/web/src/index.tsx @@ -2,11 +2,23 @@ import { html, render } from 'lit-html'; import { ManagerConsole } from './components/ManagerConsole'; import { ClientPortal } from './components/ClientPortal'; +const container = document.getElementById('app')!; + +const reRender = () => { + render(App(), container); +}; + +// Initialize the subcomponents once as factory closures accepting the reRender callback +const renderManager = ManagerConsole(reRender); +const renderClient = ClientPortal(reRender); + const App = () => html`

Commingle Swarm

- ${ManagerConsole()} - ${ClientPortal()} + ${renderManager()} + ${renderClient()}
`; -render(App(), document.getElementById('app')!); + +// Initial mount +reRender(); diff --git a/deepcli/package.json b/deepcli/package.json new file mode 100644 index 00000000000..a0a15d346f1 --- /dev/null +++ b/deepcli/package.json @@ -0,0 +1,6 @@ +{ + "name": "deepcli-pow", + "private": true, + "type": "module", + "description": "Marks deepcli JS (pow_solver) as ESM for Node 20 CI" +} diff --git a/docs/ARCHW1Z-STATUS.md b/docs/ARCHW1Z-STATUS.md index 34027b63f02..80c0077e001 100644 --- a/docs/ARCHW1Z-STATUS.md +++ b/docs/ARCHW1Z-STATUS.md @@ -32,6 +32,7 @@ repo-gate → termux-smoke → language/provider → master | `docs/schemas/session-ssot.md` | TER-10 Session SSOT | | `docs/schemas/provider-capabilities.md` | Capability registry | | `docs/SECURITY-REMEDIATION.md` | PR #3 A+B+C checklist | +| `docs/ops/LANE_CONSOLIDATION_SSOT.md` | Master Consolidation & Production improvements | --- diff --git a/docs/ops/AGENT-MONIKERS.md b/docs/ops/AGENT-MONIKERS.md new file mode 100644 index 00000000000..bdc1712def2 --- /dev/null +++ b/docs/ops/AGENT-MONIKERS.md @@ -0,0 +1,29 @@ +# Agent Monikers (SSOT) + +Creative **display** call-signs for high-performance agent orchestration. + +**Critical:** Do **not** `@`-mention monikers that collide with real GitHub usernames. +Use backticks or plain text for display. Live triggers remain the original handles +(plus approved aliases registered in the matching workflow). + +| Role | Display moniker | Live trigger (callable) | Notes | +|------|-----------------|-------------------------|-------| +| Jules (implementation) | `heyVern` | `@jules` | App only reacts to `@jules` | +| Gemini CLI (on-demand) | `sparkFlux` | `@gemini-cli` | Dispatch also accepts case-insensitive `@sparkFlux` as alias | +| DeepSeek CI (review/invoke) | `deepCore` | `@deepseek` / `@deepseek-ci` | Workflow also accepts case-insensitive `@deepCore`; labels `deepseek-ci`, `deepseek`, `deepCore` | +| CodeRabbit (review) | `codeHound` | `@coderabbitai` | Reviewer identity unchanged | +| Devin (review/fix) | `devinForge` | Devin app | | +| Continuous-ops sweep | `opsSweep` | (GHA) | Marker: `` | +| OPERATOR / Grok | `archW1z` | human OWNER | Signing: `Signed-off-by: Grok (OPERATOR)` | +| Peer orchestrator | `peerGate` | (GHA) | | + +## Rules + +1. Automated comments: **display** moniker in backticks; **ping** only the live trigger (`@jules`, `@gemini-cli`, `@deepseek` / `@deepseek-ci`). +2. Workflows matching a live trigger **must** also accept the display moniker case-insensitively where registered above. +3. Never put secrets or Class 3/4 material in moniker docs. +4. If a moniker string is later registered as a GH username we do not control, keep it non-@ only. + +## High-performance intent + +Monikers reduce ambiguous role ownership under load without notifying strangers. diff --git a/docs/ops/ARCHWIZ-ADMIN-TOKEN.md b/docs/ops/ARCHWIZ-ADMIN-TOKEN.md new file mode 100644 index 00000000000..5ba73cb7416 --- /dev/null +++ b/docs/ops/ARCHWIZ-ADMIN-TOKEN.md @@ -0,0 +1,115 @@ +# ArchWiz Admin Token (4π¢hw12) + +**Role:** Second Administrator PAT for Grok / OPERATOR / ArchWiz automation. +**Scope target:** Everything the primary `OPERATOR` token has **except** `delete_repo`. + +> GitHub does **not** allow minting classic/fine-grained PATs via API. +> An account owner (or org admin) must create the token in the UI, then store it as a repository/org secret. This document is the SSOT for *what* to create and *where* to wire it. + +## Why a second token + +| Token | Purpose | +|-------|---------| +| `OPERATOR_GITHUB_TOKEN` / `OPERATOR_TOKEN` | Primary privileged GHA + continuous-ops | +| **`ARCHWIZ_GITHUB_TOKEN`** | Parallel admin lane (ArchWiz / 4π¢hw12) — same repo powers, no delete | +| `GITHUB_TOKEN` | Default job token (limited, short-lived) | +| `DEEPSEEK_TOKEN` | **Model auth only** (DeepSeek web-wrapper / API) — **not** a GitHub PAT | + +Never use a GitHub PAT as DeepSeek model auth. Never use `DEEPSEEK_TOKEN` for `gh` / REST admin calls. + +## Create the PAT (owner UI — 2 minutes) + +### Option A — Fine-grained (preferred) + +1. GitHub → **Settings → Developer settings → Personal access tokens → Fine-grained tokens → Generate** +2. **Resource owner:** `timerloggedout-spec` (user or org) +3. **Repository access:** Only `termux-monorepo` (or All repos if you intentionally want org-wide) +4. **Permissions** (match OPERATOR, omit destructive repo delete): + +| Permission | Access | +|------------|--------| +| Contents | Read and write | +| Metadata | Read-only | +| Pull requests | Read and write | +| Issues | Read and write | +| Actions | Read and write | +| Checks | Read and write | +| Commit statuses | Read and write | +| Workflows | Read and write | +| Administration | Read and write *(repo settings, not delete)* | +| Secrets | Read and write *(optional; for secret rotation jobs)* | +| Variables | Read and write *(optional)* | +| Environments | Read and write *(optional)* | +| Pages | Read and write *(if used)* | +| Deployments | Read and write *(if used)* | + +5. **Do not** grant organization `delete_repos` / repository delete capabilities. +6. Generate → copy once → store as secret (below). + +### Option B — Classic PAT + +Scopes: + +```text +repo # full repo (includes private) +workflow # update GHA workflows +write:packages # if packages used +read:org # if org membership needed +admin:repo_hook # if hooks managed via API +``` + +**Omit:** any org-level delete. Classic `repo` cannot delete the repo by itself; still never store a token that is also used for `DELETE /repos/{owner}/{repo}` automation. + +## Store as GitHub Actions secrets + +Repo → **Settings → Secrets and variables → Actions → New repository secret**: + +| Secret name | Value | +|--------------|-------| +| `ARCHWIZ_GITHUB_TOKEN` | the new PAT | +| `OPERATOR_GITHUB_TOKEN` | existing primary (keep) | +| `DEEPSEEK_TOKEN` | DeepSeek session/API token only | + +Optional alias (if you want one name everywhere): + +| Secret name | Notes | +|--------------|-------| +| `OPERATOR_TOKEN` | Fallback some workflows already accept | + +## Workflow consumption pattern + +```yaml +env: + # Admin / git / PR writes — ArchWiz first, then OPERATOR, then default + GH_TOKEN: ${{ secrets.ARCHWIZ_GITHUB_TOKEN || secrets.OPERATOR_GITHUB_TOKEN || secrets.OPERATOR_TOKEN || secrets.GITHUB_TOKEN }} + # Model auth — never the GH PAT + DEEPSEEK_TOKEN: ${{ secrets.DEEPSEEK_TOKEN }} +``` + +`deepseek-ci.yml` and continuous-ops already prefer OPERATOR; follow-up commits add `ARCHWIZ_GITHUB_TOKEN` to the chain. + +## Rotation / compromise + +1. Revoke the leaked PAT in GitHub settings immediately. +2. Mint a replacement with the same matrix above. +3. Update **only** the secret value — no code change required if the secret *name* is stable. +4. Re-run a canary workflow (`workflow_dispatch` on continuous-ops or deepseek-ci). + +## Verification checklist + +- [ ] PAT can `gh api user` and sees `timerloggedout-spec` +- [ ] PAT can open/comment on a test PR +- [ ] PAT can `workflow_dispatch` Actions +- [ ] PAT **cannot** be used as `DEEPSEEK_TOKEN` substitute (by policy) +- [ ] Secret scanning clean after paste (never commit the value) + +## Trace + +| Item | Link | +|------|------| +| DeepSeek CI safe PR | #162 | +| Continuous-ops | #161 | +| Connector catalog | `.github/connectors/README.md` | +| Monikers | `docs/ops/AGENT-MONIKERS.md` (`archW1z`) | + +Signed-off-by: Grok (OPERATOR) / archW1z diff --git a/docs/ops/DEEPSEEK-CI.md b/docs/ops/DEEPSEEK-CI.md new file mode 100644 index 00000000000..89c46479042 --- /dev/null +++ b/docs/ops/DEEPSEEK-CI.md @@ -0,0 +1,72 @@ +# DeepSeek CI (safe path) — Agentic + +**Issue:** #109 +**Implements:** RL-18 (`docs/proposals/active/rate-limit-rotation/ITEMS.md`) +**Supersedes destructive Jules PR:** #134 +**Folders:** `deepcli/` (PoW WASM + proxy), `multi-ai-cli/` (backends + `ci_mode.py`) + +## What landed + +| Artifact | Role | +|----------|------| +| `.github/workflows/deepseek-ci.yml` | Opt-in agentic workflow | +| `multi-ai-cli/ci_mode.py` | Non-interactive review loop | +| `deepcli/pow_solver.js` + `deepseek.wasm` + `package.json` (`type: module`) | PoW for web-wrapper | +| `tests/test_multi_ai_ci.py` | Offline unit tests | +| `docs/ops/ARCHWIZ-ADMIN-TOKEN.md` | Second admin PAT runbook | +| `docs/ops/AGENT-MONIKERS.md` | Display moniker `deepCore` | + +## Agentic triggers (no CLI) + +| Trigger | How | +|---------|-----| +| Mention | Comment `@deepseek`, `@deepseek-ci`, or `@deepCore` (case-insensitive) on a **pull request** — OWNER/MEMBER/COLLABORATOR only | +| Label | Add `deepseek-ci`, `deepseek`, or `deepCore` | +| Dispatch | Actions → DeepSeek CI – Agentic (safe) → Run workflow. `pr_number` must be a positive decimal integer (e.g. `163`); leaving empty intentionally skips PR review | + +Mirrors Gemini (`@gemini-cli` / `sparkFlux`) and Jules (`@jules` / `heyVern`) patterns. + +## Secrets (repository-scoped) + +Model auth — **first non-empty wins**: + +1. `DEEPSEEK_TOKEN` (preferred) +2. `DEEPSEEK_API_KEY` +3. `DEEPSEEK_AUTH_TOKEN` +4. `NEXUSCLI_TOKEN` + +GitHub writes: `ARCHWIZ_GITHUB_TOKEN` → `OPERATOR_GITHUB_TOKEN` → `OPERATOR_TOKEN` → `GITHUB_TOKEN`. + +**If the gate reports "DeepSeek model auth unset":** +- Confirm the secret is a **repository** secret (Settings → Secrets and variables → Actions → Repository secrets), not only an Environment secret. +- Environment secrets require `jobs..environment: ` in the workflow; this workflow uses repo secrets only. +- Name must match one of the four keys above exactly (case-sensitive). +- Empty value counts as unset. + +Never use a GitHub PAT as DeepSeek model auth. Never use `DEEPSEEK_TOKEN` for `gh` / REST admin calls. + +## Security policy + +1. Auth: model secret only for model — never reuse `GITHUB_TOKEN` / OPERATOR as model auth. +2. Session: `HOME=$RUNNER_TEMP/deepseek-webwrapper-home` then **always scrub**. +3. No cookies/tokens in Actions cache or git. +4. Output JSON is **metadata only** (no model text). +5. `pr_number` validated as positive decimal before any `gh pr` call. + +## What #134 did wrong (do not merge) + +- **Deleted** `.github/workflows/agent-continuous-ops.yml` (regressed #161) +- **Deleted** `.github/connectors/*` catalog +- **Deleted** `agent-context-store` composite action +- **Lowered** elevated soft budgets in `model_router.py` +- Ran on **every** `synchronize` (quota burn) + +## ArchWiz admin token + +See `docs/ops/ARCHWIZ-ADMIN-TOKEN.md` — mint PAT in UI (API cannot create PATs), store as `ARCHWIZ_GITHUB_TOKEN`. + +## Next (MCP / multi-ai-cli expansion) + +After this path is stable, wire MCP template repos into `multi-ai-cli`. + +Signed-off-by: Grok (OPERATOR) / archW1z diff --git a/docs/ops/LANE_CONSOLIDATION_SSOT.md b/docs/ops/LANE_CONSOLIDATION_SSOT.md new file mode 100644 index 00000000000..b1cb7b268b1 --- /dev/null +++ b/docs/ops/LANE_CONSOLIDATION_SSOT.md @@ -0,0 +1,204 @@ +# lane-consolidation-ssot — Master Coordination & Production Improvements Map + +**Date:** 2026-08-11 +**Status:** ACTIVE +**Orchestration Profile:** Grok / Jules Automated Operations +**Authority Level:** Production Consolidated SSOT + +--- + +## 1. Executive Summary & Production Objectives + +To maximize return on investment (ROI) and maintain impeccable repository hygiene, this Single Source of Truth (SSOT) consolidates active and closed development lanes, aligns timing quotas and cooldowns, and maps open/closed pull requests and issues to clear, insulated scopes. + +### Core Targets +- **Zero overlapping work-areas:** Delineate exact folder ownership to avoid multi-agent merge conflicts. +- **Quota resilience:** Maximize utilization of free-tier AI pathways (Omni, OpenRouter, Gemini) without hitting hard rate limits (429). +- **Consolidated dispatch pipeline:** Ensure all local command-line interfaces and background orchestrators map through config-rooted endpoints, enforcing strict privilege controls (Sentinel 0o600/0o700 limits). + +--- + +## 2. Timing Quotas, CoolDowns & Soft-Limits Optimization Matrix + +To optimize API usage and ensure stable CI/CD runs, the repository implements a multi-tiered timing, caching, and debounce schema across all automated GitHub Actions workflows. + +### 2.1 Model Router Soft-Limits (Elevated 2026-08-10) +Model routing is controlled via `scripts/model_router.py` using dynamic ELO-based (3L0) ranking, 1-hour temporal caching, and soft budgets defined in `.github/connectors/llm-peers.yaml`. + +| Provider / Model | Triage Limit | Review Limit | Invoke Limit | Role Suitability | +|------------------|--------------|--------------|--------------|-------------------| +| **omni/auto/best-free** | **400** | **250** | **400** | Primary free peer (all roles) | +| **openrouter/google/gemma-4-31b-it:free** | **80** | **80** | **80** | Triage, Review, Invoke | +| **openrouter/google/gemma-4-26b-a4b-it:free** | **80** | **80** | **80** | Triage, Review, Invoke | +| **openrouter/meta-llama/llama-3.3-70b-instruct:free** | **80** | **80** | **80** | Triage, Review, Invoke | +| **openrouter/google/gemma-3-12b-it:free** | **80** | **80** | **80** | Triage, Review, Invoke | +| **openrouter/cohere/north-mini-code:free** | **60** | **60** | **60** | Review, Invoke | +| **openrouter/qwen/qwen3-coder:free** | **60** | **60** | **60** | Review, Invoke | +| **openrouter/deepseek/deepseek-r1:free** | **40** | **40** | **40** | Review (specialized) | +| **gemini/gemini-3.1-flash-lite** | **450** | **450** | **450** | Residual backup | +| **gemini/gemini-3.5-flash-lite** | **450** | **450** | **450** | Residual backup | +| **gemini/gemini-2.5-flash-lite** | **20** | **20** | **20** | Secondary residual | +| **gemini/gemini-3.5-flash** | **20** | **20** | **20** | Secondary residual | +| **gemini/gemini-2.5-flash** | **20** | **20** | **20** | Secondary residual | +| **gemini/gemini-3-flash** | **20** | **20** | **20** | Secondary residual | + +*Note: Newly listed free models must appear in the live OpenRouter models poll before they can be dynamically selected. Conservative fallback `LEGACY_MODELS` is used if polling fails.* + +### 2.2 GitHub Actions Debounces & Sweep Throttles + +``` +[External Bot Feedback] + │ + ▼ +[peer-review-orchestrator.yml] ──► Holds run for review completion (up to 480s) + │ + ├─► 45-Minute Throttle ───► Debounces Auto-CodeRabbit Autofix comments + │ + └─► 90-Second Settle ─────► Pauses to allow autofix commit push before second-pass + │ + ▼ +[agent-review-auto-jules.yml] ───► 20-Minute Debounce prevents redundant @jules summon pings +``` + +#### A. Peer Review Orchestrator (`peer-review-orchestrator.yml`) +- **Max Wait Time:** `480 seconds` (8 minutes) waiting for external peer bots (CodeRabbit, Devin, Aikido, Sentry, Copilot) to complete checks. +- **Autofix Request Throttle:** `45 minutes` per PR. If an autofix marker is present, comments requesting `@coderabbitai autofix` are bypassed. +- **Settle Cooldown:** `90 seconds` sleep delay after posting an autofix request to allow background file writing to complete before subsequent jobs trigger. + +#### B. Agent Review Auto-Jules (`agent-review-auto-jules.yml`) +- **Summon Debounce Window:** `20 minutes` per PR. Ensures Jules is not double-summoned by rapid succession review comments. +- **Trigger Profiles:** Runs on any non-approved `pull_request_review` or review/issue comment created by a Bot (except our own markers). + +#### C. Continuous Agent Ops Sweep (`agent-continuous-ops.yml`) +- **Schedule Interval:** Every `2 hours` (scheduled cron: `17 */2 * * *`). +- **Sweep Debounce Window:** `90 minutes` per PR. Ensures a PR is not spammed by continuous sweep comments if it was recently processed. +- **Unattended Activity Age Limit:** `3 hours` stale duration (agent must have been inactive for at least 3 hours with open threads/conflicts before sweep acts). +- **Sweep Capacity Cap:** Max `8` PRs processed per scheduled run (hard limit `20`) to respect API rate limits and quotas. + +### 2.3 Dynamic Response Lags & Lag Indexing (PR #156) +As merged in PR #156, the agent continuous operations workflow utilizes `scripts/ci/calculate_lag_index.py` to compile a historical response time lag index (`docs/ops/response_time_lag_index.json`), distinguishing between message acknowledgment ("I'm working on it") and actual programmatic responses to adaptively schedule and jump start stuck PRs. + +*Running locally/offline. Fallback defaults applied.* + +| PR/Issue | Message Response Lag | Programmatic Response Lag | Status | +|---|---|---|---| +| Default Fallback | 1.5 hours | 3.0 hours | Active | + +--- + +## 3. Pull Request & Issue Audit (Unified Map) + +Based on live GitHub tracking and active repository branches, open and closed items are consolidated into clear development lanes. + +### 3.1 Open Pull Requests (Live Audit) +1. **PR #149** (`ops(pipes): review-signal alignment docs + disposition matrix`): Focuses on aligning review signals and continuous-ops logic. +2. **PR #148** (`ops(jules): context_key persistence + continue-only auto-jules`): Adds programmatic context and dual-quota gating limits (3 concurrent, 15/24 hours rolling) using cached context stores. +3. **PR #147** (`Programmatic session management via Actions Workflows`): Wire automatic context tracking for Jules. +4. **PR #143** (`Integrate MCP Agent Mail Coordination Layer in GitHub Actions`): Rust-based agent mailbox coordination in workflows. +5. **PR #142** (`⚡ Bolt: Optimize telemetry parsing with state-tracking and seek/tell`): Optimizes real-time dashboard reading performance. +6. **PR #141** (`🛡️ Sentinel: Fix local privilege restrictions and prevent symlink hijacking`): Security hardening of permission walkers. +7. **PR #140** (`🎨 Palette: Stateful & Reactive PWA UX with Manual Vault Refresh`): Reactive web UI state for Commingle Swarm. +8. **PR #137** (`feat(ci): integrate DeepSeek v4-Pro CI with peer routing`): Plumbs reverse-engineered web-wrapper and peer routes. +9. **PR #135** (`📝 CodeRabbit Chat: Align OpenRouter Routing with Supported Models`): Adjusts OpenRouter free model catalogs. +10. **PR #133** (`Diagnose Issue #129 and Verify Codebase Integrity`): Checks telemetry logs and system map. +11. **PR #131** (`feat(multi-agent): implement MoneyBall agent roster`): Team roster bidding/betting arena algorithms. +12. **PR #126** (`📖 Linguist: optimize agentic communication compiler`): CedrLang O(N) translation and markdown compression. + +### 3.2 Active Issue Threads & Alignment +- **Issue #59** (`🚨 CRITICAL: GitHub Actions Workflow Failures`): Resolves Gemini free-tier daily exhaustion via `continue-on-error: true`. +- **Issue #122** (`Model Availability Polling`): Enforces temporal polling caches in `/tmp/model-router`. +- **Issue #86** (`Rate Limits and Model Rotations Optimizations`): Elevated model router budgets (Operator 2026-08-10). +- **Issue #146** (`ops(pipes): Align review disposition`): Maps directly to PR #149 signal alignment. +- **Issue #145** (`ops(jules): Programmatic session management`): Maps directly to PR #148 context keys. +- **Issue #130** (`Model Performance diagnostics`): Addressed by Bolt's telemetry parsing optimizations (state-tracking + seek/tell). +- **Issue #129** (`Development Teams & Emerging Tech Research`): Addressed by MoneyBall betting arena (PR #131). +- **Issue #124** (`Workflows @ call; received`): Tracks pending notifications during long-running GHA orchestrations. +- **Issue #117** (`Agent2Agent Comms Proposal`): Solved by MCP Agent Mail composite GHA mailbox actions. +- **Issue #110** (`Nested Searches`): Powered by Virtual FTS5 tables (`messages_fts` in `local_repo.db`). +- **Issue #109** (`DeepSeek v4-Pro integration`): Tracked in PR #137 CI pipeline. + +--- + +## 4. Development Lanes & Scope Clarification + +To keep work highly organized, all development is segregated into five independent Lanes. No agent may touch a file outside their active lane's domain without explicit coordination. + +``` + ┌──────────────────────────────┐ + │ Dual-Gate Spine │ + │ (repo-gate + termux-smoke) │ + └──────────────┬───────────────┘ + │ + ┌───────────────────────┼───────────────────────┐ + ▼ ▼ ▼ +┌──────────────────┐ ┌──────────────────┐ ┌──────────────────┐ +│ Performance Lane │ │ Security Lane │ │ Reactive PWA │ +│ (Bolt / Lithe) │ │ (Sentinel) │ │ (Palette / Swarm)│ +└──────────────────┘ └──────────────────┘ └──────────────────┘ +``` + +### Lane 1: Performance Optimization & Telemetry (Bolt / Linguist) +- **Primary Scope:** `termux-multi-agent/dashboard.py`, `agent_telemetry_stream.json`, `cedrlang.py`. +- **Core Guardrails:** + - Real-time display MUST utilize `rich.live.Live` and `rich.console.Group` to prevent terminal flicker. + - Telemetry logs MUST use state-tracking and seek/tell incremental I/O (no O(N) full-read repeats). + - Markdown compression (CedrLang) compiler MUST enforce O(N) regex matching and a 6-line caveman stopword list. +- **Active Agent:** Bolt / Linguist. + +### Lane 2: Security & Local Privilege (Sentinel) +- **Primary Scope:** `deepcli/deepcli/core.py`, `tests/test_sentinel_privileges.py`, configuration directories, database connections. +- **Core Guardrails:** + - Configuration directory MUST be `0o700` and config files/cached session files MUST be `0o600`. + - Recursive directory-walking permissions adjusters MUST explicitly skip symlinks (`path.is_symlink()`) to prevent symlink traversal hijacking vulnerabilities. + - Security-sensitive environments checks (e.g. `JULES_API_KEY`) must remain strictly boolean-only (no storage or console exposure). +- **Active Agent:** Sentinel. + +### Lane 3: Reactive UX & Client Portals (Palette) +- **Primary Scope:** `commingle-swarm/web/`, `palette.md` journal. +- **Core Guardrails:** + - Frontend components MUST be lit-html factory closures accepting a `reRender` callback. + - Asynchronous client-portal tasks MUST be deferred using `setTimeout` to ensure parent rendering completed instantiation first. + - Strictly use `pnpm` (`pnpm --filter=commingle-swarm-web run build/serve`); Node-bound files MUST never use npm or yarn. + - Keep UX code modifications minimal (under 50 lines) to avoid regression. +- **Active Agent:** Palette. + +### Lane 4: Multi-Agent Team-Orchestration (MoneyBall / Mail) +- **Primary Scope:** `termux-multi-agent/src/team_manager.py`, `roster.json`, `.github/actions/mcp-agent-mail/`. +- **Core Guardrails:** + - Dynamic roster management MUST employ ELO/3L0 calculations, spectator betting simulations, and culling/mutating bottom/top percentages. + - Agent Mail relies on the Rust-based composite action mailbox under `.github/actions/mcp-agent-mail/action.yml`. +- **Active Agent:** MoneyBall Scout / Betting Arena. + +### Lane 5: Peer Routing, Context, & Workflows (Grok / Jules) +- **Primary Scope:** `scripts/model_router.py`, `agent-review-auto-jules.yml`, `peer-review-orchestrator.yml`, `agent-continuous-ops.yml`. +- **Core Guardrails:** + - To prevent import-time crashes on environments lacking `rich` or third-party curl binaries (e.g., Termux NDK), CLI entrypoints MUST wrap checks in try-except fallbacks, and tests MUST handle gracefully. + - Fallbacks for `curl_cffi` MUST override requests `__init__` and strip out custom `impersonate` keyword arguments. + - Programmatic Jules runs use stable context keys (`pr--`) loaded/saved via `.github/actions/agent-context-store`. + - Enforce dual-quota capacities (3 concurrent active runs, 15 runs per rolling 24-hour period). +- **Active Agent:** Grok / Jules. + +--- + +## 5. Dual-Gate Spine: The Non-Negotiable Integration Rules + +No PR may merge to `master-staging` (and ultimately promote to `master`) without passing the two-gate spine checks: + +1. **Repo Gate:** `python3 scripts/ci/repo_gate.py` (Validates ast structural invariants, file exclusions, and syntax). +2. **Termux Smoke Gate:** `python3 scripts/ci/termux_smoke.py` (Verifies script launches, fallback routines, and command line options in headless simulation). + +For offline-first on-device execution (like BLU B160V mobile devices), execution is strictly limited to standard-library Python scripts. Heavy runtimes (Rust, Bun, Node) are cloud-side offloads only. + +--- + +## 6. Verification and Maintenance Checklist + +To maintain this SSOT, automated sweeps (2-hour cron) and manual operator audits will check: +- [x] Timing quotas are aligned with the elevated budgets in `model_router.py`. +- [x] Cooldown policies prevent concurrent write-clashes on files. +- [x] Security permissions remain tightly bound to Sentinel standards. +- [x] Branch scope is clear and contains no class 3/4 leaked credentials. + +--- + +*Consolidated & Approved by Grok Orchestration Engine (xAI) on behalf of the Termux Monorepo Operators, 2026.* diff --git a/docs/ops/response_time_lag_index.json b/docs/ops/response_time_lag_index.json new file mode 100644 index 00000000000..6676f68cc33 --- /dev/null +++ b/docs/ops/response_time_lag_index.json @@ -0,0 +1,9 @@ +{ + "global_averages": { + "avg_message_response_lag_sec": 5400, + "avg_actual_response_lag_sec": 10800, + "suggested_debounce_ms": 5400000, + "suggested_stale_ms": 10800000 + }, + "by_pr": {} +} \ No newline at end of file diff --git a/multi-ai-cli/ci_mode.py b/multi-ai-cli/ci_mode.py new file mode 100644 index 00000000000..6b2241d01ee --- /dev/null +++ b/multi-ai-cli/ci_mode.py @@ -0,0 +1,260 @@ +#!/usr/bin/env python3 +""" +CI mode for multi-ai-cli – non-interactive DeepSeek review path. + +Implements: RL-18 +Security: +- Never persist cookies / tokens / PoW answers across jobs. +- Cache dir is RUNNER_TEMP only; caller must scrub. +- OPERATOR / DEEPSEEK_TOKEN from env only; never cross-wire. +- Artifact JSON is metadata-only (no model body). +""" +from __future__ import annotations + +import argparse +import json +import os +import subprocess +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) + +import backends.deepseek as ds_mod +from backends.deepseek import DeepSeekBackend +from core.session_manager import SessionManager + + +def _configure_pow(workspace: Path) -> None: + solver = os.environ.get("DEEPSEEK_WASM_SOLVER") + if solver: + ds_mod.WASM_SOLVER = Path(solver) + else: + candidate = workspace / "deepcli" / "pow_solver.js" + if candidate.is_file(): + ds_mod.WASM_SOLVER = candidate + + +def _load_event() -> dict: + event_path = os.environ.get("GITHUB_EVENT_PATH") + if event_path and os.path.exists(event_path): + try: + with open(event_path, "r", encoding="utf-8") as f: + return json.load(f) + except Exception as e: + print(f"Warning: event load failed: {e}", file=sys.stderr) + return {} + + +def _gh_env(token: str | None) -> dict: + env = os.environ.copy() + if token: + env["GH_TOKEN"] = token + env["GITHUB_TOKEN"] = token + return env + + +def run_ci( + event: dict, + workspace: str, + operator_token: str | None, + pr_override: str | None = None, +) -> dict: + workspace_path = Path(workspace) + _configure_pow(workspace_path) + + gh_env = _gh_env(operator_token) + pr_number = pr_override or event.get("pull_request", {}).get("number") + if pr_number is not None: + pr_number = str(pr_number) + repo = ( + event.get("repository", {}).get("full_name") + or os.environ.get("GITHUB_REPOSITORY") + ) + action = event.get("action") + decisions: list[dict] = [] + status = "ok" + + if not pr_number or not repo: + return { + "actions": [], + "event": action, + "pr": pr_number, + "provider_used": "deepseek", + "status": "skipped", + "skipped": "missing pr or repo", + } + + if not os.environ.get("DEEPSEEK_TOKEN"): + print("::error::DEEPSEEK_TOKEN unset — model auth required", file=sys.stderr) + return { + "actions": [{"type": "error", "message": "DEEPSEEK_TOKEN unset"}], + "event": action, + "pr": pr_number, + "provider_used": "deepseek", + "status": "error", + } + + try: + diff = subprocess.check_output( + ["gh", "pr", "diff", str(pr_number), "--repo", repo], + env=gh_env, + text=True, + timeout=60, + ) + except Exception as e: + print(f"::error::diff retrieval failed: {e}", file=sys.stderr) + return { + "actions": [{"type": "error", "message": "diff_retrieval_failed"}], + "event": action, + "pr": pr_number, + "provider_used": "deepseek", + "status": "error", + } + + if not diff.strip(): + return { + "actions": [], + "event": action, + "pr": pr_number, + "provider_used": "deepseek", + "status": "skipped", + "skipped": "empty_diff", + } + + try: + mgr = SessionManager() + backend = DeepSeekBackend(mgr) + prompt = ( + "You are a code reviewer for a Termux monorepo. " + "Focus on security, correctness, and CI reliability. " + "Be concise. Flag Class 3/4 secret risks. " + "Never echo tokens, cookies, or secrets from the diff.\n\n" + f"PR #{pr_number} diff (truncated):\n\n{diff[:8000]}" + ) + analysis = backend.send_message(prompt, []) + + if ( + analysis + and not str(analysis).startswith("Error:") + and not str(analysis).startswith("[No content returned]") + ): + body = str(analysis) + if len(body) > 4000: + body = body[:4000] + "\n\n_(truncated)_" + signature = ( + "\n\n---\n*DeepSeek CI (multi-ai-cli / deepcli PoW) · " + "ephemeral session · Implements: RL-18 · Fixes #109*" + ) + comment_body = body + signature + try: + subprocess.run( + [ + "gh", + "pr", + "comment", + str(pr_number), + "--body", + comment_body, + "--repo", + repo, + ], + env=gh_env, + check=False, + timeout=30, + ) + except Exception as e: + print(f"::warning::Failed to post PR comment: {e}", file=sys.stderr) + + decisions.append( + { + "type": "pr_review", + "pr": pr_number, + "posted": True, + "chars": len(comment_body), + } + ) + else: + print("::warning::empty or invalid DeepSeek analysis", file=sys.stderr) + status = "error" + decisions.append({"type": "error", "message": "empty_analysis"}) + except Exception as e: + print(f"::error::DeepSeek analysis failed: {type(e).__name__}", file=sys.stderr) + status = "error" + decisions.append({"type": "error", "message": type(e).__name__}) + + if any(d.get("type") == "error" for d in decisions): + status = "error" + + return { + "actions": decisions, + "event": action, + "pr": pr_number, + "provider_used": "deepseek", + "status": status, + } + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument("--workspace", required=True) + parser.add_argument("--cache-dir", default="/tmp/deepseek-cache") + parser.add_argument("--pr", default="", help="PR number override") + args = parser.parse_args() + + # Isolate any incidental HOME-relative writes + os.environ.setdefault("MULTI_AI_CACHE_DIR", args.cache_dir) + os.makedirs(args.cache_dir, exist_ok=True) + try: + os.chmod(args.cache_dir, 0o700) + except Exception: + pass + + event = _load_event() + result = run_ci( + event=event, + workspace=args.workspace, + operator_token=os.environ.get("OPERATOR_TOKEN") + or os.environ.get("GH_TOKEN"), + pr_override=args.pr or None, + ) + + # Metadata only — never store model body (secret echo risk) + safe = { + "status": result.get("status"), + "event": result.get("event"), + "pr": result.get("pr"), + "provider_used": result.get("provider_used"), + "actions": [ + {k: v for k, v in a.items() if k != "summary"} + for a in result.get("actions", []) + ], + "skipped": result.get("skipped"), + } + + output_path = Path("deepseek_output.json") + flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC + mode = 0o600 + try: + fd = os.open(output_path, flags, mode) + with open(fd, "w", encoding="utf-8") as f: + json.dump(safe, f, indent=2) + except Exception: + with open(output_path, "w", encoding="utf-8") as f: + json.dump(safe, f, indent=2) + try: + os.chmod(output_path, 0o600) + except Exception: + pass + + print( + f"CI run completed. status={safe.get('status')} " + f"actions={[a.get('type') for a in safe.get('actions', [])]}" + ) + + if safe.get("status") == "error": + sys.exit(1) + + +if __name__ == "__main__": + main() diff --git a/scripts/ci/calculate_lag_index.py b/scripts/ci/calculate_lag_index.py new file mode 100755 index 00000000000..a78c70f599b --- /dev/null +++ b/scripts/ci/calculate_lag_index.py @@ -0,0 +1,256 @@ +#!/usr/bin/env python3 +import os +import sys +import json +import urllib.request +import urllib.error +from datetime import datetime + +# Define standard configurations as Single Source of Truth +COOLDOWN_CONFIGS = """# Lane Consolidation SSOT + +This document is the **Single Source of Truth** for coordination, timing quotas, GHA debounces, and cooldown configurations across the monorepo's agentic pipelines. + +## Active Quotas & Cooldown Configurations + +| Layer / Component | Configuration Parameter | Value / Throttle | Purpose / Detail | +|---|---|---|---| +| **`model_router.py`** | Daily Soft Budget | Saved in `/tmp/model-router` | Elevated limits, OpenRouter free polling, ELO rankings | +| **`peer-review-orchestrator.yml`** | Auto-Fix Throttle | **45 minutes** | Cooldown between `@coderabbitai autofix` requests | +| **`peer-review-orchestrator.yml`** | Settle Delay | **90 seconds** | Settle time after autofix request before posting ready marker | +| **`agent-review-auto-jules.yml`** | Idempotent Window | **20 minutes** | Debounce window on bot feedback to avoid redundant Jules summons | +| **`agent-continuous-ops.yml`** | Sweep Debounce | **90 minutes** (Dynamic) | Time to wait after continuous ops comment before re-pinging | +| **`agent-continuous-ops.yml`** | Stale Agent Activity | **3 hours** (Dynamic) | Max idle time since last agent activity before nudging | +| **`agent-continuous-ops.yml`** | Schedule Interval | **Every 1 hour** (`17 * * * *`) | Backup cron job frequency to jump start stuck PRs | +| **`agent-continuous-ops.yml`** | Sweep Capacity | **8 to 20 PRs** | Max PRs evaluated per sweep | +""" + +def github_api_request(url, token=None): + req = urllib.request.Request(url) + req.add_header("User-Agent", "Jules-Lag-Index-Calculator") + req.add_header("Accept", "application/vnd.github.v3+json") + if token: + req.add_header("Authorization", f"token {token}") + try: + with urllib.request.urlopen(req) as response: + return json.loads(response.read().decode("utf-8")) + except urllib.error.HTTPError as e: + print(f"API HTTP Error for {url}: {e.code} - {e.reason}", file=sys.stderr) + return None + except Exception as e: + print(f"API Error for {url}: {e}", file=sys.stderr) + return None + +def parse_iso8601(ts_str): + if not ts_str: + return None + try: + # standard ISO8601 like 2026-08-08T18:30:00Z + return datetime.strptime(ts_str.replace("Z", ""), "%Y-%m-%dT%H:%M:%S") + except ValueError: + return None + +def main(): + token = os.environ.get("OPERATOR_GITHUB_TOKEN") or os.environ.get("OPERATOR_TOKEN") or os.environ.get("GITHUB_TOKEN") + repo = os.environ.get("GITHUB_REPOSITORY") or "timerloggedout-spec/termux-monorepo" + + print(f"Running response time lag calculation for: {repo}") + + # Default fallbacks + default_debounce_sec = 90 * 60 # 90m + default_stale_sec = 3 * 60 * 60 # 3h + + metrics = { + "global_averages": { + "avg_message_response_lag_sec": default_debounce_sec, + "avg_actual_response_lag_sec": default_stale_sec, + "suggested_debounce_ms": default_debounce_sec * 1000, + "suggested_stale_ms": default_stale_sec * 1000 + }, + "by_pr": {} + } + + if not token: + print("Warning: GITHUB_TOKEN not provided. Generating standard lag index with fallback values.") + # Create directories if they don't exist + os.makedirs("docs/ops", exist_ok=True) + + # Write dummy/fallback files + with open("docs/ops/response_time_lag_index.json", "w") as f: + json.dump(metrics, f, indent=2) + + ssot_content = COOLDOWN_CONFIGS + "\n## Current Work & Dynamic Response Lags\n\n*Running locally/offline. Fallback defaults applied.*\n\n| PR/Issue | Message Response Lag | Programmatic Response Lag | Status |\n|---|---|---|---|\n| Default Fallback | 1.5 hours | 3.0 hours | Active |\n" + with open("docs/ops/LANE_CONSOLIDATION_SSOT.md", "w") as f: + f.write(ssot_content) + print("Fallback files written successfully.") + return + + # Fetch open PRs + print("Fetching open PRs...") + open_prs = github_api_request(f"https://api.github.com/repos/{repo}/pulls?state=open&per_page=30", token) or [] + print("Fetching closed PRs for historical data...") + closed_prs = github_api_request(f"https://api.github.com/repos/{repo}/pulls?state=closed&per_page=20", token) or [] + + all_prs = open_prs + closed_prs + print(f"Total PRs retrieved for analysis: {len(all_prs)}") + + all_message_lags = [] + all_actual_lags = [] + + pr_table_rows = [] + + for pr in all_prs: + pr_number = pr["number"] + pr_title = pr["title"] + pr_state = pr["state"] + print(f"Analyzing PR #{pr_number} - {pr_title}...") + + # Get comments + comments = github_api_request(f"https://api.github.com/repos/{repo}/issues/{pr_number}/comments?per_page=100", token) or [] + # Get commits + commits = github_api_request(f"https://api.github.com/repos/{repo}/pulls/{pr_number}/commits?per_page=100", token) or [] + + # Chronological timeline of everything + timeline = [] + for c in comments: + t = parse_iso8601(c["created_at"]) + if t: + timeline.append({ + "type": "comment", + "user": c["user"]["login"] if c.get("user") else "unknown", + "body": c.get("body") or "", + "time": t + }) + for commit in commits: + commit_meta = commit.get("commit", {}) + committer = commit_meta.get("committer", {}) or commit_meta.get("author", {}) or {} + t = parse_iso8601(committer.get("date")) + if t: + timeline.append({ + "type": "commit", + "user": commit_meta.get("author", {}).get("name") or "unknown", + "time": t + }) + + # Sort timeline chronologically + timeline.sort(key=lambda x: x["time"]) + + # Trace summon events + summon_time = None + message_response_time = None + actual_response_time = None + + pr_message_lags = [] + pr_actual_lags = [] + + agent_logins = [ + 'google-labs-jules', 'devin-ai-integration', 'coderabbitai', + 'github-actions', 'copilot', 'gitar-bot', 'blocksorg' + ] + + def is_agent(username): + u = (username or "").lower() + return any(agent in u for agent in agent_logins) + + for event in timeline: + if event["type"] == "comment": + body = event["body"] + # Is it a summon? + is_summon = any(marker in body for marker in ["", "", "@jules", "@gemini-cli"]) + if is_summon: + summon_time = event["time"] + message_response_time = None + actual_response_time = None + continue + + if summon_time: + # Look for first message response (bot acknowledgment) + if not message_response_time and is_agent(event["user"]): + message_response_time = event["time"] + lag = (message_response_time - summon_time).total_seconds() + pr_message_lags.append(lag) + all_message_lags.append(lag) + + elif event["type"] == "commit": + if summon_time and not actual_response_time: + # Look for first programmatic response (commit after summon) + actual_response_time = event["time"] + lag = (actual_response_time - summon_time).total_seconds() + pr_actual_lags.append(lag) + all_actual_lags.append(lag) + + # Calculate PR averages + pr_avg_msg = sum(pr_message_lags) / len(pr_message_lags) if pr_message_lags else None + pr_avg_act = sum(pr_actual_lags) / len(pr_actual_lags) if pr_actual_lags else None + + if pr_avg_msg is not None or pr_avg_act is not None: + # 1.5x multiplier for safe margins + suggested_debounce = max(30 * 60, (pr_avg_msg or default_debounce_sec) * 1.5) + suggested_stale = max(60 * 60, (pr_avg_act or default_stale_sec) * 1.5) + + metrics["by_pr"][str(pr_number)] = { + "avg_message_response_lag_sec": pr_avg_msg, + "avg_actual_response_lag_sec": pr_avg_act, + "suggested_debounce_ms": int(suggested_debounce * 1000), + "suggested_stale_ms": int(suggested_stale * 1000) + } + + msg_lag_str = f"{round(pr_avg_msg / 60, 1)} min" if pr_avg_msg else "N/A" + act_lag_str = f"{round(pr_avg_act / 3600, 1)} hrs" if pr_avg_act else "N/A" + pr_table_rows.append(f"| PR #{pr_number} | {msg_lag_str} | {act_lag_str} | {pr_state.upper()} |") + + # Compute global averages + if all_message_lags: + avg_msg = sum(all_message_lags) / len(all_message_lags) + metrics["global_averages"]["avg_message_response_lag_sec"] = avg_msg + metrics["global_averages"]["suggested_debounce_ms"] = int(max(30 * 60, avg_msg * 1.5) * 1000) + if all_actual_lags: + avg_act = sum(all_actual_lags) / len(all_actual_lags) + metrics["global_averages"]["avg_actual_response_lag_sec"] = avg_act + metrics["global_averages"]["suggested_stale_ms"] = int(max(60 * 60, avg_act * 1.5) * 1000) + + # Ensure dirs + os.makedirs("docs/ops", exist_ok=True) + + # Write JSON lag index + with open("docs/ops/response_time_lag_index.json", "w") as f: + json.dump(metrics, f, indent=2) + print("docs/ops/response_time_lag_index.json written successfully.") + + # Write Markdown SSOT + table_content = "\n## Current Work & Dynamic Response Lags\n\n" + if pr_table_rows: + table_content += "| PR/Issue | Message Response Lag (Acknowledge) | Programmatic Response Lag (Commit/Review) | State |\n|---|---|---|---|\n" + table_content += "\n".join(pr_table_rows) + "\n" + else: + table_content += "*No summon events/responses detected in recent history. Standard defaults applied.*\n" + + # Add historical averages + g_avg = metrics["global_averages"] + table_content += f"\n### Calculated Global Averages\n" + table_content += f"- **Average Message Acknowledgment Lag:** {round(g_avg['avg_message_response_lag_sec'] / 60, 1)} minutes\n" + table_content += f"- **Average Actual Programmatic Lag:** {round(g_avg['avg_actual_response_lag_sec'] / 3600, 1)} hours\n" + table_content += f"- **Dynamic Debounce Window:** {round(g_avg['suggested_debounce_ms'] / 60000, 1)} minutes\n" + table_content += f"- **Dynamic Stale Window:** {round(g_avg['suggested_stale_ms'] / 3600000, 1)} hours\n" + + # Add tracing of related issues + table_content += """ +### Monorepo Coordination Trace + +This lane consolidation integrates and coordinates with the following historical and active work items: + +- **Issue #118:** Context continuity (Session && Context Management) +- **Issue #109:** DeepSeek CI integration +- **Issue #112:** Executable workflow + ephemeral session policy +- **Issue #114:** Peer routing + web-wrapper opt-in +- **Issue #72:** Quota + session continuation foundations +- **PR #3:** Untrack historical session stores +""" + + ssot_content = COOLDOWN_CONFIGS + table_content + with open("docs/ops/LANE_CONSOLIDATION_SSOT.md", "w") as f: + f.write(ssot_content) + print("docs/ops/LANE_CONSOLIDATION_SSOT.md updated successfully.") + +if __name__ == "__main__": + main() diff --git a/tests/test_multi_ai_ci.py b/tests/test_multi_ai_ci.py new file mode 100644 index 00000000000..c469d6da152 --- /dev/null +++ b/tests/test_multi_ai_ci.py @@ -0,0 +1,130 @@ +import json +import os +import shutil +import sys +import tempfile +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent.parent / "multi-ai-cli")) + +from ci_mode import main, run_ci + + +def test_run_ci_offline_mock(monkeypatch): + temp_dir = tempfile.mkdtemp() + try: + import backends.deepseek as ds_mod + import subprocess + + monkeypatch.setenv("DEEPSEEK_TOKEN", "test-model-token") + monkeypatch.setattr( + ds_mod.DeepSeekBackend, + "send_message", + lambda self, msg, context: "Mocked Code Review: LGTM!", + ) + monkeypatch.setattr( + ds_mod.DeepSeekBackend, + "__init__", + lambda self, session_manager: None, + ) + monkeypatch.setattr( + subprocess, + "check_output", + lambda *a, **k: "diff --git a/x b/x\n+hello", + ) + monkeypatch.setattr( + subprocess, + "run", + lambda *a, **k: type("R", (), {"returncode": 0})(), + ) + + event_data = { + "action": "synchronize", + "pull_request": {"number": 137}, + "repository": {"full_name": "test/repo"}, + } + result = run_ci( + event=event_data, + workspace=temp_dir, + operator_token="test_token", + ) + + assert result is not None + assert result["provider_used"] == "deepseek" + assert result["status"] == "ok" + assert len(result["actions"]) == 1 + assert result["actions"][0]["type"] == "pr_review" + assert result["actions"][0].get("posted") is True + finally: + shutil.rmtree(temp_dir) + + +def test_ci_output_permissions(monkeypatch): + temp_dir = tempfile.mkdtemp() + try: + cache_dir = Path(temp_dir) / "cache" + event_path = Path(temp_dir) / "event.json" + event_data = { + "action": "opened", + "pull_request": {"number": 137}, + "repository": {"full_name": "test/repo"}, + } + with open(event_path, "w", encoding="utf-8") as f: + json.dump(event_data, f) + + monkeypatch.setenv("GITHUB_EVENT_PATH", str(event_path)) + monkeypatch.setenv("OPERATOR_TOKEN", "test_token") + monkeypatch.setenv("DEEPSEEK_TOKEN", "test-model-token") + + import backends.deepseek as ds_mod + import subprocess + + monkeypatch.setattr( + ds_mod.DeepSeekBackend, + "__init__", + lambda self, session_manager: None, + ) + monkeypatch.setattr( + ds_mod.DeepSeekBackend, + "send_message", + lambda self, msg, ctx: "Mocked output!", + ) + monkeypatch.setattr( + subprocess, + "check_output", + lambda *a, **k: "diff", + ) + monkeypatch.setattr( + subprocess, + "run", + lambda *a, **k: type("R", (), {"returncode": 0})(), + ) + monkeypatch.setattr( + sys, + "argv", + [ + "ci_mode.py", + "--workspace", + temp_dir, + "--cache-dir", + str(cache_dir), + ], + ) + + original_cwd = os.getcwd() + os.chdir(temp_dir) + try: + main() + assert cache_dir.exists() + assert (os.stat(cache_dir).st_mode & 0o777) == 0o700 + output_file = Path("deepseek_output.json") + assert output_file.exists() + assert (os.stat(output_file).st_mode & 0o777) == 0o600 + data = json.loads(output_file.read_text(encoding="utf-8")) + # Metadata only — no model body + assert "Mocked" not in json.dumps(data) + assert data.get("status") == "ok" + finally: + os.chdir(original_cwd) + finally: + shutil.rmtree(temp_dir)