instar 0.1.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 (115) hide show
  1. package/.claude/settings.local.json +7 -0
  2. package/.claude/skills/setup-wizard/skill.md +343 -0
  3. package/.github/workflows/ci.yml +78 -0
  4. package/CLAUDE.md +82 -0
  5. package/README.md +194 -0
  6. package/dist/cli.d.ts +18 -0
  7. package/dist/cli.js +141 -0
  8. package/dist/commands/init.d.ts +40 -0
  9. package/dist/commands/init.js +568 -0
  10. package/dist/commands/job.d.ts +20 -0
  11. package/dist/commands/job.js +84 -0
  12. package/dist/commands/server.d.ts +19 -0
  13. package/dist/commands/server.js +273 -0
  14. package/dist/commands/setup.d.ts +24 -0
  15. package/dist/commands/setup.js +865 -0
  16. package/dist/commands/status.d.ts +11 -0
  17. package/dist/commands/status.js +114 -0
  18. package/dist/commands/user.d.ts +17 -0
  19. package/dist/commands/user.js +53 -0
  20. package/dist/core/Config.d.ts +16 -0
  21. package/dist/core/Config.js +144 -0
  22. package/dist/core/Prerequisites.d.ts +28 -0
  23. package/dist/core/Prerequisites.js +159 -0
  24. package/dist/core/RelationshipManager.d.ts +73 -0
  25. package/dist/core/RelationshipManager.js +318 -0
  26. package/dist/core/SessionManager.d.ts +89 -0
  27. package/dist/core/SessionManager.js +326 -0
  28. package/dist/core/StateManager.d.ts +28 -0
  29. package/dist/core/StateManager.js +96 -0
  30. package/dist/core/types.d.ts +279 -0
  31. package/dist/core/types.js +8 -0
  32. package/dist/index.d.ts +18 -0
  33. package/dist/index.js +23 -0
  34. package/dist/messaging/TelegramAdapter.d.ts +73 -0
  35. package/dist/messaging/TelegramAdapter.js +288 -0
  36. package/dist/monitoring/HealthChecker.d.ts +38 -0
  37. package/dist/monitoring/HealthChecker.js +148 -0
  38. package/dist/scaffold/bootstrap.d.ts +21 -0
  39. package/dist/scaffold/bootstrap.js +110 -0
  40. package/dist/scaffold/templates.d.ts +34 -0
  41. package/dist/scaffold/templates.js +187 -0
  42. package/dist/scheduler/JobLoader.d.ts +18 -0
  43. package/dist/scheduler/JobLoader.js +70 -0
  44. package/dist/scheduler/JobScheduler.d.ts +111 -0
  45. package/dist/scheduler/JobScheduler.js +402 -0
  46. package/dist/server/AgentServer.d.ts +40 -0
  47. package/dist/server/AgentServer.js +73 -0
  48. package/dist/server/middleware.d.ts +12 -0
  49. package/dist/server/middleware.js +50 -0
  50. package/dist/server/routes.d.ts +25 -0
  51. package/dist/server/routes.js +224 -0
  52. package/dist/users/UserManager.d.ts +45 -0
  53. package/dist/users/UserManager.js +113 -0
  54. package/docs/dawn-audit-report.md +412 -0
  55. package/docs/positioning-vs-openclaw.md +246 -0
  56. package/package.json +52 -0
  57. package/src/cli.ts +169 -0
  58. package/src/commands/init.ts +654 -0
  59. package/src/commands/job.ts +110 -0
  60. package/src/commands/server.ts +325 -0
  61. package/src/commands/setup.ts +958 -0
  62. package/src/commands/status.ts +125 -0
  63. package/src/commands/user.ts +71 -0
  64. package/src/core/Config.ts +161 -0
  65. package/src/core/Prerequisites.ts +187 -0
  66. package/src/core/RelationshipManager.ts +366 -0
  67. package/src/core/SessionManager.ts +385 -0
  68. package/src/core/StateManager.ts +121 -0
  69. package/src/core/types.ts +320 -0
  70. package/src/index.ts +58 -0
  71. package/src/messaging/TelegramAdapter.ts +365 -0
  72. package/src/monitoring/HealthChecker.ts +172 -0
  73. package/src/scaffold/bootstrap.ts +122 -0
  74. package/src/scaffold/templates.ts +204 -0
  75. package/src/scheduler/JobLoader.ts +85 -0
  76. package/src/scheduler/JobScheduler.ts +476 -0
  77. package/src/server/AgentServer.ts +93 -0
  78. package/src/server/middleware.ts +58 -0
  79. package/src/server/routes.ts +278 -0
  80. package/src/templates/default-jobs.json +47 -0
  81. package/src/templates/hooks/compaction-recovery.sh +23 -0
  82. package/src/templates/hooks/dangerous-command-guard.sh +35 -0
  83. package/src/templates/hooks/grounding-before-messaging.sh +22 -0
  84. package/src/templates/hooks/session-start.sh +37 -0
  85. package/src/templates/hooks/settings-template.json +45 -0
  86. package/src/templates/scripts/health-watchdog.sh +63 -0
  87. package/src/templates/scripts/telegram-reply.sh +54 -0
  88. package/src/users/UserManager.ts +129 -0
  89. package/tests/e2e/lifecycle.test.ts +376 -0
  90. package/tests/fixtures/test-repo/CLAUDE.md +3 -0
  91. package/tests/fixtures/test-repo/README.md +1 -0
  92. package/tests/helpers/setup.ts +209 -0
  93. package/tests/integration/fresh-install.test.ts +218 -0
  94. package/tests/integration/scheduler-basic.test.ts +109 -0
  95. package/tests/integration/server-full.test.ts +284 -0
  96. package/tests/integration/session-lifecycle.test.ts +181 -0
  97. package/tests/unit/Config.test.ts +22 -0
  98. package/tests/unit/HealthChecker.test.ts +168 -0
  99. package/tests/unit/JobLoader.test.ts +151 -0
  100. package/tests/unit/JobScheduler.test.ts +267 -0
  101. package/tests/unit/Prerequisites.test.ts +59 -0
  102. package/tests/unit/RelationshipManager.test.ts +345 -0
  103. package/tests/unit/StateManager.test.ts +143 -0
  104. package/tests/unit/TelegramAdapter.test.ts +165 -0
  105. package/tests/unit/UserManager.test.ts +131 -0
  106. package/tests/unit/bootstrap.test.ts +28 -0
  107. package/tests/unit/commands.test.ts +138 -0
  108. package/tests/unit/middleware.test.ts +92 -0
  109. package/tests/unit/relationship-routes.test.ts +131 -0
  110. package/tests/unit/scaffold-templates.test.ts +132 -0
  111. package/tests/unit/server.test.ts +163 -0
  112. package/tsconfig.json +20 -0
  113. package/vitest.config.ts +9 -0
  114. package/vitest.e2e.config.ts +9 -0
  115. package/vitest.integration.config.ts +9 -0
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "instar",
3
+ "version": "0.1.0",
4
+ "description": "Persistent autonomy infrastructure for AI agents",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "instar": "dist/cli.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "dev": "tsc --watch",
13
+ "test": "vitest run",
14
+ "test:watch": "vitest",
15
+ "test:integration": "vitest run --config vitest.integration.config.ts",
16
+ "test:e2e": "vitest run --config vitest.e2e.config.ts",
17
+ "test:all": "vitest run && vitest run --config vitest.integration.config.ts && vitest run --config vitest.e2e.config.ts",
18
+ "lint": "tsc --noEmit",
19
+ "clean": "rm -rf dist",
20
+ "prepublishOnly": "npm run build"
21
+ },
22
+ "keywords": [
23
+ "instar",
24
+ "autonomous",
25
+ "agent",
26
+ "molt",
27
+ "lobster",
28
+ "claude",
29
+ "cli",
30
+ "automation",
31
+ "claude-code"
32
+ ],
33
+ "license": "UNLICENSED",
34
+ "engines": {
35
+ "node": ">=18.0.0"
36
+ },
37
+ "dependencies": {
38
+ "@inquirer/prompts": "^8.2.1",
39
+ "commander": "^12.0.0",
40
+ "croner": "^8.0.0",
41
+ "express": "^4.18.0",
42
+ "picocolors": "^1.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "@types/express": "^4.17.21",
46
+ "@types/node": "^20.11.0",
47
+ "@types/supertest": "^6.0.3",
48
+ "supertest": "^7.2.2",
49
+ "typescript": "^5.3.0",
50
+ "vitest": "^2.0.0"
51
+ }
52
+ }
package/src/cli.ts ADDED
@@ -0,0 +1,169 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * instar CLI — Persistent autonomy infrastructure for AI agents.
5
+ *
6
+ * Usage:
7
+ * instar init my-project # Create a new agent project from scratch
8
+ * instar init # Add agent infrastructure to existing project
9
+ * instar setup # Interactive setup wizard
10
+ * instar server start # Start the persistent agent server
11
+ * instar server stop # Stop the server
12
+ * instar status # Show agent infrastructure status
13
+ * instar user add # Add a user profile
14
+ * instar job add # Add a job definition
15
+ * instar job list # List all jobs
16
+ * instar add telegram # Add Telegram messaging adapter
17
+ */
18
+
19
+ import { Command } from 'commander';
20
+ import { initProject } from './commands/init.js';
21
+ import { runSetup } from './commands/setup.js';
22
+ import { startServer, stopServer } from './commands/server.js';
23
+ import { showStatus } from './commands/status.js';
24
+ import { addUser, listUsers } from './commands/user.js';
25
+ import { addJob, listJobs } from './commands/job.js';
26
+
27
+ const program = new Command();
28
+
29
+ program
30
+ .name('instar')
31
+ .description('Persistent autonomy infrastructure for AI agents')
32
+ .version('0.1.0')
33
+ .option('--classic', 'Use the classic inquirer-based setup wizard instead of Claude')
34
+ .action((opts) => runSetup(opts)); // Default: run interactive setup when no subcommand given
35
+
36
+ // ── Setup (explicit alias) ────────────────────────────────────────
37
+
38
+ program
39
+ .command('setup')
40
+ .description('Interactive setup wizard (same as running `instar` with no args)')
41
+ .option('--classic', 'Use the classic inquirer-based setup wizard instead of Claude')
42
+ .action((opts) => runSetup(opts));
43
+
44
+ // ── Init ─────────────────────────────────────────────────────────
45
+
46
+ program
47
+ .command('init [project-name]')
48
+ .description('Initialize agent infrastructure (fresh project or existing)')
49
+ .option('-d, --dir <path>', 'Project directory (default: current directory)')
50
+ .option('--port <port>', 'Server port (default: 4040)', parseInt)
51
+ .action((projectName, opts) => {
52
+ // If a project name is given, it's a fresh install
53
+ // Otherwise, augment the current directory
54
+ initProject({ ...opts, name: projectName });
55
+ });
56
+
57
+ // ── Add ───────────────────────────────────────────────────────────
58
+
59
+ const addCmd = program
60
+ .command('add')
61
+ .description('Add capabilities to the agent');
62
+
63
+ addCmd
64
+ .command('telegram')
65
+ .description('Add Telegram messaging adapter')
66
+ .option('--token <token>', 'Telegram bot token')
67
+ .option('--chat-id <id>', 'Telegram forum chat ID')
68
+ .action((_opts) => {
69
+ console.log('TODO: Add Telegram adapter (scaffolding only — use programmatic API for now)');
70
+ });
71
+
72
+ addCmd
73
+ .command('email')
74
+ .description('Add email integration (Gmail)')
75
+ .action((_opts) => {
76
+ console.log('TODO: Add email integration');
77
+ });
78
+
79
+ addCmd
80
+ .command('sentry')
81
+ .description('Add Sentry error monitoring')
82
+ .option('--dsn <dsn>', 'Sentry DSN')
83
+ .action((_opts) => {
84
+ console.log('TODO: Add Sentry integration');
85
+ });
86
+
87
+ addCmd
88
+ .command('quota')
89
+ .description('Add Claude API quota tracking')
90
+ .action((_opts) => {
91
+ console.log('TODO: Add quota tracking');
92
+ });
93
+
94
+ // ── Server ────────────────────────────────────────────────────────
95
+
96
+ const serverCmd = program
97
+ .command('server')
98
+ .description('Manage the persistent agent server');
99
+
100
+ serverCmd
101
+ .command('start')
102
+ .description('Start the agent server')
103
+ .option('--foreground', 'Run in foreground (default: background via tmux)')
104
+ .option('-d, --dir <path>', 'Project directory')
105
+ .action(startServer);
106
+
107
+ serverCmd
108
+ .command('stop')
109
+ .description('Stop the agent server')
110
+ .option('-d, --dir <path>', 'Project directory')
111
+ .action(stopServer);
112
+
113
+ // ── Status ────────────────────────────────────────────────────────
114
+
115
+ program
116
+ .command('status')
117
+ .description('Show agent infrastructure status')
118
+ .option('-d, --dir <path>', 'Project directory')
119
+ .action(showStatus);
120
+
121
+ // ── User ──────────────────────────────────────────────────────────
122
+
123
+ const userCmd = program
124
+ .command('user')
125
+ .description('Manage users');
126
+
127
+ userCmd
128
+ .command('add')
129
+ .description('Add a user profile')
130
+ .requiredOption('--id <id>', 'User ID')
131
+ .requiredOption('--name <name>', 'User display name')
132
+ .option('--telegram <topicId>', 'Telegram topic ID')
133
+ .option('--email <email>', 'Email address')
134
+ .option('--slack <userId>', 'Slack user ID')
135
+ .option('--permissions <perms>', 'Comma-separated permissions', (v: string) => v.split(','))
136
+ .action(addUser);
137
+
138
+ userCmd
139
+ .command('list')
140
+ .description('List all users')
141
+ .option('-d, --dir <path>', 'Project directory')
142
+ .action(listUsers);
143
+
144
+ // ── Job ───────────────────────────────────────────────────────────
145
+
146
+ const jobCmd = program
147
+ .command('job')
148
+ .description('Manage scheduled jobs');
149
+
150
+ jobCmd
151
+ .command('add')
152
+ .description('Add a job definition')
153
+ .requiredOption('--slug <slug>', 'Job identifier')
154
+ .requiredOption('--name <name>', 'Job display name')
155
+ .requiredOption('--schedule <cron>', 'Cron expression')
156
+ .option('--description <desc>', 'Job description')
157
+ .option('--priority <priority>', 'Priority (critical|high|medium|low)', 'medium')
158
+ .option('--model <model>', 'Model tier (opus|sonnet|haiku)', 'sonnet')
159
+ .option('--type <type>', 'Execution type (skill|prompt|script)', 'prompt')
160
+ .option('--execute <value>', 'Execution value (skill name, prompt text, or script path)')
161
+ .action(addJob);
162
+
163
+ jobCmd
164
+ .command('list')
165
+ .description('List all jobs')
166
+ .option('-d, --dir <path>', 'Project directory')
167
+ .action(listJobs);
168
+
169
+ program.parse();