agentic-mobile-kit 0.7.12 → 0.7.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/doctor.js +8 -3
- package/lib/init.js +38 -11
- package/package.json +1 -1
- package/stacks/react-native/template/.rulesync/hooks.jsonc +5 -3
- package/stacks/react-native/template/scripts/amk/guard.js +4 -1
- package/stacks/react-native/template/scripts/amk/handoff-check.js +6 -3
- package/stacks/react-native/template/scripts/amk/run-hook.sh +9 -0
package/lib/doctor.js
CHANGED
|
@@ -4,7 +4,7 @@ const fs = require('fs');
|
|
|
4
4
|
const os = require('os');
|
|
5
5
|
const path = require('path');
|
|
6
6
|
const { spawnSync } = require('child_process');
|
|
7
|
-
const { tool, hookManager, hooksWired, checkProject, emptyFolder } = require('./init');
|
|
7
|
+
const { tool, hookManager, hooksWired, kitRun, ignoredByGit, checkProject, emptyFolder } = require('./init');
|
|
8
8
|
const screens = require('../stacks/react-native/template/scripts/amk/screens.js');
|
|
9
9
|
|
|
10
10
|
const RULESYNC = 'rulesync@27.0.0';
|
|
@@ -55,9 +55,10 @@ function projectChecks(cwd, opts) {
|
|
|
55
55
|
const hooksPath = run('git', ['config', 'core.hooksPath'], { cwd });
|
|
56
56
|
out.push(hooksPath === '.githooks'
|
|
57
57
|
? ok('Git hooks active')
|
|
58
|
-
|
|
58
|
+
// with .githooks kept out of git, install doesn't turn them on: sync does, as it puts the folder back
|
|
59
|
+
: fail('Git hooks not active on this clone', ignoredByGit(cwd, '.githooks/pre-commit') ? 'run: npx agentic-mobile-kit sync' : 'run: git config core.hooksPath .githooks (your package manager\'s install does this too)'));
|
|
59
60
|
} else if (manager.manual) {
|
|
60
|
-
out.push(warn(`Git hooks run from ${manager.name}, without the kit's checks`,
|
|
61
|
+
out.push(warn(`Git hooks run from ${manager.name}, without the kit's checks`, `add "${kitRun('pre-commit')}" and "${kitRun('pre-push')}" to those hooks`));
|
|
61
62
|
} else if (!hooksWired(cwd, manager)) {
|
|
62
63
|
out.push(fail(`The kit's checks aren't in your ${manager.name} hooks`, 'run: npx agentic-mobile-kit sync'));
|
|
63
64
|
} else {
|
|
@@ -68,6 +69,10 @@ function projectChecks(cwd, opts) {
|
|
|
68
69
|
: fail(`${manager.name} isn't set up on this clone, so no git hooks run`, 'run your package manager\'s install'));
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
// a team may keep .githooks out of git, so a fresh clone has none until it runs sync, and no kit checks run till then
|
|
73
|
+
const noHooks = ['pre-commit', 'pre-push'].filter(h => !fs.existsSync(path.join(cwd, '.githooks', h)));
|
|
74
|
+
if (noHooks.length) out.push(fail(`This clone has no ${noHooks.map(h => `.githooks/${h}`).join(' or ')}, so the kit's checks don't run`, 'run: npx agentic-mobile-kit sync'));
|
|
75
|
+
|
|
71
76
|
if (fs.existsSync(path.join(cwd, 'scripts/amk/case-check.js'))) {
|
|
72
77
|
const r = spawnSync(process.execPath, ['scripts/amk/case-check.js'], { cwd, encoding: 'utf8' });
|
|
73
78
|
const lines = (r.stderr || '').trim().split('\n');
|
package/lib/init.js
CHANGED
|
@@ -430,7 +430,12 @@ function merge3(current, base, kitNew, from) {
|
|
|
430
430
|
// two tools setting it undo each other on every install (husky's prepare script runs after the kit's postinstall).
|
|
431
431
|
const KIT_HOOKS = ['pre-commit', 'pre-push'];
|
|
432
432
|
const MARK = 'agentic-mobile-kit';
|
|
433
|
-
|
|
433
|
+
// the kit's command in a hook manager. A team may keep .githooks out of git, so a fresh clone has none until it runs
|
|
434
|
+
// sync: run-hook.sh then skips the hook with a hint, where a plain `sh .githooks/<hook>` failed every commit and push
|
|
435
|
+
const kitRun = h => `sh scripts/amk/run-hook.sh .githooks/${h}`;
|
|
436
|
+
// that plain command, which kits up to 0.7.12 added: sync upgrades it
|
|
437
|
+
const oldRun = h => new RegExp(`(^|[\\s"'])sh \\.githooks/${h}(?=$|[\\s"'])`, 'gm');
|
|
438
|
+
const hookCall = h => `${kitRun(h)}${h === 'pre-push' ? ' "$@"' : ''} || exit 1 # ${MARK}`;
|
|
434
439
|
// git's other client-side hooks. One another tool installed into .git/hooks (a time tracker's post-commit, say) stops
|
|
435
440
|
// running once core.hooksPath points at .githooks, so a .githooks file passes it on, in every clone that has one
|
|
436
441
|
const OTHER_HOOKS = ['applypatch-msg', 'pre-applypatch', 'post-applypatch', 'pre-merge-commit', 'prepare-commit-msg', 'commit-msg',
|
|
@@ -461,7 +466,11 @@ function hookManager(cwd, pkg) {
|
|
|
461
466
|
}
|
|
462
467
|
|
|
463
468
|
const hookFile = (m, h) => (m.dir ? `${m.dir}/${h}` : m.yaml);
|
|
464
|
-
|
|
469
|
+
// the kit's command, or the team's own call to the hook; not an earlier kit's plain one, which sync upgrades
|
|
470
|
+
const hooksWired = (cwd, m) => KIT_HOOKS.every(h => {
|
|
471
|
+
const text = m.json ? m.json[h] || '' : readIf(path.join(cwd, hookFile(m, h))) || '';
|
|
472
|
+
return text.includes(`.githooks/${h}`) && !oldRun(h).test(text);
|
|
473
|
+
});
|
|
465
474
|
|
|
466
475
|
// after the shebang, comments and husky's own setup line: a command after the team's `exit` would never run
|
|
467
476
|
function insertCall(text, line) {
|
|
@@ -474,7 +483,7 @@ function insertCall(text, line) {
|
|
|
474
483
|
|
|
475
484
|
// adds the kit's command to a lefthook hook (under its commands: or jobs:), or the hook itself; null if it can't tell where
|
|
476
485
|
function lefthookAdd(text, h) {
|
|
477
|
-
const run =
|
|
486
|
+
const run = kitRun(h);
|
|
478
487
|
const lines = text.replace(/\n+$/, '').split('\n');
|
|
479
488
|
const start = lines.findIndex(l => new RegExp(`^["']?${h}["']?\\s*:`).test(l));
|
|
480
489
|
if (start < 0) return `${lines.join('\n')}\n${h}: # ${MARK}\n commands: # ${MARK}\n ${MARK}:\n run: ${run}\n`;
|
|
@@ -500,24 +509,31 @@ function lefthookAdd(text, h) {
|
|
|
500
509
|
// runs the kit's hooks from the project's hook manager; true if package.json changed
|
|
501
510
|
function wireHooks(cwd, m, done) {
|
|
502
511
|
if (m.manual) {
|
|
503
|
-
done.warnings.push(`git hooks already run from ${m.name}, so the kit left core.hooksPath alone. To run the kit's checks too, add "
|
|
512
|
+
done.warnings.push(`git hooks already run from ${m.name}, so the kit left core.hooksPath alone. To run the kit's checks too, add "${kitRun('pre-commit')}" and "${kitRun('pre-push')}" to those hooks.`);
|
|
504
513
|
return false;
|
|
505
514
|
}
|
|
506
515
|
let pkgChanged = false;
|
|
507
516
|
for (const h of KIT_HOOKS) {
|
|
508
517
|
if (m.json) {
|
|
509
|
-
|
|
510
|
-
|
|
518
|
+
const v = m.json[h] || '';
|
|
519
|
+
if (oldRun(h).test(v)) m.json[h] = v.replace(oldRun(h), `$1${kitRun(h)}`);
|
|
520
|
+
else if (v.includes(`.githooks/${h}`)) continue;
|
|
521
|
+
else m.json[h] = v ? `${kitRun(h)} && ${v}` : kitRun(h);
|
|
511
522
|
pkgChanged = true;
|
|
512
523
|
continue;
|
|
513
524
|
}
|
|
514
525
|
const rel = hookFile(m, h);
|
|
515
526
|
const file = path.join(cwd, rel);
|
|
516
527
|
const text = readIf(file);
|
|
528
|
+
if (text !== null && oldRun(h).test(text)) {
|
|
529
|
+
fs.writeFileSync(file, text.replace(oldRun(h), `$1${kitRun(h)}`));
|
|
530
|
+
if (!done.merged.includes(rel)) done.merged.push(rel);
|
|
531
|
+
continue;
|
|
532
|
+
}
|
|
517
533
|
if ((text || '').includes(`.githooks/${h}`)) continue;
|
|
518
534
|
if (m.yaml) {
|
|
519
535
|
const next = lefthookAdd(text, h);
|
|
520
|
-
if (next === null) { done.warnings.push(`couldn't add the kit's ${h} check to ${rel}: add a command there that runs "
|
|
536
|
+
if (next === null) { done.warnings.push(`couldn't add the kit's ${h} check to ${rel}: add a command there that runs "${kitRun(h)}"`); continue; }
|
|
521
537
|
fs.writeFileSync(file, next);
|
|
522
538
|
if (!done.merged.includes(rel)) done.merged.push(rel);
|
|
523
539
|
continue;
|
|
@@ -539,8 +555,8 @@ function unwireHooks(cwd, m, report) {
|
|
|
539
555
|
for (const h of KIT_HOOKS) {
|
|
540
556
|
if (m.json) {
|
|
541
557
|
const before = m.json[h];
|
|
542
|
-
if (before === `sh .githooks/${h}`) delete m.json[h];
|
|
543
|
-
else if (before) m.json[h] = before.replace(`sh .githooks/${h} && `, '');
|
|
558
|
+
if (before === kitRun(h) || before === `sh .githooks/${h}`) delete m.json[h];
|
|
559
|
+
else if (before) m.json[h] = before.replace(`${kitRun(h)} && `, '').replace(`sh .githooks/${h} && `, '');
|
|
544
560
|
if (m.json[h] !== before) { pkgChanged = true; report.removed.push(`package.json ${m.name} ${h} (the kit's command)`); }
|
|
545
561
|
continue;
|
|
546
562
|
}
|
|
@@ -637,10 +653,19 @@ function finish(cwd, { pkg, deps, tools, files, stack, skipGenerate }) {
|
|
|
637
653
|
// only TypeScript projects get typecheck: tsc fails ("no inputs") in JavaScript apps that merely have typescript installed
|
|
638
654
|
if (!scripts.typecheck && deps.typescript && usesTs(cwd)) { scripts.typecheck = 'tsc --noEmit'; pkgChanged = true; }
|
|
639
655
|
const manager = hookManager(cwd, pkg);
|
|
656
|
+
// a team may keep .githooks out of git: a fresh clone has none until it runs sync, which also turns the hooks on
|
|
657
|
+
const keptOut = ignoredByGit(cwd, '.githooks/pre-commit');
|
|
640
658
|
if (manager) {
|
|
641
659
|
// the project's hook manager runs the kit's hooks; drop the postinstall earlier kit versions added, which fought it
|
|
642
660
|
if (dropHooksCmd(scripts)) pkgChanged = true;
|
|
643
661
|
if (wireHooks(cwd, manager, done)) pkgChanged = true;
|
|
662
|
+
if (!manager.manual && keptOut) {
|
|
663
|
+
done.warnings.push(`.githooks is kept out of git here, so a fresh clone has none until it runs npx agentic-mobile-kit sync. Until then, ${manager.name} skips the kit's checks and says so`);
|
|
664
|
+
}
|
|
665
|
+
} else if (keptOut) {
|
|
666
|
+
// pointing git at a folder a fresh clone doesn't have would switch off every hook there, other tools' too
|
|
667
|
+
if (dropHooksCmd(scripts)) pkgChanged = true;
|
|
668
|
+
done.warnings.push('.githooks is kept out of git here, so a fresh clone has none until it runs npx agentic-mobile-kit sync, which turns the kit\'s hooks on. Until then, git runs only the hooks in .git/hooks there');
|
|
644
669
|
} else if (!(scripts.postinstall || '').includes('core.hooksPath')) {
|
|
645
670
|
// parentheses keep the existing script's failure behavior: `a && b || true` would hide a failing `a`
|
|
646
671
|
scripts.postinstall = scripts.postinstall ? `${scripts.postinstall} && (${HOOKS_CMD})` : HOOKS_CMD;
|
|
@@ -781,7 +806,9 @@ function sync(cwd, opts = {}) {
|
|
|
781
806
|
continue;
|
|
782
807
|
}
|
|
783
808
|
if (current === null) {
|
|
784
|
-
|
|
809
|
+
// new in the kit, or kept out of git, so this clone doesn't have it yet (a team may keep .githooks out of git).
|
|
810
|
+
// Not rulesync.jsonc: it holds the team's choice of tools, which the kit's own copy doesn't know
|
|
811
|
+
if (kitOld === null || rel !== 'rulesync.jsonc' && ignoredByGit(cwd, rel)) { writeKitFile(cwd, rel, kitNew); report.added.push(rel); } else report.kept.push(`${rel} (you deleted it)`);
|
|
785
812
|
continue;
|
|
786
813
|
}
|
|
787
814
|
if (current === kitNew) continue;
|
|
@@ -939,5 +966,5 @@ function printUninstall({ report }, log = console.log) {
|
|
|
939
966
|
|
|
940
967
|
module.exports = {
|
|
941
968
|
init, sync, uninstall, printSummary, printSync, printUninstall, InitError, TOOLS, TESTED, CI, KIT_VERSION, tool, cleanEnv,
|
|
942
|
-
hookManager, hooksWired, checkProject, recorded, installedCi, emptyFolder, createApp,
|
|
969
|
+
hookManager, hooksWired, kitRun, ignoredByGit, checkProject, recorded, installedCi, emptyFolder, createApp,
|
|
943
970
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentic-mobile-kit",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.14",
|
|
4
4
|
"description": "One setup for AI-assisted development of React Native apps, bare or Expo: shared rules and workflows for Claude Code, Codex and Antigravity, git hooks, device checks with screenshots, and release tooling for the App Store and Google Play.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "prakashpro1",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 1,
|
|
3
3
|
"hooks": {
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// "./" lets rulesync anchor each command to the project folder for a tool that keeps the agent's cd between
|
|
5
|
+
// commands (Claude Code: "$CLAUDE_PROJECT_DIR"/scripts/...): a relative one isn't found after a cd into a
|
|
6
|
+
// subfolder, which turns the guard off. No matcher: runs for every tool call; guard.js decides from the payload
|
|
7
|
+
"preToolUse": [{ "command": "node ./scripts/amk/guard.js" }],
|
|
8
|
+
"stop": [{ "command": "node ./scripts/amk/handoff-check.js" }]
|
|
7
9
|
}
|
|
8
10
|
}
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Agent guard hook (preToolUse). Blocks destructive shell commands and access to secret files.
|
|
3
3
|
// Each AI tool sends a differently shaped JSON payload, so look for command and path fields anywhere in it.
|
|
4
4
|
const fs = require('fs');
|
|
5
|
+
const path = require('path');
|
|
6
|
+
// the project this script is in (scripts/amk/): the agent may have moved into a subfolder
|
|
7
|
+
const root = path.join(__dirname, '..', '..');
|
|
5
8
|
|
|
6
9
|
let payload;
|
|
7
10
|
const raw = fs.readFileSync(0, 'utf8');
|
|
@@ -28,7 +31,7 @@ const destructive = /\brm(?=[^;&|\n]*\s(-[a-zA-Z]*[rR][a-zA-Z]*|--recursive)\b)(
|
|
|
28
31
|
const secretFile = /(^|[\s/'"=])\.env(?![\w.-]*\.(?:example|sample|template)(?=$|[\s'";|&)]))(\.[\w.-]+)?(?=$|[\s'";|&)])|\.(keystore|jks|p8|p12|mobileprovision)\b/;
|
|
29
32
|
// the project's own secret files: .amk-secrets lists them, one path from the project root per line (a folder ends in /)
|
|
30
33
|
let listed = [];
|
|
31
|
-
try { listed = fs.readFileSync('.amk-secrets', 'utf8').split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#')); } catch {}
|
|
34
|
+
try { listed = fs.readFileSync(path.join(root, '.amk-secrets'), 'utf8').split('\n').map(l => l.trim()).filter(l => l && !l.startsWith('#')); } catch {}
|
|
32
35
|
const secret = s => secretFile.test(s) || listed.some(p => s.includes(p));
|
|
33
36
|
|
|
34
37
|
const block = reason => { process.stderr.write(`Blocked by scripts/amk/guard.js: ${reason}\n`); process.exit(2); };
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// Agent stop hook. If code changed but the active spec's handoff block wasn't updated, ask the agent to update it.
|
|
3
3
|
const fs = require('fs');
|
|
4
|
+
const path = require('path');
|
|
4
5
|
const { execSync } = require('child_process');
|
|
6
|
+
// the project this script is in (scripts/amk/): the agent may have moved into a subfolder
|
|
7
|
+
const root = path.join(__dirname, '..', '..');
|
|
5
8
|
|
|
6
9
|
let payload = {};
|
|
7
10
|
try { payload = JSON.parse(fs.readFileSync(0, 'utf8')); } catch {}
|
|
@@ -9,13 +12,13 @@ if (payload.stop_hook_active) process.exit(0); // already reminded once; don't l
|
|
|
9
12
|
|
|
10
13
|
// a spec counts only when its handoff says "Status: in progress" (not done, not an untouched template copy)
|
|
11
14
|
const inProgress = d => {
|
|
12
|
-
const f =
|
|
15
|
+
const f = path.join(root, 'specs', d, 'progress.md');
|
|
13
16
|
return d !== '_templates' && fs.existsSync(f) && /^Status:\s*in progress/im.test(fs.readFileSync(f, 'utf8'));
|
|
14
17
|
};
|
|
15
|
-
const specs = fs.existsSync('specs') ? fs.readdirSync('specs').filter(inProgress) : [];
|
|
18
|
+
const specs = fs.existsSync(path.join(root, 'specs')) ? fs.readdirSync(path.join(root, 'specs')).filter(inProgress) : [];
|
|
16
19
|
if (specs.length === 0) process.exit(0); // no spec in progress (quick change, bug fix, or finished work)
|
|
17
20
|
|
|
18
|
-
const changed = execSync('git status --porcelain --untracked-files=all', { encoding: 'utf8' }) // every new file, not just its new folder
|
|
21
|
+
const changed = execSync('git status --porcelain --untracked-files=all', { cwd: root, encoding: 'utf8' }) // every new file, not just its new folder
|
|
19
22
|
.split('\n').filter(Boolean).map(l => l.slice(3));
|
|
20
23
|
const codeChanged = changed.some(f => !f.startsWith('specs/') && !f.startsWith('.amk/'));
|
|
21
24
|
const handoffUpdated = changed.some(f => /^specs\/[^/]+\/progress\.md$/.test(f));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
#!/bin/sh
|
|
2
|
+
# Runs one of the kit's git hooks from the project's hook manager (husky, lefthook, simple-git-hooks).
|
|
3
|
+
# Usage: sh scripts/amk/run-hook.sh .githooks/<hook> [args…]
|
|
4
|
+
# A team may keep .githooks out of git, so a fresh clone has none until it runs sync: then this says so and lets the
|
|
5
|
+
# commit or push go on, as failing every one of them would leave only git commit --no-verify
|
|
6
|
+
set -eu
|
|
7
|
+
hook=$1; shift
|
|
8
|
+
if [ -f "$hook" ]; then exec sh "$hook" "$@"; fi
|
|
9
|
+
echo "agentic-mobile-kit: this clone has no $hook yet, so the kit's checks were skipped: run npx agentic-mobile-kit sync" >&2
|