@jenga-ai/agent 1.3.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +97 -92
  2. package/agents/developer.md +9 -8
  3. package/agents/scrum-master.md +57 -23
  4. package/agents/tester.md +51 -5
  5. package/hooks/on_session_end.sh +13 -1
  6. package/lib/generate-agent-context.js +18 -1
  7. package/lib/generate-copilot-instructions.js +18 -1
  8. package/lib/generate-skill-allow-list.js +191 -0
  9. package/lib/skill-allow-list.json +43 -0
  10. package/package.json +18 -4
  11. package/scripts/apply-j-prefix.sh +230 -0
  12. package/scripts/consume-context-digest.sh +103 -0
  13. package/scripts/postinstall.js +25 -0
  14. package/scripts/sweep-stale-context-digests.sh +132 -0
  15. package/scripts/validate-board.sh +5 -0
  16. package/scripts/write-context-digest.sh +230 -0
  17. package/skills/brainstorm/SKILL.md +1 -1
  18. package/skills/btw/SKILL.md +1 -1
  19. package/skills/clearify/SKILL.md +1 -1
  20. package/skills/close-story/SKILL.md +78 -6
  21. package/skills/close-story/scripts/check-privatized.sh +345 -0
  22. package/skills/commit/SKILL.md +1 -1
  23. package/skills/continue/SKILL.md +1 -1
  24. package/skills/deep-dive/SKILL.md +1 -1
  25. package/skills/dev-done/SKILL.md +1 -1
  26. package/skills/distribute/SKILL.md +1 -1
  27. package/skills/do/SKILL.md +100 -10
  28. package/skills/doc/README.md +155 -0
  29. package/skills/doc/SKILL.md +43 -13
  30. package/skills/doc/authoring-notes.md +72 -0
  31. package/skills/doc/scripts/resolve_last_update.py +149 -0
  32. package/skills/doc-sync/SKILL.md +1 -1
  33. package/skills/dooo/SKILL.md +1 -1
  34. package/skills/error/SKILL.md +1 -1
  35. package/skills/evaluate/SKILL.md +1 -1
  36. package/skills/examplify/SKILL.md +1 -1
  37. package/skills/help/SKILL.md +1 -1
  38. package/skills/idea/SKILL.md +1 -1
  39. package/skills/improve/SKILL.md +1 -1
  40. package/skills/init/SKILL.md +1 -1
  41. package/skills/init/assets/scope-thresholds_template.json +3 -3
  42. package/skills/j-init/SKILL.md +168 -0
  43. package/skills/j-init/assets/.gitignore_template +15 -0
  44. package/skills/j-init/assets/PROJECT_SUMMARY_template.md +13 -0
  45. package/skills/j-init/assets/directory_structure.txt +14 -0
  46. package/skills/j-init/assets/scope-thresholds_template.json +7 -0
  47. package/skills/j-init/assets/strategy_stub_template.md +38 -0
  48. package/skills/j-init/assets/test-config_template.json +4 -0
  49. package/skills/j-init/assets/workflow_template.json +30 -0
  50. package/skills/j-init/scripts/apply-project-visibility.sh +176 -0
  51. package/skills/j-init/scripts/detect-existing-codebase.sh +166 -0
  52. package/skills/j-init/scripts/init.sh +116 -0
  53. package/skills/jbp/SKILL.md +1 -1
  54. package/skills/jenga/SKILL.md +1 -1
  55. package/skills/jenga/scripts/render-confirmation.sh +55 -18
  56. package/skills/jenga-permission-level/SKILL.md +1 -1
  57. package/skills/lgtm/SKILL.md +1 -1
  58. package/skills/pi-plan/SKILL.md +1 -1
  59. package/skills/proceed/SKILL.md +1 -1
  60. package/skills/publish/SKILL.md +1 -1
  61. package/skills/publish/adapters/npm-ci.md +26 -4
  62. package/skills/publish/scripts/npm_ci_pipeline.sh +21 -1
  63. package/skills/reconcile/SKILL.md +1 -1
  64. package/skills/reconcile-origin/SKILL.md +1 -1
  65. package/skills/redo/SKILL.md +1 -1
  66. package/skills/skillify/SKILL.md +1 -1
  67. package/skills/spinoff/SKILL.md +1 -1
  68. package/skills/status/SKILL.md +1 -1
  69. package/skills/todo/SKILL.md +40 -3
  70. package/skills/todo/scripts/add_trivial_task.sh +216 -0
  71. package/skills/todo/scripts/update_story_tasks.py +87 -0
  72. package/skills/uncharted/SKILL.md +1 -1
  73. package/skills/wtf/SKILL.md +1 -1
  74. package/templates/SCRUM_BOARD_SCHEMA.md +33 -2
  75. package/templates/agent-context.md.tpl +32 -9
  76. package/templates/copilot-instructions.md.tpl +25 -8
