Skip to content

Commit 2350240

Browse files
committed
Decouple security gate from pipeline, fix clang-format-20 and Linux agent detection
Workflow: - Split _lint.yml (cppcheck + clang-format) from _security.yml (security-static + codeql-gate) - Dry Run: security runs as independent island, not blocking lint → test → build → smoke/soak - Release: security only blocks final verify step Fixes: - pass_semantic_edges.c: typedef hyperplane_row_t avoids function-returning- array-pointer syntax that clang-format-20 rejects - cli.c: Linux agent detection uses home_dir-relative .config/ paths instead of cbm_app_config_dir() which ignores the test home_dir
1 parent 894c04f commit 2350240

File tree

6 files changed

+116
-98
lines changed

6 files changed

+116
-98
lines changed

.github/workflows/_lint.yml

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Reusable: lint + security-static + codeql-gate
1+
# Reusable: lint only (cppcheck + clang-format).
2+
# Security-static and CodeQL gate are separate — see _security.yml.
23
name: Lint & Security
34

45
on:
@@ -43,60 +44,3 @@ jobs:
4344

4445
- name: Lint (cppcheck + clang-format, no clang-tidy — enforced locally)
4546
run: scripts/lint.sh --ci CLANG_FORMAT=clang-format-20
46-
47-
security-static:
48-
runs-on: ubuntu-latest
49-
timeout-minutes: 5
50-
steps:
51-
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
52-
- name: "Layer 1: Static allow-list audit"
53-
run: scripts/security-audit.sh
54-
- name: "Layer 6: UI security audit"
55-
run: scripts/security-ui.sh
56-
- name: "Layer 8: Vendored dependency integrity"
57-
run: scripts/security-vendored.sh
58-
59-
codeql-gate:
60-
runs-on: ubuntu-latest
61-
timeout-minutes: 50
62-
steps:
63-
- name: Wait for CodeQL on current commit (max 45 min)
64-
env:
65-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66-
run: |
67-
CURRENT_SHA="${{ github.sha }}"
68-
echo "Waiting for CodeQL to complete on $CURRENT_SHA..."
69-
for attempt in $(seq 1 90); do
70-
LATEST=$(gh api repos/${{ github.repository }}/actions/workflows/codeql.yml/runs?per_page=5 \
71-
--jq '.workflow_runs[] | select(.head_sha == "'"$CURRENT_SHA"'") | "\(.conclusion) \(.status)"' 2>/dev/null | head -1 || echo "")
72-
if [ -z "$LATEST" ]; then
73-
echo " $attempt/90: no run yet..."; sleep 30; continue
74-
fi
75-
CONCLUSION=$(echo "$LATEST" | cut -d' ' -f1)
76-
STATUS=$(echo "$LATEST" | cut -d' ' -f2)
77-
if [ "$STATUS" = "completed" ] && [ "$CONCLUSION" = "success" ]; then
78-
echo "=== CodeQL passed ==="; exit 0
79-
elif [ "$STATUS" = "completed" ]; then
80-
echo "BLOCKED: CodeQL $CONCLUSION"; exit 1
81-
fi
82-
echo " $attempt/90: $STATUS..."; sleep 30
83-
done
84-
echo "BLOCKED: CodeQL timeout"; exit 1
85-
86-
- name: Check for open code scanning alerts
87-
env:
88-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
89-
run: |
90-
echo "Waiting 60s for alert API to settle..."
91-
sleep 60
92-
ALERTS=$(gh api 'repos/${{ github.repository }}/code-scanning/alerts?state=open' --jq 'length' 2>/dev/null || echo "0")
93-
sleep 15
94-
ALERTS2=$(gh api 'repos/${{ github.repository }}/code-scanning/alerts?state=open' --jq 'length' 2>/dev/null || echo "0")
95-
[ "$ALERTS" -lt "$ALERTS2" ] && ALERTS=$ALERTS2
96-
if [ "$ALERTS" -gt 0 ]; then
97-
echo "BLOCKED: $ALERTS open alert(s)"
98-
gh api 'repos/${{ github.repository }}/code-scanning/alerts?state=open' \
99-
--jq '.[] | " #\(.number) [\(.rule.security_severity_level // .rule.severity)] \(.rule.id) — \(.most_recent_instance.location.path):\(.most_recent_instance.location.start_line)"' 2>/dev/null || true
100-
exit 1
101-
fi
102-
echo "=== CodeQL gate passed (0 alerts) ==="

