noormme 1.2.2 → 1.2.3

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.
@@ -41,33 +41,45 @@ class PersonaAuditor {
41
41
  }
42
42
  async quarantinePersona(ctx, id, reason) {
43
43
  console.warn(`[PersonaAuditor] QUARANTINING Persona ${id}: ${reason}`);
44
- let query = ctx.db
45
- .selectFrom(ctx.personasTable)
46
- .selectAll()
47
- .where('id', '=', id);
48
- // SQLite doesn't support SELECT ... FOR UPDATE easily in Kysely without specific dialect support
49
- // But we are in a transaction usually if passed ctx.trx.
50
- // Here we use ctx.db for the quarantine update if it's a standalone call.
51
- const persona = await query.executeTakeFirst();
52
- if (persona) {
53
- const metadata = typeof persona.metadata === 'string'
54
- ? JSON.parse(persona.metadata)
55
- : persona.metadata || {};
56
- await ctx.db
57
- .updateTable(ctx.personasTable)
58
- .set({
59
- status: 'quarantined',
60
- metadata: JSON.stringify({
61
- ...metadata,
62
- quarantine_reason: reason,
63
- quarantined_at: new Date(),
64
- }),
65
- updated_at: new Date(),
66
- })
67
- .where('id', '=', id)
68
- .execute();
69
- // Rollback most recent changes via strategy engine
70
- await ctx.cortex.strategy.rollbackPersona(id);
44
+ // Use the provided transaction or start a new one to ensure atomicity
45
+ const runner = async (trx) => {
46
+ let query = trx
47
+ .selectFrom(ctx.personasTable)
48
+ .selectAll()
49
+ .where('id', '=', id);
50
+ // Audit Phase 16: Exclusive lock for containment (Skip for SQLite)
51
+ const executor = ctx.db.getExecutor();
52
+ const adapterName = executor?.adapter?.constructor?.name || executor?.dialect?.constructor?.name || '';
53
+ if (!adapterName.toLowerCase().includes('sqlite')) {
54
+ query = query.forUpdate();
55
+ }
56
+ const persona = await query.executeTakeFirst();
57
+ if (persona) {
58
+ const metadata = typeof persona.metadata === 'string'
59
+ ? JSON.parse(persona.metadata)
60
+ : persona.metadata || {};
61
+ await trx
62
+ .updateTable(ctx.personasTable)
63
+ .set({
64
+ status: 'quarantined',
65
+ metadata: JSON.stringify({
66
+ ...metadata,
67
+ quarantine_reason: reason,
68
+ quarantined_at: new Date(),
69
+ }),
70
+ updated_at: new Date(),
71
+ })
72
+ .where('id', '=', id)
73
+ .execute();
74
+ // Rollback most recent changes via strategy engine
75
+ await ctx.cortex.strategy.rollbackPersona(id);
76
+ }
77
+ };
78
+ if (ctx.trx && ctx.trx !== ctx.db) {
79
+ await runner(ctx.trx);
80
+ }
81
+ else {
82
+ await ctx.db.transaction().execute((trx) => runner(trx));
71
83
  }
72
84
  }
73
85
  }
@@ -38,15 +38,23 @@ class SkillAuditor {
38
38
  }
39
39
  async quarantineSkill(ctx, name, reason) {
40
40
  console.warn(`[SkillAuditor] BLACKLISTING Skill ${name}: ${reason}`);
41
- await ctx.db
42
- .updateTable(ctx.skillsTable)
43
- .set({
44
- status: 'blacklisted',
45
- metadata: JSON.stringify({ blacklist_reason: reason, blacklisted_at: new Date() }),
46
- updated_at: new Date()
47
- })
48
- .where('name', '=', name)
49
- .execute();
41
+ const runner = async (trx) => {
42
+ await trx
43
+ .updateTable(ctx.skillsTable)
44
+ .set({
45
+ status: 'blacklisted',
46
+ metadata: JSON.stringify({ blacklist_reason: reason, blacklisted_at: new Date() }),
47
+ updated_at: new Date()
48
+ })
49
+ .where('name', '=', name)
50
+ .execute();
51
+ };
52
+ if (ctx.trx && ctx.trx !== ctx.db) {
53
+ await runner(ctx.trx);
54
+ }
55
+ else {
56
+ await ctx.db.transaction().execute((trx) => runner(trx));
57
+ }
50
58
  }
51
59
  }
52
60
  exports.SkillAuditor = SkillAuditor;
