mantisai-cli 2.0.0 → 2.0.2

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) Kellis Lab, MIT
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) Kellis Lab, MIT
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -1,32 +1,32 @@
1
- #!/usr/bin/env node
2
- import { spacesForPrompt } from '../lib/list-cli.js';
3
-
4
- const args = process.argv.slice(2);
5
- let filter = '';
6
- let offset = 0;
7
- let limit = 4;
8
- for (let i = 0; i < args.length; i++) {
9
- const a = args[i];
10
- if (a === '--offset') {
11
- offset = parseInt(args[++i], 10) || 0;
12
- continue;
13
- }
14
- if (a === '--limit') {
15
- limit = parseInt(args[++i], 10) || 4;
16
- continue;
17
- }
18
- if (a === '--filter') {
19
- filter = args[++i] ?? '';
20
- continue;
21
- }
22
- filter = args.slice(i).join(' ').trim();
23
- break;
24
- }
25
-
26
- try {
27
- const data = await spacesForPrompt(filter, { limit, offset });
28
- process.stdout.write(JSON.stringify(data));
29
- } catch (e) {
30
- console.error(JSON.stringify({ error: e.message }));
31
- process.exit(1);
32
- }
1
+ #!/usr/bin/env node
2
+ import { spacesForPrompt } from '../lib/list-cli.js';
3
+
4
+ const args = process.argv.slice(2);
5
+ let filter = '';
6
+ let offset = 0;
7
+ let limit = 4;
8
+ for (let i = 0; i < args.length; i++) {
9
+ const a = args[i];
10
+ if (a === '--offset') {
11
+ offset = parseInt(args[++i], 10) || 0;
12
+ continue;
13
+ }
14
+ if (a === '--limit') {
15
+ limit = parseInt(args[++i], 10) || 4;
16
+ continue;
17
+ }
18
+ if (a === '--filter') {
19
+ filter = args[++i] ?? '';
20
+ continue;
21
+ }
22
+ filter = args.slice(i).join(' ').trim();
23
+ break;
24
+ }
25
+
26
+ try {
27
+ const data = await spacesForPrompt(filter, { limit, offset });
28
+ process.stdout.write(JSON.stringify(data));
29
+ } catch (e) {
30
+ console.error(JSON.stringify({ error: e.message }));
31
+ process.exit(1);
32
+ }
@@ -1,32 +1,32 @@
1
- #!/usr/bin/env node
2
- import { threadsForPrompt } from '../lib/list-cli.js';
3
-
4
- const args = process.argv.slice(2);
5
- let filter = '';
6
- let offset = 0;
7
- let limit = 4;
8
- for (let i = 0; i < args.length; i++) {
9
- const a = args[i];
10
- if (a === '--offset') {
11
- offset = parseInt(args[++i], 10) || 0;
12
- continue;
13
- }
14
- if (a === '--limit') {
15
- limit = parseInt(args[++i], 10) || 4;
16
- continue;
17
- }
18
- if (a === '--filter') {
19
- filter = args[++i] ?? '';
20
- continue;
21
- }
22
- filter = args.slice(i).join(' ').trim();
23
- break;
24
- }
25
-
26
- try {
27
- const data = await threadsForPrompt(filter, { limit, offset });
28
- process.stdout.write(JSON.stringify(data));
29
- } catch (e) {
30
- console.error(JSON.stringify({ error: e.message }));
31
- process.exit(1);
32
- }
1
+ #!/usr/bin/env node
2
+ import { threadsForPrompt } from '../lib/list-cli.js';
3
+
4
+ const args = process.argv.slice(2);
5
+ let filter = '';
6
+ let offset = 0;
7
+ let limit = 4;
8
+ for (let i = 0; i < args.length; i++) {
9
+ const a = args[i];
10
+ if (a === '--offset') {
11
+ offset = parseInt(args[++i], 10) || 0;
12
+ continue;
13
+ }
14
+ if (a === '--limit') {
15
+ limit = parseInt(args[++i], 10) || 4;
16
+ continue;
17
+ }
18
+ if (a === '--filter') {
19
+ filter = args[++i] ?? '';
20
+ continue;
21
+ }
22
+ filter = args.slice(i).join(' ').trim();
23
+ break;
24
+ }
25
+
26
+ try {
27
+ const data = await threadsForPrompt(filter, { limit, offset });
28
+ process.stdout.write(JSON.stringify(data));
29
+ } catch (e) {
30
+ console.error(JSON.stringify({ error: e.message }));
31
+ process.exit(1);
32
+ }
@@ -1,31 +1,31 @@
1
- #!/usr/bin/env node
2
- import { loadConfig, saveConfig } from '../lib/config.js';
3
- import { syncMcpConfigs } from '../lib/mcp-config.js';
4
-
5
- const id = process.argv[2];
6
- const name = process.argv[3] || '';
7
- if (!id) {
8
- console.error('Usage: mantis-set-space <space-uuid> [name]');
9
- process.exit(1);
10
- }
11
-
12
- const cfg = loadConfig();
13
- const changed = cfg.spaceId !== id;
14
- const next = {
15
- ...cfg,
16
- spaceId: id,
17
- spaceName: name || cfg.spaceName,
18
- ...(changed ? { spaceStateId: undefined, spaceStateName: undefined } : {}),
19
- };
20
- saveConfig(next);
21
- syncMcpConfigs(next);
22
- console.log(
23
- JSON.stringify({
24
- ok: true,
25
- spaceId: id,
26
- spaceName: name,
27
- threadCleared: changed,
28
- needThread: changed,
29
- needReloadPlugins: true,
30
- }),
31
- );
1
+ #!/usr/bin/env node
2
+ import { loadConfig, saveConfig } from '../lib/config.js';
3
+ import { syncMcpConfigs } from '../lib/mcp-config.js';
4
+
5
+ const id = process.argv[2];
6
+ const name = process.argv[3] || '';
7
+ if (!id) {
8
+ console.error('Usage: mantis-set-space <space-uuid> [name]');
9
+ process.exit(1);
10
+ }
11
+
12
+ const cfg = loadConfig();
13
+ const changed = cfg.spaceId !== id;
14
+ const next = {
15
+ ...cfg,
16
+ spaceId: id,
17
+ spaceName: name || cfg.spaceName,
18
+ ...(changed ? { spaceStateId: undefined, spaceStateName: undefined } : {}),
19
+ };
20
+ saveConfig(next);
21
+ syncMcpConfigs(next);
22
+ console.log(
23
+ JSON.stringify({
24
+ ok: true,
25
+ spaceId: id,
26
+ spaceName: name,
27
+ threadCleared: changed,
28
+ needThread: changed,
29
+ needReloadPlugins: true,
30
+ }),
31
+ );
package/bin/mantis.js CHANGED
@@ -38,7 +38,7 @@ function addMapOptions(cmd) {
38
38
  program
39
39
  .name('mantis')
40
40
  .description('Mantis developer CLI — manage spaces, create maps, and configure Claude Code integration')
41
- .version('2.0.0');
41
+ .version('2.0.1');
42
42
 
43
43
  program
44
44
  .command('setup')
@@ -90,6 +90,9 @@ addMapOptions(create
90
90
  const result = await createCodebaseCsv(root, out, { maxChars: opts.maxChars });
91
91
  success(`Indexed ${result.count} files`);
92
92
  info(`CSV: ${result.outFile}`);
93
+ if (result.skipped?.length) {
94
+ info(`Skipped ${result.skipped.length} binary file(s) (e.g. ${result.skipped.slice(0, 3).join(', ')})`);
95
+ }
93
96
  if (opts.createMap) {
94
97
  const mapResult = await createMapFlow(result.outFile, {
95
98
  ...opts,
@@ -1,150 +1,150 @@
1
- import { execSync, spawnSync } from 'node:child_process';
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { fileURLToPath } from 'node:url';
6
-
7
- import { loadConfig } from './config.js';
8
- import { syncMcpConfigs } from './mcp-config.js';
9
-
10
- const MARKETPLACE = 'mantis-plugins';
11
- const PLUGIN_ID = `mantis@${MARKETPLACE}`;
12
- const MARKETPLACE_REPO = 'KellisLab/mantis-cli';
13
- const NPM_PACKAGE = 'mantisai-cli';
14
- const LEGACY_NPM_PACKAGES = ['mantis-cli', 'mantis-claude-code'];
15
-
16
- export function resolvePluginRoot() {
17
- try {
18
- const root = execSync('npm root -g', { encoding: 'utf8', windowsHide: true }).trim();
19
- for (const candidate of [NPM_PACKAGE, ...LEGACY_NPM_PACKAGES]) {
20
- const globalPkg = path.join(root, candidate);
21
- if (fs.existsSync(path.join(globalPkg, '.claude-plugin', 'plugin.json'))) {
22
- return path.normalize(globalPkg);
23
- }
24
- }
25
- } catch {
26
- /* not installed globally */
27
- }
28
- const here = path.dirname(fileURLToPath(import.meta.url));
29
- return path.normalize(path.resolve(here, '..'));
30
- }
31
-
32
- function settingsPath() {
33
- return path.join(os.homedir(), '.claude', 'settings.json');
34
- }
35
-
36
- function installedPluginsPath() {
37
- return path.join(os.homedir(), '.claude', 'plugins', 'installed_plugins.json');
38
- }
39
-
40
- function readSettings() {
41
- const file = settingsPath();
42
- if (!fs.existsSync(file)) return {};
43
- try {
44
- return JSON.parse(fs.readFileSync(file, 'utf8'));
45
- } catch {
46
- return {};
47
- }
48
- }
49
-
50
- function writeSettings(settings) {
51
- const file = settingsPath();
52
- fs.mkdirSync(path.dirname(file), { recursive: true });
53
- fs.writeFileSync(file, `${JSON.stringify(settings, null, 2)}\n`);
54
- }
55
-
56
- function stripBrokenInlinePlugins(settings) {
57
- const bad = (v) =>
58
- typeof v === 'string' &&
59
- (v.includes('$(npm') || v.includes('mantis-claude-code-plugin') || v.includes('mantis-cli-plugin'));
60
- if (Array.isArray(settings.plugins)) {
61
- settings.plugins = settings.plugins.filter((p) => {
62
- const paths = [p?.path, p?.commands, p?.source?.path].filter(Boolean);
63
- return !paths.some(bad);
64
- });
65
- if (!settings.plugins.length) delete settings.plugins;
66
- }
67
- }
68
-
69
- export function isPluginInstalled() {
70
- try {
71
- const data = JSON.parse(fs.readFileSync(installedPluginsPath(), 'utf8'));
72
- const entries = data.plugins?.[PLUGIN_ID];
73
- if (!Array.isArray(entries) || !entries.length) return false;
74
- const installPath = entries[0]?.installPath;
75
- if (!installPath || !fs.existsSync(installPath)) return false;
76
- return !fs.existsSync(path.join(installPath, '.orphaned_at'));
77
- } catch {
78
- return false;
79
- }
80
- }
81
-
82
- function mergeMarketplaceIntoSettings() {
83
- const settings = readSettings();
84
- stripBrokenInlinePlugins(settings);
85
- settings.extraKnownMarketplaces = settings.extraKnownMarketplaces || {};
86
- settings.extraKnownMarketplaces[MARKETPLACE] = {
87
- source: { source: 'github', repo: MARKETPLACE_REPO },
88
- };
89
- writeSettings(settings);
90
- }
91
-
92
- const BENIGN = [
93
- /already enabled/i,
94
- /already installed/i,
95
- /already on disk/i,
96
- /no updates/i,
97
- /is already enabled/i,
98
- ];
99
-
100
- function quoteCmdArg(arg) {
101
- return `"${String(arg).replace(/"/g, '\\"')}"`;
102
- }
103
-
104
- function runClaude(argv, { optional = false } = {}) {
105
- const opts = { encoding: 'utf8', windowsHide: true };
106
- const r = process.platform === 'win32'
107
- ? spawnSync(['claude', ...argv.map(quoteCmdArg)].join(' '), { ...opts, shell: true })
108
- : spawnSync('claude', argv, opts);
109
- if (r.error) {
110
- const msg =
111
- r.error.code === 'ENOENT'
112
- ? 'claude not found on PATH — install Claude Code CLI first'
113
- : r.error.message;
114
- if (optional) return null;
115
- throw new Error(msg);
116
- }
117
- const out = `${r.stdout || ''}${r.stderr || ''}`.trim();
118
- if (r.status === 0 || BENIGN.some((re) => re.test(out))) return out;
119
- if (optional) return null;
120
- throw new Error(out || `claude ${argv.join(' ')} failed (exit ${r.status})`);
121
- }
122
-
123
- function installPluginScopes() {
124
- for (const scope of ['user', 'local']) {
125
- if (isPluginInstalled()) return scope;
126
- runClaude(['plugin', 'install', PLUGIN_ID, '--scope', scope], { optional: true });
127
- }
128
- return isPluginInstalled() ? 'user' : null;
129
- }
130
-
131
- export function installClaudePlugin() {
132
- const pluginRoot = resolvePluginRoot();
133
- mergeMarketplaceIntoSettings();
134
-
135
- runClaude(['plugin', 'marketplace', 'add', MARKETPLACE_REPO, '--scope', 'user'], { optional: true });
136
- const scope = installPluginScopes();
137
- if (!scope) {
138
- throw new Error(
139
- 'Plugin not registered after install. Run: claude plugin install mantis@mantis-plugins',
140
- );
141
- }
142
- runClaude(['plugin', 'update', PLUGIN_ID, '--scope', scope], { optional: true });
143
- runClaude(['plugin', 'enable', PLUGIN_ID, '--scope', scope], { optional: true });
144
- const settings = readSettings();
145
- settings.enabledPlugins = settings.enabledPlugins || {};
146
- settings.enabledPlugins[PLUGIN_ID] = true;
147
- writeSettings(settings);
148
- syncMcpConfigs(loadConfig());
149
- return { ok: true, method: 'cli', pluginRoot, scope };
150
- }
1
+ import { execSync, spawnSync } from 'node:child_process';
2
+ import fs from 'node:fs';
3
+ import os from 'node:os';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ import { loadConfig } from './config.js';
8
+ import { syncMcpConfigs } from './mcp-config.js';
9
+
10
+ const MARKETPLACE = 'mantis-plugins';
11
+ const PLUGIN_ID = `mantis@${MARKETPLACE}`;
12
+ const MARKETPLACE_REPO = 'KellisLab/mantis-cli';
13
+ const NPM_PACKAGE = 'mantisai-cli';
14
+ const LEGACY_NPM_PACKAGES = ['mantis-cli', 'mantis-claude-code'];
15
+
16
+ export function resolvePluginRoot() {
17
+ try {
18
+ const root = execSync('npm root -g', { encoding: 'utf8', windowsHide: true }).trim();
19
+ for (const candidate of [NPM_PACKAGE, ...LEGACY_NPM_PACKAGES]) {
20
+ const globalPkg = path.join(root, candidate);
21
+ if (fs.existsSync(path.join(globalPkg, '.claude-plugin', 'plugin.json'))) {
22
+ return path.normalize(globalPkg);
23
+ }
24
+ }
25
+ } catch {
26
+ /* not installed globally */
27
+ }
28
+ const here = path.dirname(fileURLToPath(import.meta.url));
29
+ return path.normalize(path.resolve(here, '..'));
30
+ }
31
+
32
+ function settingsPath() {
33
+ return path.join(os.homedir(), '.claude', 'settings.json');
34
+ }
35
+
36
+ function installedPluginsPath() {
37
+ return path.join(os.homedir(), '.claude', 'plugins', 'installed_plugins.json');
38
+ }
39
+
40
+ function readSettings() {
41
+ const file = settingsPath();
42
+ if (!fs.existsSync(file)) return {};
43
+ try {
44
+ return JSON.parse(fs.readFileSync(file, 'utf8'));
45
+ } catch {
46
+ return {};
47
+ }
48
+ }
49
+
50
+ function writeSettings(settings) {
51
+ const file = settingsPath();
52
+ fs.mkdirSync(path.dirname(file), { recursive: true });
53
+ fs.writeFileSync(file, `${JSON.stringify(settings, null, 2)}\n`);
54
+ }
55
+
56
+ function stripBrokenInlinePlugins(settings) {
57
+ const bad = (v) =>
58
+ typeof v === 'string' &&
59
+ (v.includes('$(npm') || v.includes('mantis-claude-code-plugin') || v.includes('mantis-cli-plugin'));
60
+ if (Array.isArray(settings.plugins)) {
61
+ settings.plugins = settings.plugins.filter((p) => {
62
+ const paths = [p?.path, p?.commands, p?.source?.path].filter(Boolean);
63
+ return !paths.some(bad);
64
+ });
65
+ if (!settings.plugins.length) delete settings.plugins;
66
+ }
67
+ }
68
+
69
+ export function isPluginInstalled() {
70
+ try {
71
+ const data = JSON.parse(fs.readFileSync(installedPluginsPath(), 'utf8'));
72
+ const entries = data.plugins?.[PLUGIN_ID];
73
+ if (!Array.isArray(entries) || !entries.length) return false;
74
+ const installPath = entries[0]?.installPath;
75
+ if (!installPath || !fs.existsSync(installPath)) return false;
76
+ return !fs.existsSync(path.join(installPath, '.orphaned_at'));
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ function mergeMarketplaceIntoSettings() {
83
+ const settings = readSettings();
84
+ stripBrokenInlinePlugins(settings);
85
+ settings.extraKnownMarketplaces = settings.extraKnownMarketplaces || {};
86
+ settings.extraKnownMarketplaces[MARKETPLACE] = {
87
+ source: { source: 'github', repo: MARKETPLACE_REPO },
88
+ };
89
+ writeSettings(settings);
90
+ }
91
+
92
+ const BENIGN = [
93
+ /already enabled/i,
94
+ /already installed/i,
95
+ /already on disk/i,
96
+ /no updates/i,
97
+ /is already enabled/i,
98
+ ];
99
+
100
+ function quoteCmdArg(arg) {
101
+ return `"${String(arg).replace(/"/g, '\\"')}"`;
102
+ }
103
+
104
+ function runClaude(argv, { optional = false } = {}) {
105
+ const opts = { encoding: 'utf8', windowsHide: true };
106
+ const r = process.platform === 'win32'
107
+ ? spawnSync(['claude', ...argv.map(quoteCmdArg)].join(' '), { ...opts, shell: true })
108
+ : spawnSync('claude', argv, opts);
109
+ if (r.error) {
110
+ const msg =
111
+ r.error.code === 'ENOENT'
112
+ ? 'claude not found on PATH — install Claude Code CLI first'
113
+ : r.error.message;
114
+ if (optional) return null;
115
+ throw new Error(msg);
116
+ }
117
+ const out = `${r.stdout || ''}${r.stderr || ''}`.trim();
118
+ if (r.status === 0 || BENIGN.some((re) => re.test(out))) return out;
119
+ if (optional) return null;
120
+ throw new Error(out || `claude ${argv.join(' ')} failed (exit ${r.status})`);
121
+ }
122
+
123
+ function installPluginScopes() {
124
+ for (const scope of ['user', 'local']) {
125
+ if (isPluginInstalled()) return scope;
126
+ runClaude(['plugin', 'install', PLUGIN_ID, '--scope', scope], { optional: true });
127
+ }
128
+ return isPluginInstalled() ? 'user' : null;
129
+ }
130
+
131
+ export function installClaudePlugin() {
132
+ const pluginRoot = resolvePluginRoot();
133
+ mergeMarketplaceIntoSettings();
134
+
135
+ runClaude(['plugin', 'marketplace', 'add', MARKETPLACE_REPO, '--scope', 'user'], { optional: true });
136
+ const scope = installPluginScopes();
137
+ if (!scope) {
138
+ throw new Error(
139
+ 'Plugin not registered after install. Run: claude plugin install mantis@mantis-plugins',
140
+ );
141
+ }
142
+ runClaude(['plugin', 'update', PLUGIN_ID, '--scope', scope], { optional: true });
143
+ runClaude(['plugin', 'enable', PLUGIN_ID, '--scope', scope], { optional: true });
144
+ const settings = readSettings();
145
+ settings.enabledPlugins = settings.enabledPlugins || {};
146
+ settings.enabledPlugins[PLUGIN_ID] = true;
147
+ writeSettings(settings);
148
+ syncMcpConfigs(loadConfig());
149
+ return { ok: true, method: 'cli', pluginRoot, scope };
150
+ }
@@ -18,6 +18,8 @@ const DEFAULT_IGNORES = [
18
18
  '**/package-lock.json',
19
19
  '**/pnpm-lock.yaml',
20
20
  '**/yarn.lock',
21
+ '**/.DS_Store',
22
+ '**/Thumbs.db',
21
23
  ];
22
24
 
23
25
  const EXT_LANGUAGE = {
@@ -42,6 +44,8 @@ const EXT_LANGUAGE = {
42
44
 
43
45
  const SOURCE_EXTENSIONS = Object.keys(EXT_LANGUAGE);
44
46
 
47
+ const NULL_BYTE = String.fromCharCode(0);
48
+
45
49
  function inferKind(rel) {
46
50
  const base = path.basename(rel).toLowerCase();
47
51
  if (base.includes('test') || base.includes('spec')) return 'test';
@@ -73,8 +77,27 @@ function summarize(content) {
73
77
  return (comment || lines[0] || '').replace(/^\/\/|^#|^\/\*+|^\*|<!--|-->/g, '').trim().slice(0, 240);
74
78
  }
75
79
 
80
+ function isBinaryBuffer(buf) {
81
+ // Postgres JSON/text columns reject the NUL byte (0x00), and other low
82
+ // control bytes are a strong signal of non-text payloads (images,
83
+ // .DS_Store, compiled artifacts). Sniff the head of the file.
84
+ const sample = buf.subarray(0, Math.min(buf.length, 8192));
85
+ for (let i = 0; i < sample.length; i++) {
86
+ const b = sample[i];
87
+ if (b === 0) return true;
88
+ // allow \t (9), \n (10), \r (13); reject other C0 control bytes
89
+ if (b < 9 || (b > 13 && b < 32)) return true;
90
+ }
91
+ return false;
92
+ }
93
+
76
94
  function readText(file, maxChars) {
77
- const raw = fs.readFileSync(file, 'utf8');
95
+ const buf = fs.readFileSync(file);
96
+ if (isBinaryBuffer(buf)) return null;
97
+ let raw = buf.toString('utf8');
98
+ // belt-and-suspenders: strip any NUL chars that survived decoding,
99
+ // since Postgres JSON columns will reject them.
100
+ if (raw.indexOf(NULL_BYTE) !== -1) raw = raw.split(NULL_BYTE).join('');
78
101
  return raw.length > maxChars ? `${raw.slice(0, maxChars)}\n\n[truncated]` : raw;
79
102
  }
80
103
 
@@ -89,12 +112,18 @@ export async function createCodebaseCsv(rootDir, outFile, { maxChars = 12000, in
89
112
  onlyFiles: true,
90
113
  });
91
114
 
92
- const rows = files.sort().map((file) => {
115
+ const skipped = [];
116
+ const rows = [];
117
+ for (const file of files.sort()) {
93
118
  const rel = path.relative(root, file).replace(/\\/g, '/');
94
119
  const ext = path.extname(file).toLowerCase();
95
120
  const content = readText(file, maxChars);
121
+ if (content === null) {
122
+ skipped.push(rel);
123
+ continue;
124
+ }
96
125
  const stat = fs.statSync(file);
97
- return {
126
+ rows.push({
98
127
  path: rel,
99
128
  file_name: path.basename(file),
100
129
  extension: ext.replace(/^\./, ''),
@@ -105,11 +134,11 @@ export async function createCodebaseCsv(rootDir, outFile, { maxChars = 12000, in
105
134
  imports: importsFrom(content),
106
135
  summary: summarize(content),
107
136
  content,
108
- };
109
- });
137
+ });
138
+ }
110
139
 
111
140
  if (!rows.length) throw new Error(`No source files found in ${root}`);
112
141
  fs.mkdirSync(path.dirname(path.resolve(outFile)), { recursive: true });
113
142
  fs.writeFileSync(outFile, stringify(rows, { header: true }));
114
- return { root, outFile: path.resolve(outFile), count: rows.length };
143
+ return { root, outFile: path.resolve(outFile), count: rows.length, skipped };
115
144
  }
package/lib/map-create.js CHANGED
@@ -22,9 +22,29 @@ function boolOption(value, fallback = false) {
22
22
  return ['1', 'true', 'yes', 'public'].includes(String(value).toLowerCase());
23
23
  }
24
24
 
25
+ function frontendBaseUrl(apiBaseUrl) {
26
+ const root = normalizeBaseUrl(apiBaseUrl).replace(/\/api\/?$/, '');
27
+ let url;
28
+ try {
29
+ url = new URL(root);
30
+ } catch {
31
+ return root;
32
+ }
33
+ // Local dev: API on :8000, frontend on :3000.
34
+ if (/^(localhost|127\.0\.0\.1)$/i.test(url.hostname)) {
35
+ url.port = '3000';
36
+ return url.origin;
37
+ }
38
+ // Mantis production: API on kellis-h200-1.csail.mit.edu, frontend on mantis.csail.mit.edu.
39
+ if (/(^|\.)kellis-h200-1\.csail\.mit\.edu$/i.test(url.hostname)) {
40
+ url.hostname = 'mantis.csail.mit.edu';
41
+ return url.origin;
42
+ }
43
+ return root;
44
+ }
45
+
25
46
  function spaceUrl(baseUrl, spaceId) {
26
- const root = normalizeBaseUrl(baseUrl).replace(/\/api\/?$/, '');
27
- return `${root}/space/${spaceId}`;
47
+ return `${frontendBaseUrl(baseUrl)}/space/${spaceId}`;
28
48
  }
29
49
 
30
50
  async function chooseExistingSpace(cfg, filter = '') {
package/lib/mcp-config.js CHANGED
@@ -1,50 +1,50 @@
1
- import fs from 'node:fs';
2
- import os from 'node:os';
3
- import path from 'node:path';
4
- import { fileURLToPath } from 'node:url';
5
-
6
- import { mcpUrl } from './config.js';
7
-
8
- const MARKETPLACE = 'mantis-plugins';
9
- const PACKAGE = 'mantisai-cli';
10
-
11
- function existingPackageRoot(root) {
12
- return root && fs.existsSync(path.join(root, 'package.json')) ? path.normalize(root) : null;
13
- }
14
-
15
- function isInstallRoot(root) {
16
- const p = root.toLowerCase();
17
- return p.includes(`${path.sep}.claude${path.sep}plugins${path.sep}`) ||
18
- p.endsWith(`${path.sep}node_modules${path.sep}${PACKAGE}`);
19
- }
20
-
21
- function cacheRoots() {
22
- const base = path.join(os.homedir(), '.claude', 'plugins', 'cache', MARKETPLACE, 'mantis');
23
- if (!fs.existsSync(base)) return [];
24
- return fs.readdirSync(base).map((v) => path.join(base, v));
25
- }
26
-
27
- export function pluginRoots() {
28
- const here = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
29
- const home = os.homedir();
30
- return [
31
- here,
32
- path.join(home, '.claude', 'plugins', 'marketplaces', MARKETPLACE),
33
- path.join(home, '.claude', 'plugins', 'npm-cache', 'node_modules', PACKAGE),
34
- path.join(home, 'AppData', 'Roaming', 'npm', 'node_modules', PACKAGE),
35
- ...cacheRoots(),
36
- ].map(existingPackageRoot).filter(Boolean).filter(isInstallRoot).filter((v, i, a) => a.indexOf(v) === i);
37
- }
38
-
39
- export function mcpConfig(cfg) {
40
- const server = { type: 'http', url: mcpUrl(cfg) };
41
- if (cfg.spaceStateId) server.headers = { 'X-Space-State-ID': String(cfg.spaceStateId) };
42
- return { mcpServers: { mantis: server } };
43
- }
44
-
45
- export function syncMcpConfigs(cfg) {
46
- const body = `${JSON.stringify(mcpConfig(cfg), null, 2)}\n`;
47
- for (const root of pluginRoots()) {
48
- fs.writeFileSync(path.join(root, '.mcp.json'), body);
49
- }
50
- }
1
+ import fs from 'node:fs';
2
+ import os from 'node:os';
3
+ import path from 'node:path';
4
+ import { fileURLToPath } from 'node:url';
5
+
6
+ import { mcpUrl } from './config.js';
7
+
8
+ const MARKETPLACE = 'mantis-plugins';
9
+ const PACKAGE = 'mantisai-cli';
10
+
11
+ function existingPackageRoot(root) {
12
+ return root && fs.existsSync(path.join(root, 'package.json')) ? path.normalize(root) : null;
13
+ }
14
+
15
+ function isInstallRoot(root) {
16
+ const p = root.toLowerCase();
17
+ return p.includes(`${path.sep}.claude${path.sep}plugins${path.sep}`) ||
18
+ p.endsWith(`${path.sep}node_modules${path.sep}${PACKAGE}`);
19
+ }
20
+
21
+ function cacheRoots() {
22
+ const base = path.join(os.homedir(), '.claude', 'plugins', 'cache', MARKETPLACE, 'mantis');
23
+ if (!fs.existsSync(base)) return [];
24
+ return fs.readdirSync(base).map((v) => path.join(base, v));
25
+ }
26
+
27
+ export function pluginRoots() {
28
+ const here = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
29
+ const home = os.homedir();
30
+ return [
31
+ here,
32
+ path.join(home, '.claude', 'plugins', 'marketplaces', MARKETPLACE),
33
+ path.join(home, '.claude', 'plugins', 'npm-cache', 'node_modules', PACKAGE),
34
+ path.join(home, 'AppData', 'Roaming', 'npm', 'node_modules', PACKAGE),
35
+ ...cacheRoots(),
36
+ ].map(existingPackageRoot).filter(Boolean).filter(isInstallRoot).filter((v, i, a) => a.indexOf(v) === i);
37
+ }
38
+
39
+ export function mcpConfig(cfg) {
40
+ const server = { type: 'http', url: mcpUrl(cfg) };
41
+ if (cfg.spaceStateId) server.headers = { 'X-Space-State-ID': String(cfg.spaceStateId) };
42
+ return { mcpServers: { mantis: server } };
43
+ }
44
+
45
+ export function syncMcpConfigs(cfg) {
46
+ const body = `${JSON.stringify(mcpConfig(cfg), null, 2)}\n`;
47
+ for (const root of pluginRoots()) {
48
+ fs.writeFileSync(path.join(root, '.mcp.json'), body);
49
+ }
50
+ }
package/lib/space-id.js CHANGED
@@ -1,13 +1,13 @@
1
- const UUID_RE =
2
- /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
3
-
4
- /** Extract space UUID from a Mantis URL (/space/{id}), raw UUID, or search text containing one. */
5
- export function parseSpaceIdFromInput(text) {
6
- const t = (text || '').trim();
7
- if (!t) return null;
8
- const pathMatch = t.match(/\/space\/([0-9a-f-]{36})/i);
9
- if (pathMatch) return pathMatch[1].toLowerCase();
10
- const uuidMatch = t.match(UUID_RE);
11
- if (uuidMatch) return uuidMatch[0].toLowerCase();
12
- return null;
13
- }
1
+ const UUID_RE =
2
+ /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/i;
3
+
4
+ /** Extract space UUID from a Mantis URL (/space/{id}), raw UUID, or search text containing one. */
5
+ export function parseSpaceIdFromInput(text) {
6
+ const t = (text || '').trim();
7
+ if (!t) return null;
8
+ const pathMatch = t.match(/\/space\/([0-9a-f-]{36})/i);
9
+ if (pathMatch) return pathMatch[1].toLowerCase();
10
+ const uuidMatch = t.match(UUID_RE);
11
+ if (uuidMatch) return uuidMatch[0].toLowerCase();
12
+ return null;
13
+ }
package/lib/spaces.js CHANGED
@@ -1,48 +1,48 @@
1
- import { listSpaces } from './api.js';
2
- import { parseSpaceIdFromInput } from './space-id.js';
3
-
4
- export async function fetchSpaceById(baseUrl, apiKey, spaceId) {
5
- const page = await listSpaces(baseUrl, apiKey, {
6
- scope: 'accessible',
7
- space_id: spaceId,
8
- limit: 1,
9
- offset: 0,
10
- });
11
- return page.spaces?.[0] ?? null;
12
- }
13
-
14
- export async function resolveSpaceFromInput(baseUrl, apiKey, text) {
15
- const id = parseSpaceIdFromInput(text);
16
- if (!id) return null;
17
- return fetchSpaceById(baseUrl, apiKey, id);
18
- }
19
-
20
- /** One page of spaces; optional name/id search — does not load the full catalog. */
21
- export async function searchSpaces(
22
- baseUrl,
23
- apiKey,
24
- { q = '', limit = 20, offset = 0, scope = 'accessible' } = {},
25
- ) {
26
- const id = parseSpaceIdFromInput(q);
27
- if (id) {
28
- const one = await fetchSpaceById(baseUrl, apiKey, id);
29
- return {
30
- spaces: one ? [one] : [],
31
- total: one ? 1 : 0,
32
- limit: 1,
33
- offset: 0,
34
- };
35
- }
36
- const page = await listSpaces(baseUrl, apiKey, {
37
- scope,
38
- limit,
39
- offset,
40
- q: q.trim() || undefined,
41
- });
42
- return {
43
- spaces: page.spaces || [],
44
- total: page.total ?? (page.spaces || []).length,
45
- limit: page.limit ?? limit,
46
- offset: page.offset ?? offset,
47
- };
48
- }
1
+ import { listSpaces } from './api.js';
2
+ import { parseSpaceIdFromInput } from './space-id.js';
3
+
4
+ export async function fetchSpaceById(baseUrl, apiKey, spaceId) {
5
+ const page = await listSpaces(baseUrl, apiKey, {
6
+ scope: 'accessible',
7
+ space_id: spaceId,
8
+ limit: 1,
9
+ offset: 0,
10
+ });
11
+ return page.spaces?.[0] ?? null;
12
+ }
13
+
14
+ export async function resolveSpaceFromInput(baseUrl, apiKey, text) {
15
+ const id = parseSpaceIdFromInput(text);
16
+ if (!id) return null;
17
+ return fetchSpaceById(baseUrl, apiKey, id);
18
+ }
19
+
20
+ /** One page of spaces; optional name/id search — does not load the full catalog. */
21
+ export async function searchSpaces(
22
+ baseUrl,
23
+ apiKey,
24
+ { q = '', limit = 20, offset = 0, scope = 'accessible' } = {},
25
+ ) {
26
+ const id = parseSpaceIdFromInput(q);
27
+ if (id) {
28
+ const one = await fetchSpaceById(baseUrl, apiKey, id);
29
+ return {
30
+ spaces: one ? [one] : [],
31
+ total: one ? 1 : 0,
32
+ limit: 1,
33
+ offset: 0,
34
+ };
35
+ }
36
+ const page = await listSpaces(baseUrl, apiKey, {
37
+ scope,
38
+ limit,
39
+ offset,
40
+ q: q.trim() || undefined,
41
+ });
42
+ return {
43
+ spaces: page.spaces || [],
44
+ total: page.total ?? (page.spaces || []).length,
45
+ limit: page.limit ?? limit,
46
+ offset: page.offset ?? offset,
47
+ };
48
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mantisai-cli",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Mantis developer CLI — create maps, manage spaces and threads, configure Claude Code, and connect agents to Mantis MCP.",
5
5
  "type": "module",
6
6
  "license": "MIT",