.github/workflows/_security.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Reusable: security-static + CodeQL gate.
2+
# Runs independently from lint/test/build — does not block the main pipeline.
3+
# Affects overall workflow success status.
4+
name: Security Gate
5+
6+
on:
7+
workflow_call: {}
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
security-static:
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 5
16+
steps:
17+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
18+
- name: "Layer 1: Static allow-list audit"
19+
run: scripts/security-audit.sh
20+
- name: "Layer 6: UI security audit"
21+
run: scripts/security-ui.sh
22+
- name: "Layer 8: Vendored dependency integrity"
23+
run: scripts/security-vendored.sh
24+
25+
codeql-gate:
26+
runs-on: ubuntu-latest
27+
timeout-minutes: 50
28+
steps:
29+
- name: Wait for CodeQL on current commit (max 45 min)
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: |
33+
CURRENT_SHA="${{ github.sha }}"
34+
echo "Waiting for CodeQL to complete on $CURRENT_SHA..."
35+
for attempt in $(seq 1 90); do
36+
LATEST=$(gh api repos/${{ github.repository }}/actions/workflows/codeql.yml/runs?per_page=5 \
37+
--jq '.workflow_runs[] | select(.head_sha == "'"$CURRENT_SHA"'") | "\(.conclusion) \(.status)"' 2>/dev/null | head -1 || echo "")
38+
if [ -z "$LATEST" ]; then
39+
echo " $attempt/90: no run yet..."; sleep 30; continue
40+
fi
41+
CONCLUSION=$(echo "$LATEST" | cut -d' ' -f1)
42+
STATUS=$(echo "$LATEST" | cut -d' ' -f2)
43+
if [ "$STATUS" = "completed" ] && [ "$CONCLUSION" = "success" ]; then
44+
echo "=== CodeQL passed ==="; exit 0
45+
elif [ "$STATUS" = "completed" ]; then
46+
echo "BLOCKED: CodeQL $CONCLUSION"; exit 1
47+
fi
48+
echo " $attempt/90: $STATUS..."; sleep 30
49+
done
50+
echo "BLOCKED: CodeQL timeout"; exit 1
51+
52+
- name: Check for open code scanning alerts
53+
env:
54+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
55+
run: |
56+
echo "Waiting 60s for alert API to settle..."
57+
sleep 60
58+
ALERTS=$(gh api 'repos/${{ github.repository }}/code-scanning/alerts?state=open' --jq 'length' 2>/dev/null || echo "0")
59+
sleep 15
60+
ALERTS2=$(gh api 'repos/${{ github.repository }}/code-scanning/alerts?state=open' --jq 'length' 2>/dev/null || echo "0")
61+
[ "$ALERTS" -lt "$ALERTS2" ] && ALERTS=$ALERTS2
62+
if [ "$ALERTS" -gt 0 ]; then
63+
echo "BLOCKED: $ALERTS open alert(s)"
64+
gh api 'repos/${{ github.repository }}/code-scanning/alerts?state=open' \
65+
--jq '.[] | " #\(.number) [\(.rule.security_severity_level // .rule.severity)] \(.rule.id) — \(.most_recent_instance.location.path):\(.most_recent_instance.location.start_line)"' 2>/dev/null || true
66+
exit 1
67+
fi
68+
echo "=== CodeQL gate passed (0 alerts) ==="

.github/workflows/dry-run.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
# Manual trigger: test everything before pushing a release.
22
# Each step can be skipped for faster iteration.
3+
#
4+
# Pipeline: lint → test → build → smoke/soak (sequential chain)
5+
# Security: security-static + codeql-gate (independent island)
6+
#
7+
# Security does NOT block lint/test/build/smoke/soak. All jobs must pass
8+
# for the overall workflow to be green.
39
name: Dry Run
410

511
on:
612
workflow_dispatch:
713
inputs:
814
skip_lint:
9-
description: 'Skip lint + security + CodeQL'
15+
description: 'Skip lint (cppcheck + clang-format)'
1016
type: boolean
1117
default: false
1218
skip_tests:
@@ -27,33 +33,37 @@ permissions:
2733
contents: read
2834

2935
jobs:
30-
# ── Lint + Security ──────────────────────────────────────────
36+
# ── Security (independent island — does not block main pipeline) ──
37+
security:
38+
uses: ./.github/workflows/_security.yml
39+
secrets: inherit
40+
41+
# ── Lint (cppcheck + clang-format) ────────────────────────────
3142
lint:
3243
if: ${{ inputs.skip_lint != true }}
3344
uses: ./.github/workflows/_lint.yml
34-
secrets: inherit
3545