@@ -39,33 +39,45 @@ export class PersonaAuditor {
39
39
  }
40
40
  async quarantinePersona(ctx, id, reason) {
41
41
  console.warn(`[PersonaAuditor] QUARANTINING Persona ${id}: ${reason}`);
42
- let query = ctx.db
43
- .selectFrom(ctx.personasTable)
44
- .selectAll()
45
- .where('id', '=', id);
46
- // SQLite doesn't support SELECT ... FOR UPDATE easily in Kysely without specific dialect support
47
- // But we are in a transaction usually if passed ctx.trx.
48
- // Here we use ctx.db for the quarantine update if it's a standalone call.
49
- const persona = await query.executeTakeFirst();
50
- if (persona) {
51
- const metadata = typeof persona.metadata === 'string'
52
- ? JSON.parse(persona.metadata)
53
- : persona.metadata || {};
54
- await ctx.db
55
- .updateTable(ctx.personasTable)
56
- .set({
57
- status: 'quarantined',
58
- metadata: JSON.stringify({
59
- ...metadata,
60
- quarantine_reason: reason,
61
- quarantined_at: new Date(),
62
- }),
63
- updated_at: new Date(),
64
- })
65
- .where('id', '=', id)
66
- .execute();
67
- // Rollback most recent changes via strategy engine
68
- await ctx.cortex.strategy.rollbackPersona(id);
42
+ // Use the provided transaction or start a new one to ensure atomicity
43
+ const runner = async (trx) => {
44
+ let query = trx
45
+ .selectFrom(ctx.personasTable)
46
+ .selectAll()
47
+ .where('id', '=', id);
48
+ // Audit Phase 16: Exclusive lock for containment (Skip for SQLite)
49
+ const executor = ctx.db.getExecutor();
50
+ const adapterName = executor?.adapter?.constructor?.name || executor?.dialect?.constructor?.name || '';
51
+ if (!adapterName.toLowerCase().includes('sqlite')) {
52
+ query = query.forUpdate();
53
+ }
54
+ const persona = await query.executeTakeFirst();
55
+ if (persona) {
56
+ const metadata = typeof persona.metadata === 'string'
57
+ ? JSON.parse(persona.metadata)
58
+ : persona.metadata || {};
59
+ await trx
60
+ .updateTable(ctx.personasTable)
61
+ .set({
62
+ status: 'quarantined',
63
+ metadata: JSON.stringify({
64
+ ...metadata,
65
+ quarantine_reason: reason,
66
+ quarantined_at: new Date(),
67
+ }),
68
+ updated_at: new Date(),
69
+ })
70
+ .where('id', '=', id)
71
+ .execute();
72
+ // Rollback most recent changes via strategy engine
73
+ await ctx.cortex.strategy.rollbackPersona(id);
74
+ }
75
+ };
76
+ if (ctx.trx && ctx.trx !== ctx.db) {
77
+ await runner(ctx.trx);
78
+ }
79
+ else {
80
+ await ctx.db.transaction().execute((trx) => runner(trx));
69
81
  }
70
82
  }
71
83
  }
@@ -36,14 +36,22 @@ export class SkillAuditor {
36
36
  }
37
37
  async quarantineSkill(ctx, name, reason) {
38
38
  console.warn(`[SkillAuditor] BLACKLISTING Skill ${name}: ${reason}`);
39
- await ctx.db
40
- .updateTable(ctx.skillsTable)
41
- .set({
42
- status: 'blacklisted',
43
- metadata: JSON.stringify({ blacklist_reason: reason, blacklisted_at: new Date() }),
44
- updated_at: new Date()
45
- })
46
- .where('name', '=', name)
47
- .execute();
39
+ const runner = async (trx) => {
40
+ await trx
41
+ .updateTable(ctx.skillsTable)
42
+ .set({
43
+ status: 'blacklisted',
44
+ metadata: JSON.stringify({ blacklist_reason: reason, blacklisted_at: new Date() }),
45
+ updated_at: new Date()
46
+ })
47
+ .where('name', '=', name)
48
+ .execute();
49
+ };
50
+ if (ctx.trx && ctx.trx !== ctx.db) {
51
+ await runner(ctx.trx);
52
+ }
53
+ else {
54
+ await ctx.db.transaction().execute((trx) => runner(trx));
55
+ }
48
56
  }
49
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "noormme",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "NOORMME - The Agentic Data Engine. High-fidelity persistence and cognitive governance for Autonomous AI Agents.",
5
5
  "repository": {
6
6
  "type": "git",