cognitivebc 0.2.0 → 0.2.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cognitivebc",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Cognitive Bytecode (CBC) — The Decision Encoding & Execution Substrate for Synap-se",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -56,10 +56,14 @@ function createHttpBackend(options = {}) {
56
56
  return data;
57
57
  }
58
58
 
59
- async function identify() {
60
- if (identifyCache) return identifyCache;
59
+ /**
60
+ * Read-only lookup by default. Only explicit agent use (MCP tools) may
61
+ * register a personal candidate project for an unknown repository.
62
+ */
63
+ async function identify({ register = false } = {}) {
64
+ if (identifyCache && (!register || identifyCache.status !== 'new')) return identifyCache;
61
65
  if (!identity) identity = loadIdentity(cwd);
62
- identifyCache = await request('POST', '/api/v1/projects/identify', { identity, register_candidate: true });
66
+ identifyCache = await request('POST', '/api/v1/projects/identify', { identity, register_candidate: register });
63
67
  return identifyCache;
64
68
  }
65
69
 
@@ -74,7 +78,7 @@ function createHttpBackend(options = {}) {
74
78
  }
75
79
 
76
80
  const handlers = {
77
- async cbc_identify_project() { return identify(); },
81
+ async cbc_identify_project() { return identify({ register: true }); },
78
82
 
79
83
  async cbc_get_context(a) {
80
84
  const project = await safeProject();
@@ -187,6 +187,10 @@ function createProjectRegistry({ db, dir } = {}) {
187
187
  async function registerCandidate(rawIdentity, principal) {
188
188
  if (!principal || !principal.id) fail(403, 'Authenticated principal required');
189
189
  const id = cleanIdentity(rawIdentity);
190
+ // A folder name alone cannot be recognized again on another machine.
191
+ if (!id.git_remotes.length && !id.root_commits.length) {
192
+ return { status: 'new', registered: false, reason: 'no_repository_identifiers', hint: 'Run inside a git repository with a remote, or create .cognitivebc.yaml with `cognitivebc init`.' };
193
+ }
190
194
  const existing = await identify(id, { trustedLocal: true });
191
195
  if (existing.status !== 'new') {
192
196
  const p = existing.project;
@@ -268,7 +272,19 @@ function createProjectRegistry({ db, dir } = {}) {
268
272
  return Promise.all(visible.map(describe));
269
273
  }
270
274
 
271
- return { migrate: () => store.migrate(), identify, registerCandidate, upsertProject, linkIdentifiers, promote, list, backend: db ? 'postgres' : 'file' };
275
+ /** Removes a candidate project. Owners may drop their own; approvers any candidate in their tenants. Active projects are never removed here. */
276
+ async function archiveCandidate(projectId, principal) {
277
+ validateProjectId(projectId);
278
+ const p = await store.getProject(projectId);
279
+ if (!p) fail(404, 'Project not found');
280
+ if (p.status !== 'candidate') fail(409, 'Only candidate projects can be archived');
281
+ const owner = principal && p.tenant === `user-${slug(principal.id, 'anon')}`;
282
+ if (!owner) { requirePerm(principal, 'approve'); requireTenant(principal, p.tenant); }
283
+ await store.deleteProject(projectId);
284
+ return { project_id: projectId, archived: true };
285
+ }
286
+
287
+ return { migrate: () => store.migrate(), identify, registerCandidate, upsertProject, linkIdentifiers, promote, archiveCandidate, list, backend: db ? 'postgres' : 'file' };
272
288
  }
273
289
 
274
290
  // ---------- HTTP routes ----------
@@ -281,7 +297,8 @@ async function handleProjectRoutes({ method, pathname, body, principal, registry
281
297
  const ident = b.identity || b;
282
298
  const r = await registry.identify(ident, principal);
283
299
  if (r.status === 'new' && b.register_candidate === true && has(principal, 'ingest')) {
284
- return { status: 201, json: await registry.registerCandidate(ident, principal) };
300
+ const reg = await registry.registerCandidate(ident, principal);
301
+ return { status: reg.created ? 201 : 200, json: reg };
285
302
  }
286
303
  return { status: 200, json: r };
287
304
  }
@@ -292,6 +309,10 @@ async function handleProjectRoutes({ method, pathname, body, principal, registry
292
309
  if (pathname === '/api/v1/projects' && method === 'POST') {
293
310
  return { status: 200, json: { project: await registry.upsertProject(b, principal, { move: b.move === true }) } };
294
311
  }
312
+ const del = /^\/api\/v1\/projects\/(.+)\/archive$/.exec(pathname);
313
+ if (del && method === 'POST') {
314
+ return { status: 200, json: await registry.archiveCandidate(decodeURIComponent(del[1]), principal) };
315
+ }
295
316
  const m = /^\/api\/v1\/projects\/(.+)\/(link|promote)$/.exec(pathname);
296
317
  if (m && method === 'POST') {
297
318
  const pid = decodeURIComponent(m[1]);
@@ -71,7 +71,7 @@ function createServer(options = {}) {
71
71
  res.setHeader('X-Content-Type-Options', 'nosniff');
72
72
  // Authorized representations must never be reused across identities.
73
73
  res.setHeader('Cache-Control', 'no-store');
74
- res.setHeader('X-CognitiveBC-Version', '0.2.0');
74
+ res.setHeader('X-CognitiveBC-Version', packageInfo.version);
75
75
  res.setHeader('X-CognitiveBC-License', packageInfo.license);
76
76
 
77
77
  if (!allowedOrigin) {