36-
# ── Tests (all platforms, perf tests skipped on CI) ──────────
46+
# ── Tests (all platforms, perf tests skipped on CI) ────────────
3747
test:
3848
needs: [lint]
3949
if: ${{ inputs.skip_tests != true && !cancelled() && (needs.lint.result == 'success' || needs.lint.result == 'skipped') }}
4050
uses: ./.github/workflows/_test.yml
4151
with:
4252
skip_perf: true
4353

44-
# ── Build all platforms ──────────────────────────────────────
54+
# ── Build all platforms ────────────────────────────────────────
4555
build:
4656
if: ${{ inputs.skip_builds != true && !cancelled() && (needs.test.result == 'success' || needs.test.result == 'skipped') }}
4757
needs: [test]
4858
uses: ./.github/workflows/_build.yml
4959

50-
# ── Smoke test every binary ─────────────────────────────────
60+
# ── Smoke test every binary ────────────────────────────────────
5161
smoke:
5262
if: ${{ inputs.skip_builds != true && !cancelled() && needs.build.result == 'success' }}
5363
needs: [build]
5464
uses: ./.github/workflows/_smoke.yml
5565

56-
# ── Soak tests (optional, parallel with smoke) ──────────────
66+
# ── Soak tests (optional, parallel with smoke) ────────────────
5767
soak:
5868
if: ${{ inputs.soak_level != 'none' && !cancelled() && needs.build.result == 'success' }}
5969
needs: [build]

.github/workflows/release.yml

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
# Release pipeline: lint → test → build → smoke → soak → draft → verify → publish
1+
# Release pipeline: lint → test → build → smoke/soak → draft → verify → publish
2+
#
3+
# Security (security-static + codeql-gate) starts immediately and runs in
4+
# parallel with lint/test/build/smoke/soak. It only blocks the final verify
5+
# step — everything else proceeds independently.
26
name: Release
37

48
on:
@@ -27,31 +31,35 @@ permissions:
2731
contents: read
2832

2933
jobs:
30-
# ── 1. Lint + Security + CodeQL ────────────────────────────────
34+
# ── Security (starts immediately, blocks only verify) ───────────
35+
security:
36+
uses: ./.github/workflows/_security.yml
37+
secrets: inherit
38+
39+
# ── 1. Lint (cppcheck + clang-format) ───────────────────────────
3140
lint:
3241
uses: ./.github/workflows/_lint.yml
33-
secrets: inherit
3442

35-
# ── 2. Tests (all platforms, full suite for release) ───────────
43+
# ── 2. Tests (all platforms, full suite for release) ───────────
3644
test:
3745
needs: [lint]
3846
uses: ./.github/workflows/_test.yml
3947
with:
4048
skip_perf: false
4149

42-
# ── 3. Build all platforms ─────────────────────────────────────
50+
# ── 3. Build all platforms ─────────────────────────────────────
4351
build:
4452
needs: [test]
4553
uses: ./.github/workflows/_build.yml
4654
with:
4755
version: ${{ inputs.version }}
4856

49-
# ── 4. Smoke test every binary ─────────────────────────────────
57+
# ── 4. Smoke test every binary ─────────────────────────────────
5058
smoke:
5159
needs: [build]
5260
uses: ./.github/workflows/_smoke.yml
5361

54-
# ── 5. Soak tests ─────────────────────────────────────────────
62+
# ── 5. Soak tests ─────────────────────────────────────────────
5563
soak:
5664
if: ${{ inputs.soak_level != 'none' }}
5765
needs: [build]
@@ -61,9 +69,9 @@ jobs:
6169
run_asan: ${{ inputs.soak_level == 'full' }}
6270
version: ${{ inputs.version }}
6371

64-
# ── 6. Create DRAFT release ───────────────────────────────────
72+
# ── 6. Create DRAFT release ───────────────────────────────────
6573
release-draft:
66-
needs: [smoke, soak, lint]
74+
needs: [smoke, soak]
6775
if: ${{ !cancelled() && !failure() }}
6876
runs-on: ubuntu-latest
6977
permissions:
@@ -157,9 +165,9 @@ jobs:
157165
body: ${{ inputs.release_notes || '' }}
158166
generate_release_notes: ${{ inputs.release_notes == '' }}
159167

