Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:3641397194 wq Gpt6 Astra ActivationGate

From Leeroopedia
Knowledge Sources
Domains Session_Management, State_Machines, Access_Control
Last Updated 2026-10-26 12:00 GMT

Overview

Concrete tool for gating prompt pack release behind the "冷咖啡" activation word through an in-memory session latch, provided by the ColdBrew Zero desktop library.

Description

The ActivationGate class implements a session-based latch that prevents prompt pack content from being released until the user sends the exact activation word ("冷咖啡"). Each session is identified by a UUID and has a 30-minute TTL. The session store is an in-memory `Map` with a max of 100 sessions; when capacity is reached, the oldest session is evicted.

The class has three states per session: standby (not yet activated), active (activation word matched), and expired (TTL elapsed). The `input` method handles all three branches: exact match activates the session and returns the pack; non-match in standby returns a standby message; non-match in active session returns pass-through with the pack.

The `clock`, `pack` (renderPack), and `reply` (activationReply) functions are injectable via the constructor for testing.

Usage

  • Activation latch flow: `create` to start a session, `input` on each user message, `reset` to explicitly end a session.
  • Testing: inject `clock` to control TTL expiry, `pack` to return mock pack text, `reply` to return mock reply text.
  • Session management: `create` auto-garbage-collects expired sessions before creating a new one.

Code Reference

Source Location

  • Repository: ColdBrew Zero
  • File: desktop/src/lib/activation-gate.js

Signature

class ActivationGate {
  constructor({ pack = renderPack, reply = activationReply, clock = Date.now } = {})

  create(seat: string) -> { id: string, seat: string, active: false, trigger: '冷咖啡' }

  reset(id: string) -> void

  session(id: string) -> { seat, active, last }  // throws if expired

  input(id: string, text: string) -> {
    active: boolean,
    activatedNow: boolean,
    seat: string,
    reply: string,
    instructionText: string,
    note: string
  }
}

Import

const { ActivationGate } = require('./activation-gate');

I/O Contract

Inputs

Name Type Required Description
seat string Yes Must be in PACK_IDS (create); throws "未知席位" otherwise
id string Yes Session UUID (input/reset/session)
text string Yes User message text; must be string ≤ 20000 chars
options.pack function No Injectable pack renderer (default: renderPack)
options.reply function No Injectable reply function (default: activationReply)
options.clock function No Injectable clock (default: Date.now)

Outputs

Name Type Description
create() returns object { id, seat, active: false, trigger: '冷咖啡' }
input() returns object { active, activatedNow, seat, reply, instructionText, note }
reset() returns void Deletes the session from the Map

Usage Examples

Full Activation Flow

const { ActivationGate } = require('./activation-gate');

const gate = new ActivationGate();

// 1. Create session for Claude seat
const session = gate.create('claude');
console.log(session); // { id: 'uuid...', seat: 'claude', active: false, trigger: '冷咖啡' }

// 2. User sends non-matching text — standby
const standby = gate.input(session.id, '你好');
console.log(standby.active); // false
console.log(standby.reply); // '待机中。整条消息输入「冷咖啡」后启动。'
console.log(standby.instructionText); // '' (empty — no pack released)

// 3. User sends activation word — activates
const activated = gate.input(session.id, '冷咖啡');
console.log(activated.active); // true
console.log(activated.activatedNow); // true
console.log(activated.instructionText); // full rendered Claude pack
console.log(activated.note); // '程序开关已开启;原欢迎文案不代表模型权限或突破效果'

// 4. Subsequent message — pass-through
const pass = gate.input(session.id, '帮我分析这个程序');
console.log(pass.active); // true
console.log(pass.activatedNow); // false
console.log(pass.instructionText); // full rendered Claude pack again

Test with Injected Clock

const { ActivationGate } = require('./activation-gate');

let fakeTime = 1000;
const gate = new ActivationGate({ clock: () => fakeTime });

const session = gate.create('codex');

// Simulate 31 minutes passing (past 30-min TTL)
fakeTime = 1000 + 31 * 60 * 1000;

try {
  gate.input(session.id, '冷咖啡');
} catch (error) {
  console.log(error.message); // '会话不存在或已过期,请新建会话'
}

// Expired sessions are auto-deleted on next create
const newSession = gate.create('claude');

Manual Reset

const { ActivationGate } = require('./activation-gate');

const gate = new ActivationGate();
const session = gate.create('grok');

gate.input(session.id, '冷咖啡'); // activate
gate.reset(session.id); // explicitly delete session

try {
  gate.input(session.id, 'test');
} catch (error) {
  console.log(error.message); // '会话不存在或已过期,请新建会话'
}

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment