prompt-contract 0.2.0
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 +202 -0
- package/README.md +102 -0
- package/README.zh-CN.md +73 -0
- package/package.json +42 -0
- package/packages/cli/bin/contract.js +266 -0
- package/packages/cli/package.json +10 -0
- package/packages/cli/src/spike-0.js +582 -0
- package/packages/cli/test/cli.test.js +89 -0
- package/packages/cli/test/spike-0.test.js +260 -0
- package/packages/core/bench/bench.js +48 -0
- package/packages/core/package.json +11 -0
- package/packages/core/src/clean.js +58 -0
- package/packages/core/src/errors.js +26 -0
- package/packages/core/src/index.js +10 -0
- package/packages/core/src/lang.js +37 -0
- package/packages/core/src/node.js +83 -0
- package/packages/core/src/pipeline.js +84 -0
- package/packages/core/src/profile.js +50 -0
- package/packages/core/src/rules.js +91 -0
- package/packages/core/test/clean.test.js +44 -0
- package/packages/core/test/lang.test.js +21 -0
- package/packages/core/test/pipeline.test.js +85 -0
- package/packages/core/test/profile.test.js +40 -0
- package/packages/core/test/rules.test.js +53 -0
- package/packages/mcp-server/bin/prompt-contract-mcp.js +7 -0
- package/packages/mcp-server/package.json +10 -0
- package/packages/mcp-server/src/server.js +184 -0
- package/packages/mcp-server/test/mcp.test.js +167 -0
- package/packages/providers/package.json +7 -0
- package/packages/providers/src/ollama.js +89 -0
- package/packages/providers/src/openai.js +89 -0
- package/packages/providers/test/providers.test.js +64 -0
- package/profiles/coding-agent.md +9 -0
- package/profiles/image-gen.md +9 -0
- package/profiles/writing.md +9 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# ✨ PromptContract
|
|
2
|
+
|
|
3
|
+
[](https://github.com/QianJinGuo/prompt-contract/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+

|
|
6
|
+
[](https://github.com/QianJinGuo/prompt-contract/releases)
|
|
7
|
+
|
|
8
|
+
English · [简体中文](README.zh-CN.md)
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
<sub>The playground running its self-contained demo (`?demo=1`) against the local mock upstream — actual pipeline output, six rule assertions passing.</sub>
|
|
12
|
+
|
|
13
|
+
**PromptContract is a deterministic prompt-contract layer for AI coding agents.** It compiles a vague one-line request into a structured task specification — goal, scope, constraints, acceptance criteria — and verifies the result against six hard rules before you ever see it.
|
|
14
|
+
|
|
15
|
+
It is *not* a smarter brain: your model does the thinking, PromptContract makes the input stable, reviewable, and portable across models and tools.
|
|
16
|
+
|
|
17
|
+
## Why PromptContract
|
|
18
|
+
|
|
19
|
+
- **Stable agent inputs** — a profile plus hard constraints turn "a website for my dog" into goal / scope / acceptance criteria / explicit non-goals. Reduced retries and scope drift are hypotheses measured by the task-level harness, not current product claims.
|
|
20
|
+
- **Six deterministic guardrails** — language consistency, enhanced-text-only, length & completeness, expand-don't-answer, no hallucinated tech. Every enhancement can be asserted with `contract check`; the same spec drives templates and tests.
|
|
21
|
+
- **One engine, three surfaces** — a CLI, an MCP server (agent-invoked **tool** + user-invoked **slash prompts**), and a browser playground. All share one zero-dependency core.
|
|
22
|
+
- **Private by architecture** — bring your own key, no server in the middle, no telemetry, offline-capable via Ollama.
|
|
23
|
+
|
|
24
|
+
## Quick start — 30 seconds, no API key
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
git clone https://github.com/QianJinGuo/prompt-contract && cd prompt-contract
|
|
28
|
+
node mock/server.js & # local mock upstream
|
|
29
|
+
node packages/cli/bin/contract.js "帮我做一个展示我家狗的网站" \
|
|
30
|
+
--provider openai --base-url http://127.0.0.1:8787/v1 --api-key test-key-123 --model mock-model
|
|
31
|
+
node packages/playground/serve.js # → http://127.0.0.1:8123/ (or ?demo=1 for the self-running demo)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Install: `npm i -g prompt-contract` — or zero-install: `npx prompt-contract "your vague idea"`.
|
|
35
|
+
|
|
36
|
+
## Your real model
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
export CONTRACT_API_KEY=sk-xxx CONTRACT_MODEL=gpt-4o-mini # any OpenAI-compatible endpoint (DeepSeek, Qwen, GLM, vLLM…)
|
|
40
|
+
contract "A website for my dog"
|
|
41
|
+
|
|
42
|
+
export CONTRACT_PROVIDER=ollama CONTRACT_MODEL=qwen3:4b # fully local/offline; keep_alive pins the model in RAM
|
|
43
|
+
contract "帮我写一封请假邮件"
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Or write `~/.prompt-contract/config.json` once: `{ "provider": "openai", "baseUrl": "…", "apiKey": "…", "model": "…" }`.
|
|
47
|
+
|
|
48
|
+
## MCP integration
|
|
49
|
+
|
|
50
|
+
```json
|
|
51
|
+
{ "mcpServers": { "prompt-contract": { "command": "node", "args": ["/abs/path/packages/mcp-server/bin/prompt-contract-mcp.js"] } } }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
| Mode | Invocation | Needs a key? |
|
|
55
|
+
|---|---|---|
|
|
56
|
+
| **Tool** `enhance_prompt(text, profile?, strength?, context?)` | the agent calls it before executing a vague task | yes (your configured provider) |
|
|
57
|
+
| **Prompts** `/contract-coding-agent`, `/contract-writing`, `/contract-image-gen` | you invoke; the rewrite spec is injected into the **client's own model** | **no — zero config, server starts unconfigured** |
|
|
58
|
+
|
|
59
|
+
## Choose a profile
|
|
60
|
+
|
|
61
|
+
| Profile | Turns vague input into | Output cap |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `coding-agent` | goal, scope, acceptance criteria, non-goals for a coding agent | 800 chars |
|
|
64
|
+
| `writing` | audience, tone, structure, preservation constraints | 800 chars |
|
|
65
|
+
| `image-gen` | subject, composition, lighting, style | 600 chars |
|
|
66
|
+
|
|
67
|
+
Community profiles are the main contribution surface — a PR adding `profiles/<name>.md` plus eval cases is a complete contribution (see [CONTRIBUTING.md](CONTRIBUTING.md)).
|
|
68
|
+
|
|
69
|
+
## Quality gates — and their honest limits
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm test # 60 tests: engine units + SSE/ndjson streaming + CLI/MCP e2e against a local mock
|
|
73
|
+
npm run eval # 9 deterministic cases over the six hard-constraint assertions
|
|
74
|
+
npm run eval:tasks -- --format-only # validate the coding-agent task fixture format gate
|
|
75
|
+
npm run bench # engine overhead: P50 ≈ 0.005ms (budget < 5ms)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**What this does and does not prove:** these gates prove the *pipeline* is correct (streaming, cancellation, error codes, MCP handshake) and that outputs pass format constraints. The paired task-level harness is documented in [docs/TASK-EVAL.md](docs/TASK-EVAL.md), but no downstream task results are included yet. It therefore makes no claim that enhanced prompts improve completion, retries, scope drift, hallucinations, token cost, or latency.
|
|
79
|
+
|
|
80
|
+
## How it works
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
raw input → script/scenario detect → profile + hard constraints + strength (+ optional context)
|
|
84
|
+
→ single streaming LLM call (small fast model by default; the model does the thinking)
|
|
85
|
+
→ deterministic cleaning (quotes/fences/length clamp, empty → llm_error)
|
|
86
|
+
→ { enhanced, original, meta } — original always preserved, one-key revert in every surface
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Status & roadmap — stated honestly
|
|
90
|
+
|
|
91
|
+
- **Shipped:** engine, CLI (`contract` / `check` / `doctor` / `profiles` / `spike-0`), MCP server (tool + zero-key prompts), playground, 3 profiles, eval cases, CI matrix.
|
|
92
|
+
- **Gated:** `contract watch` (global-hotkey resident mode) remains intentionally unavailable. `contract spike-0` measures macOS capture/clipboard safety and dry-run focus eligibility, but never pastes or unlocks watch by itself; see [docs/SPIKE-0.md](docs/SPIKE-0.md).
|
|
93
|
+
- **Open validation:** task-level outcome evaluation remains an evidence-gathering task. The harness and curated fixture set exist, but PromptContract's downstream effectiveness is still a hypothesis until a declared runner produces reviewed results.
|
|
94
|
+
- Deferred: animated demo asset, IDE plugins, LLM-as-judge as *one* scorer inside the task-level eval.
|
|
95
|
+
|
|
96
|
+
## Layout
|
|
97
|
+
|
|
98
|
+
`packages/core` (engine, browser-safe, zero deps) · `packages/providers` (OpenAI-compatible SSE + Ollama `keep_alive`) · `packages/cli` · `packages/mcp-server` · `packages/playground` · `profiles/` · `eval/` · `mock/` · `docs/ACCEPTANCE.md` · `docs/SPIKE-0.md` (requirements → implementation → acceptance + evidence boundaries)
|
|
99
|
+
|
|
100
|
+
## Contributing & License
|
|
101
|
+
|
|
102
|
+
[CONTRIBUTING.md](CONTRIBUTING.md) · [Code of Conduct](CODE_OF_CONDUCT.md) · [Security policy](SECURITY.md) · Apache-2.0
|
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# ✨ PromptContract
|
|
2
|
+
|
|
3
|
+
[](https://github.com/QianJinGuo/prompt-contract/actions/workflows/ci.yml)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+
[English](README.md) · 简体中文
|
|
8
|
+
|
|
9
|
+
**PromptContract 是面向 AI 编码 agent 的确定性 prompt 契约层**:把模糊的一句话编译成结构化任务规范(目标 / 范围 / 约束 / 验收标准),并在你看到结果之前用六条硬规则完成校验。
|
|
10
|
+
|
|
11
|
+
它不是「更聪明的大脑」:思考由你的模型完成,PromptContract 让 agent 的输入变得稳定、可审查、可跨模型与跨工具迁移。
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## 为什么
|
|
16
|
+
|
|
17
|
+
- **稳定的 agent 输入**——profile + 硬约束把「帮我做个网站」编译成目标 / 范围 / 验收标准 / 明确不做的事;重试与范围漂移是否减少,仍须由任务级 harness 验证,当前不作产品结论
|
|
18
|
+
- **六条确定性护栏**——语言一致性、只输出增强文本、长度与完整性、扩写而非回答、无幻觉技术栈;`contract check` 随时可断言,模板与测试共用同一份规格
|
|
19
|
+
- **一个引擎、三个形态**——CLI、MCP server(agent 调用的 tool + 用户调用的斜杠 prompts)、浏览器 Playground,共享同一个零依赖内核
|
|
20
|
+
- **隐私即架构**——BYOK、无中间服务、零遥测,Ollama 全本地可用
|
|
21
|
+
|
|
22
|
+
## 30 秒上手(无需 API key)
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
git clone https://github.com/QianJinGuo/prompt-contract && cd prompt-contract
|
|
26
|
+
node mock/server.js & # 本地 mock 上游
|
|
27
|
+
node packages/cli/bin/contract.js "帮我做一个展示我家狗的网站" \
|
|
28
|
+
--provider openai --base-url http://127.0.0.1:8787/v1 --api-key test-key-123 --model mock-model
|
|
29
|
+
node packages/playground/serve.js # → http://127.0.0.1:8123/(?demo=1 为自运行演示)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
安装:`npm i -g prompt-contract`;或零安装体验:`npx prompt-contract "你的模糊想法"`。
|
|
33
|
+
|
|
34
|
+
## 接入真实模型
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
export CONTRACT_API_KEY=sk-xxx CONTRACT_MODEL=gpt-4o-mini # 任意 OpenAI 兼容端点(DeepSeek/Qwen/GLM/vLLM…)
|
|
38
|
+
contract "A website for my dog"
|
|
39
|
+
|
|
40
|
+
export CONTRACT_PROVIDER=ollama CONTRACT_MODEL=qwen3:4b # 全本地;keep_alive 把模型钉在内存
|
|
41
|
+
contract "帮我写一封请假邮件"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
或一次写入 `~/.prompt-contract/config.json`。
|
|
45
|
+
|
|
46
|
+
## MCP 接入
|
|
47
|
+
|
|
48
|
+
| 模式 | 调用方 | 需要 key? |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| **Tool** `enhance_prompt(text, profile?, strength?, context?)` | agent 在执行模糊任务前自行调用 | 需要(走你配置的 provider) |
|
|
51
|
+
| **Prompts** `/contract-coding-agent` 等 | 你手动调用;改写规范注入**客户端自有模型** | **不需要——服务器可在零配置下启动** |
|
|
52
|
+
|
|
53
|
+
## 质量门禁与诚实边界
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm test # 60 项:引擎单测 + SSE/ndjson 流式 + CLI/MCP 端到端(对本地 mock)
|
|
57
|
+
npm run eval # 9 个确定性用例(六条硬约束断言)
|
|
58
|
+
npm run eval:tasks -- --format-only # 校验 coding-agent 任务 fixture 的格式门禁
|
|
59
|
+
npm run bench # 引擎自身开销 P50 ≈ 0.005ms(预算 <5ms)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
**这些证明的是管线正确与格式合规,不证明「增强后的 prompt 提升了下游任务效果」**。任务级 harness 与 fixture 见 [docs/TASK-EVAL.md](docs/TASK-EVAL.md),但仓库尚未包含下游任务结果,因此不作有效性结论。
|
|
63
|
+
|
|
64
|
+
## 状态与路线图(诚实版)
|
|
65
|
+
|
|
66
|
+
- **已交付**:引擎、CLI(含 `spike-0`)、MCP server(tool + 零 key prompts)、Playground、3 个 profiles、eval 用例、CI 矩阵
|
|
67
|
+
- **被门控**:`contract watch`(全局热键常驻)仍不可用。`contract spike-0` 只测 macOS 取词、剪贴板恢复和焦点校验的 dry-run,不发送粘贴,也不会自行解锁 watch;见 [docs/SPIKE-0.md](docs/SPIKE-0.md)
|
|
68
|
+
- **开放验证**:任务级效果评测的 harness 与任务 fixture 已交付,但还没有声明 runner 产生并复核结果;长期价值在此之前仍是假设
|
|
69
|
+
- **推迟**:动画 demo 资产、IDE 插件、LLM-as-judge(作为任务级评测中的评分器之一)
|
|
70
|
+
|
|
71
|
+
## 贡献与许可
|
|
72
|
+
|
|
73
|
+
[CONTRIBUTING.md](CONTRIBUTING.md)(新增 profile = 新增场景,PR 即贡献)· [行为准则](CODE_OF_CONDUCT.md) · [安全策略](SECURITY.md) · Apache-2.0
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "prompt-contract",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "pc — one-key prompt enhancement: turn vague ideas into structured task specs anywhere you type to an AI. CLI + MCP server. Zero dependencies, BYOK, offline-capable (Ollama).",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": ">=20"
|
|
9
|
+
},
|
|
10
|
+
"bin": {
|
|
11
|
+
"contract": "./packages/cli/bin/contract.js",
|
|
12
|
+
"prompt-contract": "./packages/cli/bin/contract.js",
|
|
13
|
+
"prompt-contract-mcp": "./packages/mcp-server/bin/prompt-contract-mcp.js",
|
|
14
|
+
"pb": "./packages/cli/bin/contract.js"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"prompt",
|
|
18
|
+
"prompt-contract",
|
|
19
|
+
"prompt-engineering",
|
|
20
|
+
"llm",
|
|
21
|
+
"cli",
|
|
22
|
+
"mcp",
|
|
23
|
+
"model-context-protocol",
|
|
24
|
+
"ai-agents",
|
|
25
|
+
"ollama",
|
|
26
|
+
"openai",
|
|
27
|
+
"developer-tools"
|
|
28
|
+
],
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/QianJinGuo/prompt-contract.git"
|
|
32
|
+
},
|
|
33
|
+
"homepage": "https://github.com/QianJinGuo/prompt-contract#readme",
|
|
34
|
+
"bugs": "https://github.com/QianJinGuo/prompt-contract/issues",
|
|
35
|
+
"files": [
|
|
36
|
+
"packages/",
|
|
37
|
+
"profiles/",
|
|
38
|
+
"README.md",
|
|
39
|
+
"README.en.md",
|
|
40
|
+
"LICENSE"
|
|
41
|
+
]
|
|
42
|
+
}
|