160-
# ── 7. Verify + Publish ────────────────────────────────────────
168+
# ── 7. Verify + Publish (requires security gate) ───────────────
161169
verify:
162-
needs: [release-draft]
170+
needs: [release-draft, security]
163171
runs-on: ubuntu-latest
164172
permissions:
165173
contents: write

src/cli/cli.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -997,12 +997,7 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir) {
997997
}
998998
}
999999
#else
1000-
{
1001-
const char *zed_cfg = cbm_app_config_dir();
1002-
if (zed_cfg) {
1003-
snprintf(path, sizeof(path), "%s/zed", zed_cfg);
1004-
}
1005-
}
1000+
snprintf(path, sizeof(path), "%s/.config/zed", home_dir);
10061001
#endif
10071002
agents.zed = dir_exists(path);
10081003

@@ -1020,24 +1015,14 @@ cbm_detected_agents_t cbm_detect_agents(const char *home_dir) {
10201015
snprintf(path, sizeof(path),
10211016
"%s/Library/Application Support/Code/User/globalStorage/kilocode.kilo-code", home_dir);
10221017
#else
1023-
{
1024-
const char *kc_cfg = cbm_app_config_dir();
1025-
if (kc_cfg) {
1026-
snprintf(path, sizeof(path), "%s/Code/User/globalStorage/kilocode.kilo-code", kc_cfg);
1027-
}
1028-
}
1018+
snprintf(path, sizeof(path), "%s/.config/Code/User/globalStorage/kilocode.kilo-code", home_dir);
10291019
#endif
10301020
agents.kilocode = dir_exists(path);
10311021

10321022
#ifdef __APPLE__
10331023
snprintf(path, sizeof(path), "%s/Library/Application Support/Code/User", home_dir);
10341024
#else
1035-
{
1036-
const char *vs_cfg = cbm_app_config_dir();
1037-
if (vs_cfg) {
1038-
snprintf(path, sizeof(path), "%s/Code/User", vs_cfg);
1039-
}
1040-
}
1025+
snprintf(path, sizeof(path), "%s/.config/Code/User", home_dir);
10411026
#endif
10421027
agents.vscode = dir_exists(path);
10431028

src/pipeline/pass_semantic_edges.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,13 @@ enum {
657657
SEM_MAX_CANDIDATES = 200,
658658
};
659659

660+
/* Row of a hyperplane matrix: float[CBM_SEM_DIM]. */
661+
typedef float hyperplane_row_t[CBM_SEM_DIM];
662+
660663
typedef struct {
661664
cbm_sem_func_t *funcs;
662665
uint64_t *signatures;
663-
float (*hyperplanes)[CBM_SEM_DIM];
666+
hyperplane_row_t *hyperplanes;
664667
int func_count;
665668
_Atomic int next_idx;
666669
} sig_build_ctx_t;
@@ -975,8 +978,8 @@ static void phase3c_export_token_vectors(cbm_gbuf_t *gbuf, cbm_sem_corpus_t *cor
975978

976979
/* Phase 5a: generate NUM_HYPERPLANES × CBM_SEM_DIM deterministic random
977980
* float hyperplanes seeded from XXH3 so signatures are reproducible. */
978-
static float (*phase5a_build_hyperplanes(void)) [CBM_SEM_DIM] {
979-
float (*hyperplanes)[CBM_SEM_DIM] = malloc(sizeof(float[NUM_HYPERPLANES][CBM_SEM_DIM]));
981+
static hyperplane_row_t *phase5a_build_hyperplanes(void) {
982+
hyperplane_row_t *hyperplanes = malloc(sizeof(hyperplane_row_t) * NUM_HYPERPLANES);
980983
if (!hyperplanes) {
981984
return NULL;
982985
}
@@ -1058,7 +1061,7 @@ static void phase4_build_and_store_vectors(cbm_gbuf_t *gbuf, cbm_sem_func_t *fun
10581061
* caller frees both. */
10591062
static void phase5_lsh_build(cbm_sem_func_t *funcs, int func_count, int worker_count,
10601063
uint64_t **out_signatures, sem_bucket_t ***out_buckets) {
1061-
float (*hyperplanes)[CBM_SEM_DIM] = phase5a_build_hyperplanes();
1064+
hyperplane_row_t *hyperplanes = phase5a_build_hyperplanes();
10621065
uint64_t *signatures = calloc((size_t)func_count, sizeof(uint64_t));
10631066
if (hyperplanes && signatures) {
10641067
sig_build_ctx_t sc = {

0 commit comments

Comments
 (0)