lov-project-port

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

端口管家 · Port Keeper

Port Steward · Port Keeper

为项目生成稳定唯一的端口号(范围 3000-8999),同一项目名永远返回相同端口。
Generates a stable, unique port number for a project (within the 3000-8999 range). The same project name will always return the same port.

端口生成算法

Port Generation Algorithm

python
def generate_port(project_name: str) -> int:
    hash_value = sum(ord(c) * (i + 1) for i, c in enumerate(project_name))
    return 3000 + (hash_value % 6000)
python
def generate_port(project_name: str) -> int:
    hash_value = sum(ord(c) * (i + 1) for i, c in enumerate(project_name))
    return 3000 + (hash_value % 6000)

使用场景

Use Cases

1. 查询项目端口

1. Query a Project Port

用户询问端口时,直接计算并告知:
项目 "skill-publisher" 的端口号是:7965
When the user asks for a port, calculate it directly and respond:
The port number for project "skill-publisher" is: 7965

2. 更新项目配置

2. Update the Project Configuration

检测并更新项目中的端口配置文件:
文件配置方式
.env
/
.env.local
PORT=<port>
package.json
scripts 中的
--port <port>
vite.config.ts
server.port: <port>
next.config.js
通常使用 .env
更新时优先使用
.env
方式,最小侵入性。
Detect and update the port configuration files in the project:
FileConfiguration Method
.env
/
.env.local
PORT=<port>
package.json
--port <port>
in scripts
vite.config.ts
server.port: <port>
next.config.js
Usually uses
.env
When updating, prefer the
.env
method to minimize changes.

3. 启动开发服务器

3. Start the Development Server

bash
PORT=$(scripts/hashport.sh) pnpm dev
bash
PORT=$(scripts/hashport.sh) pnpm dev

脚本

Scripts

运行
scripts/hashport.sh [project-name]
生成端口:
bash
undefined
Run
scripts/hashport.sh [project-name]
to generate a port:
bash
undefined

使用当前目录名

Use the current directory name

./scripts/hashport.sh
./scripts/hashport.sh

输出: 7965

Output: 7965

指定项目名

Specify a project name

./scripts/hashport.sh my-project
./scripts/hashport.sh my-project

输出: 5123

Output: 5123

undefined
undefined

端口冲突处理

Port Conflict Handling

若端口被占用:
  1. 提示用户哪个进程占用了端口
  2. 建议使用
    lsof -i :<port>
    查看
  3. 可追加后缀生成备用端口:
    generate_port("project-dev")
If the port is occupied:
  1. Inform the user which process is occupying the port
  2. Suggest using
    lsof -i :<port>
    to inspect it
  3. A suffix can be appended to generate a fallback port:
    generate_port("project-dev")

Runtime context (shared)

Runtime Context (Shared)

运行前读取本 Skill 包的
skill.yaml
,由宿主提供
skill-runtime/v1
上下文。字段解析顺序为:当前请求、项目上下文、个人 Preferences、品牌 Profile、通用默认值。
  • 只使用 Manifest 声明的字段;Profile 保存公开品牌事实,Preferences 保存个人工作偏好。
  • required: true
    字段缺失时,按 Manifest 的问题配置向用户提出一个聚焦问题;用户明确同意后再保存回答。
  • 报错提供可复制的
    context_id
    、字段路径与来源,诊断内容避开秘密、完整私人路径和原始配置。
Before running, read the
skill.yaml
file of this Skill package. The host provides the
skill-runtime/v1
context. Fields are resolved in the following order: current request, project context, personal Preferences, brand Profile, and general defaults.
  • Use only fields declared in the Manifest. The Profile stores public brand facts, while Preferences stores personal work preferences.
  • If a
    required: true
    field is missing, ask the user one focused question based on the Manifest's question configuration. Save the answer only after the user explicitly agrees.
  • Errors should provide a copyable
    context_id
    , field path, and source. Diagnostics must avoid secrets, full private paths, and raw configuration.

通用反馈闭环

General Feedback Loop

用户在 Skill 驱动任务中提出修改意见时,继续当前产物前必须执行:
  1. 先判断意见是
    task-specific
    (仅本次)还是
    reusable
    (可跨任务复用)。
  2. task-specific
    只修改当前任务,不改 Skill。
  3. reusable
    先确定作用域:领域规则先更新对应 canonical Skill;适用于所有 Skill 的规则先更新共享规范。
  4. 完成规则更新、版本、lint 与分发核验后,再把修改应用到当前任务。
  5. reusable
    修改会使此前的“确认”“继续”“发吧”失效;完成当前产物修改和回读后必须停下,等待用户下一步指示,不自动进入发布、提交或其他外部写入。
When a user provides modification feedback during a Skill-driven task, perform the following steps before continuing with the current deliverable:
  1. Determine whether the feedback is
    task-specific
    (for this task only) or
    reusable
    (applicable across tasks).
  2. For
    task-specific
    feedback, modify only the current task and do not change the Skill.
  3. For
    reusable
    feedback, determine the scope first: update the corresponding canonical Skill for domain-specific rules, or update the shared specification for rules that apply to all Skills.
  4. After completing the rule update, versioning, linting, and distribution verification, apply the modification to the current task.
  5. A
    reusable
    modification invalidates any previous "Confirm", "Continue", or "Ship" instruction. After modifying and reading back the current deliverable, stop and wait for the user's next instruction. Do not automatically proceed to publishing, committing, or any other external write.