@@ -0,0 +1,168 @@
1
+ ---
2
+ name: j:j-init
3
+ description: Polyfill alias of the init skill under a collision-safe directory name. Identical behavior to /init — initializes a new project with the standard directory structure, PROJECT_SUMMARY.md, workflow.json, git repo, and gitignore. Use when the built-in "/init" command (e.g. GH Copilot's own init) shadows Jenga's /init alias.
4
+ keywords:
5
+ - init
6
+ - initialize
7
+ - setup
8
+ - new project
9
+ - scaffold
10
+ - j-init
11
+ - polyfill
12
+ examples:
13
+ - "initialize a new project"
14
+ - "set up a new workspace"
15
+ - "j-init"
16
+ ---
17
+
18
+ # J-Init — Project Setup (polyfill alias of Init)
19
+
20
+ This skill is a literal-directory-name duplicate of `skills/init/`. It exists because
21
+ some host tools/harnesses (e.g. GH Copilot) ship their own built-in command literally
22
+ named `/init`, which can shadow or override Jenga AI's own `/init` alias (Claude Code's
23
+ native skill resolution is a literal-string, directory-name-based match — see
24
+ `docs/skill-authoring.md`'s "Invocation Convention"). `/j-init` (and `j:j-init`) give
25
+ users a guaranteed-unshadowed way to reach the exact same setup flow.
26
+
27
+ Keep this file's instructions in lockstep with `skills/init/SKILL.md` — any change made
28
+ there should be mirrored here.
29
+
30
+ ## Instructions
31
+
32
+ Follow these steps in order. Do not skip steps — the sequence matters.
33
+
34
+ ### 1. Detect existing project state
35
+
36
+ Before asking anything or scaffolding anything, classify the target directory
37
+ (the current directory) by running the detection script:
38
+
39
+ ```bash
40
+ skills/j-init/scripts/detect-existing-codebase.sh .
41
+ ```
42
+
43
+ It prints exactly one verdict on stdout:
44
+
45
+ | Verdict | Meaning | What to do |
46
+ |---|---|---|
47
+ | `empty` | The directory is empty, or contains only `.git`, `.gitignore`, and top-level `README*`/`LICENSE*` boilerplate. | Proceed to step 2 — behaviour here is unchanged from before this detection step existed. |
48
+ | `already-scaffolded` | `project/board/`, `project/PROJECT_SUMMARY.md`, or `project/configs/workflow.json` already exists. | Tell the user this directory already has a Jenga scaffold and **stop** — do not run the scaffold script. Re-running it would silently overwrite `PROJECT_SUMMARY.md` and `workflow.json` with fresh stubs. Point them at `/continue` or `/status` instead. |
49
+ | `existing-codebase` | The directory has real content (source, configs, docs beyond the boilerplate list) and is not already scaffolded. | **Pause. Do not scaffold.** Present the choice below and wait for an answer. |
50
+
51
+ On `existing-codebase`, present this choice verbatim, per the Interaction Pattern in
52
+ `CLAUDE.md` (numbered, free-text last):
53
+
54
+ This directory already contains code that wasn't built through Jenga. How would
55
+ you like to proceed?
56
+ 1. Run /uncharted onboard first, to analyze the existing code and backfill the
57
+ board before scaffolding
58
+ 2. Scaffold fresh anyway, leaving the board empty (the existing code is never
59
+ modified either way — onboard mode and fresh scaffolding are both board-only)
60
+ 3. Abort — don't scaffold, don't run /uncharted
61
+ 4. Other (describe below)
62
+
63
+ - **Option 1** — invoke `/uncharted onboard`. It analyzes the existing code and backfills
64
+ the board; it never modifies, moves, or restructures application code. Once it
65
+ finishes, the directory now has `project/PROJECT_SUMMARY.md` etc., so re-running this
66
+ detection step returns `already-scaffolded` — there is nothing left to scaffold.
67
+ - **Option 2** — continue to step 2 and scaffold fresh. Note in your response that the
68
+ board will start empty despite the directory containing pre-existing code, since the
69
+ user explicitly chose that.
70
+ - **Option 3** — stop here. Do not run the scaffold script and do not invoke `/uncharted`.
71
+ - **Option 4** — handle the free-text response on its own merits.
72
+
73
+ If the run is non-interactive (no user available to answer), default to **option 3
74
+ (abort)**. Unlike the visibility question in step 2, none of these three choices is a
75
+ no-op: running `/uncharted onboard` unattended commits an analysis pass the user never
76
+ asked for, and scaffolding fresh unattended silently discards pre-existing code from the
77
+ board exactly as `/init` did before this step existed. Aborting is the only choice that
78
+ changes nothing on disk, so it is the only safe default.
79
+
80
+ Never treat `existing-codebase` as if it were `empty`, and never skip straight to step 2
81
+ on that verdict without the user (or the non-interactive default) choosing to.
82
+
83
+ ### 2. Ask how Jenga AI's working files should appear
84
+
85
+ Ask the user this question, verbatim, before running any script:
86
+
87
+ How should Jenga AI's own working files (project/ — the scrum board, todo.md,
88
+ queue/, rapports/, and logs/) appear in this project?
89
+ 1. Visible — keep them at `project/`, tracked and visible in directory listings
90
+ 2. Ignored — keep them at `project/` but add them to `.gitignore` so they are never committed
91
+ 3. Not sure — explain the trade-offs and ask me again
92
+
93
+ If the user picks option 3, explain the trade-offs and re-ask. Do not proceed until
94
+ the answer is one of `visible` or `ignored`.
95
+
96
+ If the run is non-interactive (no user available to answer), use the default:
97
+ **`visible`**. It is the only choice that changes nothing on disk, so an unattended
98
+ run can never silently relocate directories or edit `.gitignore`.
99
+
100
+ > A third mode, `hidden` (dot-prefixing `project/` to `.project/`, matching the
101
+ > `.agents/`/`.claude/` convention), was built and then withdrawn before release —
102
+ > testing found it left board resolution and session-end hooks writing to two
103
+ > different trees. It is not offered here. See
104
+ > `skills/distribute/CONFIG_SCHEMA.md` for the root-cause note and the tracked
105
+ > follow-up to reintroduce it once fixed.
106
+
107
+ Carry the chosen value into step 3. Do not apply it yourself — the script owns all
108
+ of the mechanical work.
109
+
110
+ ### 3. Run the scaffold script
111
+
112
+ `init.sh` is not guaranteed to live at a single fixed path: in a project that
113
+ installed Jenga via npm, it was mirrored to `.claude/skills/j-init/scripts/`
114
+ (Claude Code) and `.agents/skills/j-init/scripts/` (Copilot/other agents) by
115
+ `postinstall.js`, and neither of those exists yet in this framework's own
116
+ source checkout, where it lives at the bare `skills/j-init/scripts/` path
117
+ instead. This step runs before `CLAUDE.md`/`AGENTS.md` exist, so it cannot
118
+ rely on either file's routing instructions to resolve the path — it must
119
+ locate its own script directly. Execute the init script from the project
120
+ root, passing the choice from step 2:
121
+
122
+ ```bash
123
+ INIT_SCRIPT=""
124
+ for candidate in .claude/skills/j-init/scripts/init.sh .agents/skills/j-init/scripts/init.sh skills/j-init/scripts/init.sh; do
125
+ [[ -f "$candidate" ]] && { INIT_SCRIPT="$candidate"; break; }
126
+ done
127
+ if [[ -z "$INIT_SCRIPT" ]]; then
128
+ echo "Error: could not locate init.sh under .claude/skills/, .agents/skills/, or skills/" >&2
129
+ exit 1
130
+ fi
131
+ chmod +x "$INIT_SCRIPT" && "$INIT_SCRIPT" --visibility <visible|ignored>
132
+ ```
133
+
134
+ Omitting `--visibility` falls back to the `JENGA_PROJECT_FILES_VISIBILITY`
135
+ environment variable, then to `visible`.
136
+
137
+ This script handles all scaffolding in one step:
138
+ 1. Initializes the git repository
139
+ 2. Creates `.gitignore`
140
+ 3. Creates the full directory structure under `project/`
141
+ 4. Creates `project/PROJECT_SUMMARY.md` with placeholder content
142
+ 5. Creates `project/configs/workflow.json` with shared constants
143
+ 6. Creates `project/configs/test-config.json` stub
144
+ 7. Creates `project/configs/scope-thresholds.json` with default execution-scope thresholds (consumed by `/jenga` and `/do`, which halt if it's missing)
145
+ 8. Creates `project/data/baselines.json`
146
+ 9. Creates `project/logs/events.json`
147
+ 10. Creates `docs/STRATEGY.md` — a strategic brief stub intended for investors, partners, and the product team
148
+ 11. Creates `CHANGELOG.md` from the shared template — a running log of notable changes, seeded with an `[Unreleased]` section
149
+ 12. Applies the chosen visibility mode via `scripts/apply-project-visibility.sh`, which records it as `project_files_visibility` in `jenga.config.json` and performs any `.gitignore` change
150
+ 13. Stages and commits all files with the message `init: scaffold project structure and workflow config`
151
+
152
+ The visibility mode is validated before any scaffolding happens, so an invalid
153
+ value fails fast and leaves nothing behind. It is applied before the commit, so
154
+ the `.gitignore` entry is captured in the initial commit.
155
+
156
+ If the script fails, check that you are in the project root and that git and `jq`
157
+ are available.
158
+
159
+ See `skills/distribute/CONFIG_SCHEMA.md` for the full `project_files_visibility`
160
+ field reference.
161
+
162
+ ### 4. Prompt next step
163
+
164
+ Inform the user that setup is complete, and state which visibility mode was applied
165
+ and where the working files now live. Mention that `docs/STRATEGY.md` was created as
166
+ a strategic brief stub for investors, partners, and the product team — they can fill
167
+ it in now or return to it later. Suggest running `/pi-plan` to define project goals
168
+ and epics.
@@ -0,0 +1,15 @@
1
+ # macOS & Windows system files
2
+ .DS_Store
3
+ Thumbs.db
4
+ Desktop.ini
5
+
6
+ # Environment files
7
+ .env
8
+ .env.*
9
+ *.local
10
+
11
+ # Dependency directories
12
+ node_modules/
13
+ vendor/
14
+ .venv/
15
+ EOF
@@ -0,0 +1,13 @@
1
+ # Project Summary
2
+
3
+ ## Overview
4
+ _To be completed._
5
+
6
+ ## Architecture & Structure
7
+ _To be completed._
8
+
9
+ ## Epics
10
+ _To be completed via /pi-plan._
11
+
12
+ ## Conventions
13
+ _To be completed._
@@ -0,0 +1,14 @@
1
+ project/board/epics
2
+ project/board/stories
3
+ project/board/tasks
4
+ project/instructions
5
+ project/configs
6
+ project/data
7
+ project/queue
8
+ project/rapports/problems
9
+ project/rapports/analysis
10
+ project/logs
11
+ project/documentation
12
+ project/documentation/plans
13
+ project/documentation/summaries
14
+ project/documentation/examples
@@ -0,0 +1,7 @@
1
+ {
2
+ "threshold_version": 2,
3
+ "inline_max_files": 3,
4
+ "inline_max_lines": 75,
5
+ "story_max_files": 5,
6
+ "bundle_lock_ttl_minutes": 30
7
+ }
@@ -0,0 +1,38 @@
1
+ # Strategy
2
+
3
+ <!-- This document is intended for investors, strategic partners, and senior stakeholders.
4
+ Write in clear, confident language that conveys conviction and focus.
5
+ Avoid jargon. Prioritise substance over length. -->
6
+
7
+ ## Vision
8
+
9
+ <!-- Describe the long-term direction of this project over a 3–5 year horizon.
10
+ What change do you want to see in the world, and what role does this project play in bringing it about?
11
+ A strong vision statement is specific, ambitious, and grounded — it should be possible to hold yourself accountable to it. -->
12
+
13
+ ## Value Proposition
14
+
15
+ <!-- Articulate what makes this project uniquely valuable and to whom.
16
+ Answer: Why does this exist? Why now? Why this team?
17
+ Focus on the distinct advantage or insight that underpins the project — not features, but the underlying value delivered. -->
18
+
19
+ ## Scope
20
+
21
+ ### In Scope
22
+
23
+ <!-- List the capabilities, domains, or problem spaces this project actively addresses.
24
+ Be specific enough that a new stakeholder can quickly understand the boundaries of the work.
25
+ Use bullet points for readability. -->
26
+
27
+ ### Out of Scope
28
+
29
+ <!-- List what this project explicitly does not cover.
30
+ Revenue model, pricing strategy, and competitive analysis are intentionally excluded from this document —
31
+ they belong in separate artefacts and are out of scope here.
32
+ Use this section to prevent scope creep and set clear expectations with stakeholders. -->
33
+
34
+ ## Target Audience
35
+
36
+ <!-- Describe who this project is built for.
37
+ Include both the end users (who experiences the product) and the stakeholders (who evaluates or funds it).
38
+ Be specific: a well-defined audience sharpens every other section of this document. -->
@@ -0,0 +1,4 @@
1
+ {
2
+ "_note": "Run the tester agent to configure tools for this project.",
3
+ "tools": []
4
+ }
@@ -0,0 +1,30 @@
1
+ {
2
+ "statuses": ["Pending", "In Progress", "Passed", "Passed with remarks", "Failed", "Rejected", "Blocked"],
3
+ "rapport_types": ["conflict", "implementation_blocker", "security_concern", "test_failure", "analysis"],
4
+ "paths": {
5
+ "board": "project/board",
6
+ "epics": "project/board/epics",
7
+ "stories": "project/board/stories",
8
+ "tasks": "project/board/tasks",
9
+ "rapports_problems": "project/rapports/problems",
10
+ "rapports_analysis": "project/rapports/analysis",
11
+ "queue": "project/queue",
12
+ "scrum_triggers": "project/queue/scrum_triggers.jsonl",
13
+ "developer_triggers": "project/queue/developer_triggers.jsonl",
14
+ "tester_triggers": "project/queue/tester_triggers.jsonl",
15
+ "session_handoff": "project/queue/handoffs/",
16
+ "logs": "project/logs",
17
+ "data": "project/data",
18
+ "configs": "project/configs",
19
+ "documentation": "project/documentation",
20
+ "documentation_plans": "project/documentation/plans",
21
+ "documentation_summaries": "project/documentation/summaries"
22
+ },
23
+ "agents": ["developer", "tester", "scrum-master"],
24
+ "pipeline": [
25
+ {"step": 1, "agent": "scrum-master", "phase": "planning", "on_complete": "write planning_complete handoff → developer_triggers.jsonl"},
26
+ {"step": 2, "agent": "developer", "phase": "implementation", "on_complete": "write implementation_complete handoff → tester_triggers.jsonl"},
27
+ {"step": 3, "agent": "tester", "phase": "verification", "on_complete": "write test status handoff → scrum_triggers.jsonl (+ developer_triggers.jsonl if failed)"},
28
+ {"step": 4, "agent": "scrum-master", "phase": "rollup_review", "on_complete": "update board statuses, close epic/story if all done"}
29
+ ]
30
+ }
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # apply-project-visibility.sh — apply the `project_files_visibility` mode to a project.
4
+ #
5
+ # Usage:
6
+ # apply-project-visibility.sh <mode> [project_root]
7
+ # apply-project-visibility.sh --check-only <mode>
8
+ #
9
+ # Modes:
10
+ # visible Working files stay where they are. No-op on disk beyond the config write.
11
+ # ignored Working files are added to the project's .gitignore — present on disk,
12
+ # never committed.
13
+ #
14
+ # NOTE: A third mode, `hidden` (dot-prefixing project/ -> .project/), was
15
+ # implemented and then withdrawn before release. Testing found it functionally
16
+ # broken: scripts/board_resolver.sh hardcodes project/configs/workflow.json
17
+ # and never locates the rewritten path, and hooks/on_session_end.sh
18
+ # unconditionally recreates a shadow project/ tree on every session end,
19
+ # splitting runtime state across two trees. See
20
+ # project/rapports/problems/E31_S05_T01-hidden-mode-path-resolution-gaps.md
21
+ # for the full findings. Re-introducing `hidden` requires fixing both of
22
+ # those hardcoded paths first — tracked as a follow-up /todo item.
23
+ #
24
+ # Exit codes:
25
+ # 0 Success
26
+ # 1 Bad usage or missing prerequisite
27
+ # 2 Invalid mode (outside the two-value enum)
28
+ # 3 Filesystem apply failure
29
+ # 4 jenga.config.json write failure
30
+
31
+ # Do NOT use set -e globally — each step handles its own errors.
32
+ set -uo pipefail
33
+
34
+ info() { echo "[visibility] $*"; }
35
+ warn() { echo "[visibility] WARNING: $*"; }
36
+ err() { echo "[visibility] ERROR: $*" >&2; }
37
+
38
+ usage() {
39
+ echo "Usage: $(basename "$0") <visible|ignored> [project_root]" >&2
40
+ echo " $(basename "$0") --check-only <visible|ignored>" >&2
41
+ exit 1
42
+ }
43
+
44
+ # Every Jenga AI working file named in E31_S05 — the scrum board, todo.md,
45
+ # queue/, rapports/ and logs/ — nests under this single root, so one entry
46
+ # covers them all. `ignored` consumes this list.
47
+ JENGA_WORKING_PATHS=("project")
48
+
49
+ VALID_MODES="visible ignored"
50
+
51
+ validate_mode() {
52
+ local mode="$1"
53
+ for valid in $VALID_MODES; do
54
+ [ "$mode" = "$valid" ] && return 0
55
+ done
56
+ err "Invalid project_files_visibility value: '${mode}'"
57
+ err "Allowed values are: ${VALID_MODES// /, }"
58
+ exit 2
59
+ }
60
+
61
+ # ---------------------------------------------------------------------------
62
+ # Argument parsing
63
+ # ---------------------------------------------------------------------------
64
+
65
+ CHECK_ONLY=0
66
+ if [ "${1:-}" = "--check-only" ]; then
67
+ CHECK_ONLY=1
68
+ shift
69
+ fi
70
+
71
+ MODE="${1:-}"
72
+ [ -n "$MODE" ] || usage
73
+
74
+ validate_mode "$MODE"
75
+
76
+ if [ "$CHECK_ONLY" -eq 1 ]; then
77
+ info "Mode '$MODE' is valid."
78
+ exit 0
79
+ fi
80
+
81
+ PROJECT_ROOT="${2:-$PWD}"
82
+ if [ ! -d "$PROJECT_ROOT" ]; then
83
+ err "Project root does not exist: $PROJECT_ROOT"
84
+ exit 1
85
+ fi
86
+ cd "$PROJECT_ROOT" || { err "Cannot enter project root: $PROJECT_ROOT"; exit 1; }
87
+
88
+ if ! command -v jq >/dev/null 2>&1; then
89
+ err "jq is required to write jenga.config.json but was not found on PATH."
90
+ exit 1
91
+ fi
92
+
93
+ # ---------------------------------------------------------------------------
94
+ # ignored — append to .gitignore, without ever duplicating an entry
95
+ # ---------------------------------------------------------------------------
96
+
97
+ gitignore_append() {
98
+ local entry="$1"
99
+ local gitignore=".gitignore"
100
+
101
+ if [ -f "$gitignore" ] && grep -qxF -- "$entry" "$gitignore"; then
102
+ info "'$entry' already present in .gitignore — skipping."
103
+ return 0
104
+ fi
105
+
106
+ # Don't glue our entry onto a final line that lacks a newline.
107
+ if [ -s "$gitignore" ] && [ -n "$(tail -c 1 "$gitignore")" ]; then
108
+ printf '\n' >> "$gitignore"
109
+ fi
110
+
111
+ if ! printf '%s\n' "$entry" >> "$gitignore"; then
112
+ err "Failed to append '$entry' to .gitignore"
113
+ exit 3
114
+ fi
115
+ info "Added '$entry' to .gitignore"
116
+ }
117
+
118
+ # ---------------------------------------------------------------------------
119
+ # jenga.config.json — merge the field in, written atomically (temp + mv)
120
+ # ---------------------------------------------------------------------------
121
+
122
+ write_visibility_config() {
123
+ local mode="$1"
124
+ local config="jenga.config.json"
125
+ local tmp="${config}.tmp"
126
+ local existing='{}'
127
+
128
+ # /init normally runs before any /distribute, so the file usually does not
129
+ # exist yet. Merge rather than overwrite so other fields survive.
130
+ if [ -f "$config" ]; then
131
+ if ! jq empty "$config" 2>/dev/null; then
132
+ err "$config exists but contains malformed JSON — refusing to overwrite it."
133
+ exit 4
134
+ fi
135
+ existing="$(cat "$config")"
136
+ fi
137
+
138
+ local content
139
+ content="$(jq --arg v "$mode" '.project_files_visibility = $v' <<< "$existing")"
140
+ if [ -z "$content" ]; then
141
+ err "Failed to construct $config content."
142
+ exit 4
143
+ fi
144
+
145
+ if ! printf '%s\n' "$content" > "$tmp"; then
146
+ err "Failed to write temporary config file: $tmp"
147
+ exit 4
148
+ fi
149
+
150
+ if ! mv "$tmp" "$config"; then
151
+ err "Failed to atomically move $tmp to $config"
152
+ rm -f "$tmp"
153
+ exit 4
154
+ fi
155
+
156
+ info "Wrote project_files_visibility = \"$mode\" to $config"
157
+ }
158
+
159
+ # ---------------------------------------------------------------------------
160
+ # Apply
161
+ # ---------------------------------------------------------------------------
162
+
163
+ case "$MODE" in
164
+ visible)
165
+ info "Mode 'visible' — working files stay in place; nothing to change on disk."
166
+ ;;
167
+ ignored)
168
+ for path in "${JENGA_WORKING_PATHS[@]}"; do
169
+ gitignore_append "${path}/"
170
+ done
171
+ ;;
172
+ esac
173
+
174
+ write_visibility_config "$MODE"
175
+
176
+ info "Applied project_files_visibility '$MODE' to $PROJECT_ROOT"
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env bash
2
+ # ---------------------------------------------------------------------------
3
+ # skills/init/scripts/detect-existing-codebase.sh
4
+ #
5
+ # Deterministic front half of the /init "detect existing project state" step.
6
+ # /init currently always scaffolds as though the target directory were empty.
7
+ # That is wrong whenever a directory already carries a Jenga scaffold, or
8
+ # already carries substantial application code that predates Jenga entirely
9
+ # -- in the second case, scaffolding fresh produces an empty board and a stub
10
+ # PROJECT_SUMMARY.md that actively misrepresent the project.
11
+ #
12
+ # This script answers exactly one question -- "what kind of directory is
13
+ # this?" -- and nothing else. It never scaffolds, never prompts, never runs
14
+ # /uncharted, and never modifies anything on disk. Deciding what to DO with
15
+ # the verdict is agent judgement and lives in skills/init/SKILL.md.
16
+ #
17
+ # ---------------------------------------------------------------------------
18
+ # VERDICTS -- exactly one is printed on stdout, nothing else
19
+ # ---------------------------------------------------------------------------
20
+ # empty The target is empty, or contains only boilerplate
21
+ # that does not count as "there is a project here":
22
+ # .git (the directory itself, pruned entirely -- not
23
+ # merely excluded by name), .gitignore, and top-level
24
+ # README*/LICENSE*/LICENCE* files (case-insensitive),
25
+ # plus anything git itself reports as ignored. A repo
26
+ # containing only a README is empty for this purpose.
27
+ # already-scaffolded The target already carries a Jenga scaffold: any one
28
+ # of project/board/, project/PROJECT_SUMMARY.md, or
29
+ # project/configs/workflow.json is present. Checked
30
+ # BEFORE the emptiness scan, so a scaffolded project
31
+ # that also happens to look sparse is never misreported
32
+ # as "empty".
33
+ # existing-codebase The target has real content (source files, configs,
34
+ # docs beyond the boilerplate list above, etc.) and is
35
+ # not already Jenga-scaffolded. This is the case /init
36
+ # currently mishandles: scaffolding fresh here silently
37
+ # discards the fact that pre-existing code exists.
38
+ #
39
+ # ---------------------------------------------------------------------------
40
+ # NOTES ON GITIGNORE HANDLING
41
+ # ---------------------------------------------------------------------------
42
+ # /init runs this check BEFORE `git init` in the fresh-scaffold path, so the
43
+ # target directory is very often not a git work tree yet. Gitignore-based
44
+ # filtering is therefore best-effort: it only runs when the target already
45
+ # has a `.git` directory AND `git` is on PATH. A standalone `.gitignore` file
46
+ # with no repository behind it still counts as boilerplate via the name-based
47
+ # exclusion below -- it just cannot hide any OTHER file, because there is no
48
+ # git to ask "is this ignored".
49
+ #
50
+ # README/LICENSE exclusion applies to TOP-LEVEL entries only. A directory
51
+ # whose only content is a buried `docs/README.md` two levels down is real
52
+ # structure, not boilerplate, and must not be reported as empty.
53
+ #
54
+ # ---------------------------------------------------------------------------
55
+ # Usage
56
+ # ---------------------------------------------------------------------------
57
+ # detect-existing-codebase.sh [target-dir]
58
+ #
59
+ # target-dir Directory to classify. Default: current directory.
60
+ #
61
+ # Options:
62
+ # -h, --help Show this help and exit 0.
63
+ #
64
+ # Exit codes:
65
+ # 0 A verdict was printed on stdout.
66
+ # 1 Usage error (unknown option, more than one positional argument).
67
+ # 2 target-dir does not exist or is not a directory.
68
+ #
69
+ # Requires: bash, find. git is used opportunistically for gitignore
70
+ # filtering when the target is already a git work tree; its absence never
71
+ # causes a failure.
72
+ # ---------------------------------------------------------------------------
73
+
74
+ set -euo pipefail
75
+
76
+ SELF="$(basename "$0")"
77
+
78
+ usage() {
79
+ sed -n '/^# Usage$/,/^# Requires:/p' "$0" | sed -e 's/^# \{0,1\}//' -e '/^-\{10,\}$/d'
80
+ }
81
+
82
+ die_usage() {
83
+ printf '%s: error: %s\n' "$SELF" "$*" >&2
84
+ echo >&2
85
+ usage >&2
86
+ exit 1
87
+ }
88
+
89
+ TARGET_DIR="."
90
+ HAVE_TARGET=0
91
+
92
+ while [ "$#" -gt 0 ]; do
93
+ case "$1" in
94
+ -h|--help) usage; exit 0 ;;
95
+ --)
96
+ shift
97
+ [ "$#" -le 1 ] || die_usage "at most one target directory is allowed"
98
+ if [ "$#" -eq 1 ]; then TARGET_DIR="$1"; HAVE_TARGET=1; fi
99
+ shift $#
100
+ ;;
101
+ -*)
102
+ die_usage "unknown option \"$1\"" ;;
103
+ *)
104
+ [ "$HAVE_TARGET" -eq 0 ] || die_usage "at most one target directory is allowed (got \"$TARGET_DIR\" and \"$1\")"
105
+ TARGET_DIR="$1"; HAVE_TARGET=1; shift ;;
106
+ esac
107
+ done
108
+
109
+ [ -d "$TARGET_DIR" ] || { printf '%s: error: not a directory: %s\n' "$SELF" "$TARGET_DIR" >&2; exit 2; }
110
+
111
+ TARGET_DIR="$(cd -- "$TARGET_DIR" && pwd -P)"
112
+
113
+ # --- already-scaffolded: checked first, independent of emptiness -----------
114
+ if [ -d "$TARGET_DIR/project/board" ] \
115
+ || [ -f "$TARGET_DIR/project/PROJECT_SUMMARY.md" ] \
116
+ || [ -f "$TARGET_DIR/project/configs/workflow.json" ]; then
117
+ echo "already-scaffolded"
118
+ exit 0
119
+ fi
120
+
121
+ # --- enumerate candidate files, pruning .git entirely -----------------------
122
+ ALL_FILES=$(mktemp "${TMPDIR:-/tmp}/detect-existing-codebase.XXXXXX")
123
+ IGNORED_FILES=$(mktemp "${TMPDIR:-/tmp}/detect-existing-codebase-ignored.XXXXXX")
124
+ cleanup() { rm -f "$ALL_FILES" "$IGNORED_FILES"; }
125
+ trap cleanup EXIT
126
+
127
+ find "$TARGET_DIR" -path "$TARGET_DIR/.git" -prune -o -type f -print > "$ALL_FILES"
128
+
129
+ # --- best-effort gitignore filtering ----------------------------------------
130
+ : > "$IGNORED_FILES"
131
+ if [ -d "$TARGET_DIR/.git" ] && command -v git >/dev/null 2>&1; then
132
+ git -C "$TARGET_DIR" check-ignore --stdin < "$ALL_FILES" > "$IGNORED_FILES" 2>/dev/null || true
133
+ fi
134
+
135
+ # --- classify each candidate -------------------------------------------------
136
+ SOURCE_FOUND=0
137
+ while IFS= read -r f; do
138
+ [ -n "$f" ] || continue
139
+
140
+ if [ -s "$IGNORED_FILES" ] && grep -Fxq -- "$f" "$IGNORED_FILES"; then
141
+ continue
142
+ fi
143
+
144
+ rel="${f#"$TARGET_DIR"/}"
145
+ base="$(basename -- "$f")"
146
+ dir_rel="$(dirname -- "$rel")"
147
+
148
+ if [ "$dir_rel" = "." ]; then
149
+ if [ "$base" = ".gitignore" ]; then
150
+ continue
151
+ fi
152
+ base_upper="$(printf '%s' "$base" | tr '[:lower:]' '[:upper:]')"
153
+ case "$base_upper" in
154
+ README*|LICENSE*|LICENCE*) continue ;;
155
+ esac
156
+ fi
157
+
158
+ SOURCE_FOUND=1
159
+ break
160
+ done < "$ALL_FILES"
161
+
162
+ if [ "$SOURCE_FOUND" -eq 1 ]; then
163
+ echo "existing-codebase"
164
+ else
165
+ echo "empty"
166
+ fi